-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include Column Lineage Info for All Queries #23322
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1596,7 +1596,33 @@ protected Scope visitQuery(Query node, Optional<Scope> scope) | |
.withRelationType(RelationId.of(node), queryBodyScope.getRelationType()) | ||
.build(); | ||
|
||
// collect output columns info | ||
ImmutableList.Builder<OutputColumn> outputColumnsBuilder = ImmutableList.builder(); | ||
for (Field field : queryScope.getRelationType().getVisibleFields()) { | ||
OutputColumn outputColumn = new OutputColumn(new Column(field.getName().orElse(""), field.getType().toString()), analysis.getSourceColumns(field)); | ||
outputColumnsBuilder.add(outputColumn); | ||
} | ||
|
||
analysis.setScope(node, queryScope); | ||
ImmutableList<OutputColumn> outputColumns = outputColumnsBuilder.build(); | ||
if (!outputColumns.isEmpty()) { | ||
QualifiedObjectName qualifiedName = new QualifiedObjectName("", "", ""); | ||
CatalogHandle.CatalogVersion version = new CatalogHandle.CatalogVersion("1"); | ||
if (node.getQueryBody() instanceof QuerySpecification querySpecification) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is a bit brittle as we capture them only for simple queries and not for queries which has |
||
Optional<Relation> from = querySpecification.getFrom(); | ||
if (from.isPresent() && from.get() instanceof Table) { | ||
qualifiedName = createQualifiedObjectName(session, from.get(), ((Table) from.get()).getName()); | ||
try { | ||
CatalogHandle catalogHandle = getRequiredCatalogHandle(metadata, session, node, qualifiedName.catalogName()); | ||
version = catalogHandle.getVersion(); | ||
} | ||
catch (TrinoException e) { | ||
// ignore since catalog might not be available | ||
} | ||
} | ||
} | ||
analysis.setUpdateTarget(version, qualifiedName, Optional.empty(), Optional.of(outputColumns)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did think about this and tried to first add a dedicated target but it required quite a bit of plumbing and changes creeped in across many classes and ultimately the EventListener as well; hence the snippet in the description of the PR. So I wasn't sure if we want to go down a major change. |
||
} | ||
return queryScope; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import io.trino.spi.connector.ConnectorFactory; | ||
import io.trino.spi.eventlistener.QueryCompletedEvent; | ||
import io.trino.spi.eventlistener.QueryCreatedEvent; | ||
import io.trino.spi.eventlistener.QueryOutputMetadata; | ||
import io.trino.spi.eventlistener.QueryStatistics; | ||
import io.trino.spi.eventlistener.SplitCompletedEvent; | ||
import io.trino.spi.resourcegroups.QueryType; | ||
|
@@ -122,7 +123,10 @@ public void testSplitsForNormalQuery() | |
QueryCompletedEvent queryCompletedEvent = queryEvents.getQueryCompletedEvent(); | ||
assertThat(queryCompletedEvent.getContext().getResourceGroupId().isPresent()).isTrue(); | ||
assertThat(queryCompletedEvent.getContext().getResourceGroupId().get()).isEqualTo(createResourceGroupId("global", "user-user")); | ||
assertThat(queryCompletedEvent.getIoMetadata().getOutput()).isEqualTo(Optional.empty()); | ||
Optional<QueryOutputMetadata> output = queryCompletedEvent.getIoMetadata().getOutput(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of capturing this event for @martint - Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did take a stab at storing these info separately from |
||
assertThat(output).isNotEmpty(); | ||
assertThat(output.get().getColumns()).isNotEmpty(); | ||
assertThat(output.get().getColumns().get().size()).isEqualTo(1); | ||
assertThat(queryCompletedEvent.getIoMetadata().getInputs().size()).isEqualTo(1); | ||
assertThat(queryCompletedEvent.getContext().getClientInfo().get()).isEqualTo("{\"clientVersion\":\"testVersion\"}"); | ||
assertThat(getOnlyElement(queryCompletedEvent.getIoMetadata().getInputs()).getCatalogName()).isEqualTo("tpch"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: List