Search in sources :

Example 1 with TableColumn

use of com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn in project presto by prestodb.

the class MaterializedViewColumnMappingExtractor method getColumnMappings.

private static Map<String, Map<SchemaTableName, String>> getColumnMappings(Analysis analysis, Map<TableColumn, Set<TableColumn>> columnMappings) {
    checkState(analysis.getStatement() instanceof CreateMaterializedView, "Only support the computation of column mappings when analyzing CreateMaterializedView");
    ImmutableMap.Builder<String, Map<SchemaTableName, String>> fullColumnMappings = ImmutableMap.builder();
    Map<String, TableColumn> originalColumnMappings = getOriginalColumnsFromAnalysis(analysis);
    for (Map.Entry<String, TableColumn> columnMapping : originalColumnMappings.entrySet()) {
        String viewColumn = columnMapping.getKey();
        TableColumn originalBaseColumn = columnMapping.getValue();
        Map<SchemaTableName, String> fullBaseColumns = columnMappings.getOrDefault(originalBaseColumn, ImmutableSet.of(originalBaseColumn)).stream().collect(toImmutableMap(e -> e.getTableName(), e -> e.getColumnName()));
        fullColumnMappings.put(viewColumn, fullBaseColumns);
    }
    return fullColumnMappings.build();
}
Also used : Table(com.facebook.presto.sql.tree.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TableColumn(com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn) SchemaTableName(com.facebook.presto.spi.SchemaTableName) MaterializedViewUtils.transitiveClosure(com.facebook.presto.sql.MaterializedViewUtils.transitiveClosure) SetOperation(com.facebook.presto.sql.tree.SetOperation) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet(com.google.common.collect.ImmutableSet) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) Query(com.facebook.presto.sql.tree.Query) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) NOT_SUPPORTED(com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CreateMaterializedView(com.facebook.presto.sql.tree.CreateMaterializedView) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) INNER(com.facebook.presto.sql.tree.Join.Type.INNER) Optional(java.util.Optional) Collections(java.util.Collections) CreateMaterializedView(com.facebook.presto.sql.tree.CreateMaterializedView) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableColumn(com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn) SchemaTableName(com.facebook.presto.spi.SchemaTableName) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 2 with TableColumn

use of com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn in project presto by prestodb.

the class MaterializedViewColumnMappingExtractor method tryGetOriginalTableColumn.

private static Optional<TableColumn> tryGetOriginalTableColumn(Field field) {
    if (field.getOriginTable().isPresent() && field.getOriginColumnName().isPresent()) {
        SchemaTableName table = toSchemaTableName(field.getOriginTable().get());
        String column = field.getOriginColumnName().get();
        return Optional.of(new TableColumn(table, column, true));
    }
    return Optional.empty();
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) TableColumn(com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn)

Aggregations

MetadataUtil.toSchemaTableName (com.facebook.presto.metadata.MetadataUtil.toSchemaTableName)2 TableColumn (com.facebook.presto.spi.ConnectorMaterializedViewDefinition.TableColumn)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 Session (com.facebook.presto.Session)1 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)1 MaterializedViewUtils.transitiveClosure (com.facebook.presto.sql.MaterializedViewUtils.transitiveClosure)1 NOT_SUPPORTED (com.facebook.presto.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 CreateMaterializedView (com.facebook.presto.sql.tree.CreateMaterializedView)1 INNER (com.facebook.presto.sql.tree.Join.Type.INNER)1 Query (com.facebook.presto.sql.tree.Query)1 SetOperation (com.facebook.presto.sql.tree.SetOperation)1 Table (com.facebook.presto.sql.tree.Table)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1