-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Track column lineage #7354
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
Track column lineage #7354
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 |
|---|---|---|
|
|
@@ -503,9 +503,7 @@ private Type handleResolvedField(Expression node, ResolvedField resolvedField, S | |
| } | ||
| } | ||
|
|
||
| if (field.getOriginTable().isPresent() && field.getOriginColumnName().isPresent()) { | ||
| tableColumnReferences.put(field.getOriginTable().get(), field.getOriginColumnName().get()); | ||
| } | ||
| field.getOriginColumnDetails().forEach(columnDetail -> tableColumnReferences.put(columnDetail.getTableName(), columnDetail.getColumnName())); | ||
|
|
||
| fieldId.getRelationId() | ||
| .getSourceNode() | ||
|
|
@@ -1973,6 +1971,7 @@ public static ExpressionAnalysis analyzeExpression( | |
| analyzer.analyze(expression, scope); | ||
|
|
||
| updateAnalysis(analysis, analyzer, session, accessControl); | ||
| analysis.addReferencedFields(expression, analyzer.getReferencedFields()); | ||
|
Member
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. Probably |
||
|
|
||
| return new ExpressionAnalysis( | ||
| analyzer.getExpressionTypes(), | ||
|
|
@@ -2030,7 +2029,6 @@ private static void updateAnalysis(Analysis analysis, ExpressionAnalyzer analyze | |
| analysis.addColumnReferences(analyzer.getColumnReferences()); | ||
| analysis.addLambdaArgumentReferences(analyzer.getLambdaArgumentReferences()); | ||
| analysis.addTableColumnReferences(accessControl, session.getIdentity(), analyzer.getTableColumnReferences()); | ||
| analysis.addReferencedFields(analyzer.getReferencedFields()); | ||
| } | ||
|
|
||
| public static ExpressionAnalyzer create( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,18 +13,19 @@ | |
| */ | ||
| package io.trino.sql.analyzer; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import io.trino.metadata.QualifiedObjectName; | ||
| import io.trino.spi.type.Type; | ||
| import io.trino.sql.tree.QualifiedName; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class Field | ||
| { | ||
| private final Optional<QualifiedObjectName> originTable; | ||
| private final Optional<String> originColumnName; | ||
| private final List<OriginColumnDetail> originColumnDetails; | ||
|
Member
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. Could you explain how it is possible to have more than 1 element in this list?
Member
Author
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. Like if we have field for a expression like |
||
| private final Optional<QualifiedName> relationAlias; | ||
| private final Optional<String> name; | ||
| private final Type type; | ||
|
|
@@ -36,61 +37,54 @@ public static Field newUnqualified(String name, Type type) | |
| requireNonNull(name, "name is null"); | ||
| requireNonNull(type, "type is null"); | ||
|
|
||
| return new Field(Optional.empty(), Optional.of(name), type, false, Optional.empty(), Optional.empty(), false); | ||
| return new Field(Optional.empty(), Optional.of(name), type, false, ImmutableList.of(), false); | ||
| } | ||
|
|
||
| public static Field newUnqualified(Optional<String> name, Type type) | ||
| { | ||
| requireNonNull(name, "name is null"); | ||
| requireNonNull(type, "type is null"); | ||
|
|
||
| return new Field(Optional.empty(), name, type, false, Optional.empty(), Optional.empty(), false); | ||
| return new Field(Optional.empty(), name, type, false, ImmutableList.of(), false); | ||
| } | ||
|
|
||
| public static Field newUnqualified(Optional<String> name, Type type, Optional<QualifiedObjectName> originTable, Optional<String> originColumn, boolean aliased) | ||
| public static Field newUnqualified(Optional<String> name, Type type, List<OriginColumnDetail> originColumnDetails, boolean aliased) | ||
| { | ||
| requireNonNull(name, "name is null"); | ||
| requireNonNull(type, "type is null"); | ||
| requireNonNull(originTable, "originTable is null"); | ||
| requireNonNull(originColumnDetails, "originColumnDetails is null"); | ||
|
|
||
| return new Field(Optional.empty(), name, type, false, originTable, originColumn, aliased); | ||
| return new Field(Optional.empty(), name, type, false, originColumnDetails, aliased); | ||
| } | ||
|
|
||
| public static Field newQualified(QualifiedName relationAlias, Optional<String> name, Type type, boolean hidden, Optional<QualifiedObjectName> originTable, Optional<String> originColumn, boolean aliased) | ||
| public static Field newQualified(QualifiedName relationAlias, Optional<String> name, Type type, boolean hidden, List<OriginColumnDetail> originColumnDetails, boolean aliased) | ||
| { | ||
| requireNonNull(relationAlias, "relationAlias is null"); | ||
| requireNonNull(name, "name is null"); | ||
| requireNonNull(type, "type is null"); | ||
| requireNonNull(originTable, "originTable is null"); | ||
| requireNonNull(originColumnDetails, "originColumnDetails is null"); | ||
|
|
||
| return new Field(Optional.of(relationAlias), name, type, hidden, originTable, originColumn, aliased); | ||
| return new Field(Optional.of(relationAlias), name, type, hidden, originColumnDetails, aliased); | ||
| } | ||
|
|
||
| public Field(Optional<QualifiedName> relationAlias, Optional<String> name, Type type, boolean hidden, Optional<QualifiedObjectName> originTable, Optional<String> originColumnName, boolean aliased) | ||
| public Field(Optional<QualifiedName> relationAlias, Optional<String> name, Type type, boolean hidden, List<OriginColumnDetail> originColumnDetails, boolean aliased) | ||
| { | ||
| requireNonNull(relationAlias, "relationAlias is null"); | ||
| requireNonNull(name, "name is null"); | ||
| requireNonNull(type, "type is null"); | ||
| requireNonNull(originTable, "originTable is null"); | ||
| requireNonNull(originColumnName, "originColumnName is null"); | ||
| requireNonNull(originColumnDetails, "originColumnDetails is null"); | ||
|
|
||
| this.relationAlias = relationAlias; | ||
| this.name = name; | ||
| this.type = type; | ||
| this.hidden = hidden; | ||
| this.originTable = originTable; | ||
| this.originColumnName = originColumnName; | ||
| this.originColumnDetails = ImmutableList.copyOf(originColumnDetails); | ||
| this.aliased = aliased; | ||
| } | ||
|
|
||
| public Optional<QualifiedObjectName> getOriginTable() | ||
| public List<OriginColumnDetail> getOriginColumnDetails() | ||
| { | ||
| return originTable; | ||
| } | ||
|
|
||
| public Optional<String> getOriginColumnName() | ||
| { | ||
| return originColumnName; | ||
| return originColumnDetails; | ||
| } | ||
|
|
||
| public Optional<QualifiedName> getRelationAlias() | ||
|
|
@@ -169,4 +163,26 @@ public String toString() | |
|
|
||
| return result.toString(); | ||
| } | ||
|
|
||
| public static class OriginColumnDetail | ||
|
Member
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. The |
||
| { | ||
| private final QualifiedObjectName tableName; | ||
| private final String columnName; | ||
|
|
||
| public OriginColumnDetail(QualifiedObjectName tableName, String columnName) | ||
| { | ||
| this.tableName = requireNonNull(tableName, "tableName is null"); | ||
| this.columnName = requireNonNull(columnName, "columnName is null"); | ||
| } | ||
|
|
||
| public QualifiedObjectName getTableName() | ||
| { | ||
| return tableName; | ||
| } | ||
|
|
||
| public String getColumnName() | ||
| { | ||
| return columnName; | ||
| } | ||
| } | ||
| } | ||
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.
addColumnOriginDetails?