Search in sources :

Example 56 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class LogicalPlanner method createVacuumTablePlan.

private RelationPlan createVacuumTablePlan(Analysis analysis, VacuumTable vacuumTable) {
    TableHandle handle = analysis.getTableHandle(vacuumTable.getTable());
    TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
    List<ColumnMetadata> columns = tableMetadata.getColumns();
    List<String> columnNames = columns.stream().filter(column -> !column.isHidden()).map(ColumnMetadata::getName).collect(Collectors.toList());
    List<Symbol> symbols = columns.stream().filter(column -> !column.isHidden()).map(c -> planSymbolAllocator.newSymbol(c.getName(), c.getType())).collect(Collectors.toList());
    ColumnHandle rowIdHandle = metadata.getDeleteRowIdColumnHandle(session, handle);
    ColumnMetadata rowIdColumnMetadata = metadata.getColumnMetadata(session, handle, rowIdHandle);
    Type rowIdType = rowIdColumnMetadata.getType();
    Symbol rowIdSymbol = planSymbolAllocator.newSymbol("$rowId", rowIdType);
    symbols.add(rowIdSymbol);
    columnNames.add(rowIdHandle.getColumnName());
    String catalogName = handle.getCatalogName().getCatalogName();
    TableStatisticsMetadata statisticsMetadata = TableStatisticsMetadata.empty();
    return createVacuumWriterPlan(analysis, handle, vacuumTable, new VacuumTargetReference(handle, vacuumTable.isFull(), vacuumTable.isUnify(), vacuumTable.getPartition()), symbols, columnNames, statisticsMetadata);
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) GREATER_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) LongSupplier(java.util.function.LongSupplier) CostCalculator(io.prestosql.cost.CostCalculator) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) CreateReference(io.prestosql.sql.planner.plan.TableWriterNode.CreateReference) AggregationNode(io.prestosql.spi.plan.AggregationNode) Cast(io.prestosql.sql.tree.Cast) Statement(io.prestosql.sql.tree.Statement) WarningCollector(io.prestosql.execution.warnings.WarningCollector) ExpressionFormatter(io.prestosql.sql.ExpressionFormatter) SystemSessionProperties.isSkipAttachingStatsWithPlan(io.prestosql.SystemSessionProperties.isSkipAttachingStatsWithPlan) PlanSanityChecker(io.prestosql.sql.planner.sanity.PlanSanityChecker) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OutputNode(io.prestosql.sql.planner.plan.OutputNode) CubeFilter(io.hetu.core.spi.cube.CubeFilter) Identifier(io.prestosql.sql.tree.Identifier) CostProvider(io.prestosql.cost.CostProvider) Delete(io.prestosql.sql.tree.Delete) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) Set(java.util.Set) NullLiteral(io.prestosql.sql.tree.NullLiteral) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) Insert(io.prestosql.sql.tree.Insert) NodeRef(io.prestosql.sql.tree.NodeRef) CachingCostProvider(io.prestosql.cost.CachingCostProvider) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ExpressionUtils(io.prestosql.sql.ExpressionUtils) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) VacuumTargetReference(io.prestosql.sql.planner.plan.TableWriterNode.VacuumTargetReference) StringLiteral(io.prestosql.sql.tree.StringLiteral) StatisticAggregations(io.prestosql.sql.planner.plan.StatisticAggregations) StatisticsWriterNode(io.prestosql.sql.planner.plan.StatisticsWriterNode) VacuumTableNode(io.prestosql.sql.planner.plan.VacuumTableNode) WriterTarget(io.prestosql.sql.planner.plan.TableWriterNode.WriterTarget) Field(io.prestosql.sql.analyzer.Field) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) Analyze(io.prestosql.sql.tree.Analyze) FIXED_HASH_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION) TableMetadata(io.prestosql.metadata.TableMetadata) VacuumTable(io.prestosql.sql.tree.VacuumTable) CharType(io.prestosql.spi.type.CharType) Node(io.prestosql.sql.tree.Node) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Session(io.prestosql.Session) ParsingUtil.createParsingOptions(io.prestosql.sql.ParsingUtil.createParsingOptions) Signature(io.prestosql.spi.function.Signature) DeleteNode(io.prestosql.sql.planner.plan.DeleteNode) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) StatsProvider(io.prestosql.cost.StatsProvider) Query(io.prestosql.sql.tree.Query) Assignments(io.prestosql.spi.plan.Assignments) QUERY_REJECTED(io.prestosql.spi.StandardErrorCode.QUERY_REJECTED) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) Explain(io.prestosql.sql.tree.Explain) MetadataUtil.toSchemaTableName(io.prestosql.metadata.MetadataUtil.toSchemaTableName) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) ValuesNode(io.prestosql.spi.plan.ValuesNode) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) LimitNode(io.prestosql.spi.plan.LimitNode) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) VarcharType(io.prestosql.spi.type.VarcharType) Expression(io.prestosql.sql.tree.Expression) StatisticAggregationsDescriptor(io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor) QualifiedName(io.prestosql.sql.tree.QualifiedName) APPLY_ALL_RULES(io.prestosql.spi.plan.PlanNode.SkipOptRuleLevel.APPLY_ALL_RULES) SqlParser(io.prestosql.sql.parser.SqlParser) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) TableFinishNode(io.prestosql.sql.planner.plan.TableFinishNode) Type(io.prestosql.spi.type.Type) TypeCoercion(io.prestosql.type.TypeCoercion) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) StatsCalculator(io.prestosql.cost.StatsCalculator) NewTableLayout(io.prestosql.metadata.NewTableLayout) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) CatalogName(io.prestosql.spi.connector.CatalogName) ROW_COUNT(io.prestosql.spi.statistics.TableStatisticType.ROW_COUNT) UUID(java.util.UUID) RelationType(io.prestosql.sql.analyzer.RelationType) CubeFinishNode(io.prestosql.sql.planner.plan.CubeFinishNode) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) OptimizerUtils(io.prestosql.utils.OptimizerUtils) Scope(io.prestosql.sql.analyzer.Scope) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Analysis(io.prestosql.sql.analyzer.Analysis) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) IfExpression(io.prestosql.sql.tree.IfExpression) StatsAndCosts(io.prestosql.cost.StatsAndCosts) HashMap(java.util.HashMap) RelationId(io.prestosql.sql.analyzer.RelationId) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) NOT_FOUND(io.prestosql.spi.StandardErrorCode.NOT_FOUND) TableHandle(io.prestosql.spi.metadata.TableHandle) Function(java.util.function.Function) HashSet(java.util.HashSet) CubeStatus(io.hetu.core.spi.cube.CubeStatus) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) Verify.verify(com.google.common.base.Verify.verify) InsertReference(io.prestosql.sql.planner.plan.TableWriterNode.InsertReference) Objects.requireNonNull(java.util.Objects.requireNonNull) TableStatisticAggregation(io.prestosql.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) Symbol(io.prestosql.spi.plan.Symbol) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) CubeUpdateMetadata(io.prestosql.spi.cube.CubeUpdateMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) UpdateNode(io.prestosql.sql.planner.plan.UpdateNode) LambdaArgumentDeclaration(io.prestosql.sql.tree.LambdaArgumentDeclaration) Update(io.prestosql.sql.tree.Update) InsertCube(io.prestosql.sql.tree.InsertCube) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) DISTRIBUTED_PLAN_SANITY_CHECKER(io.prestosql.sql.planner.sanity.PlanSanityChecker.DISTRIBUTED_PLAN_SANITY_CHECKER) ExplainAnalyzeNode(io.prestosql.sql.planner.plan.ExplainAnalyzeNode) Streams.zip(com.google.common.collect.Streams.zip) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) Symbol(io.prestosql.spi.plan.Symbol) VacuumTargetReference(io.prestosql.sql.planner.plan.TableWriterNode.VacuumTargetReference) CharType(io.prestosql.spi.type.CharType) VarcharType(io.prestosql.spi.type.VarcharType) Type(io.prestosql.spi.type.Type) RelationType(io.prestosql.sql.analyzer.RelationType) TableHandle(io.prestosql.spi.metadata.TableHandle)

Example 57 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class LogicalPlanner method createUpdatePlan.

private RelationPlan createUpdatePlan(Analysis analysis, Update node) {
    TableHandle handle = analysis.getTableHandle(node.getTable());
    if (handle.getConnectorHandle().isUpdateAsInsertSupported()) {
        QueryPlanner.UpdateDeleteRelationPlan updatePlan = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).planUpdateRowAsInsert(node);
        RelationPlan plan = updatePlan.getPlan();
        Analysis.Update update = analysis.getUpdate().get();
        TableMetadata tableMetadata = metadata.getTableMetadata(session, update.getTarget());
        Optional<NewTableLayout> newTableLayout = metadata.getUpdateLayout(session, update.getTarget());
        String catalogName = update.getTarget().getCatalogName().getCatalogName();
        TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, catalogName, tableMetadata.getMetadata());
        Optional<Expression> constraint = updatePlan.getPredicate().isPresent() ? Optional.of(OriginalExpressionUtils.castToExpression(updatePlan.getPredicate().get())) : Optional.empty();
        return createTableWriterPlan(analysis, plan, new TableWriterNode.UpdateReference(update.getTarget(), constraint, updatePlan.getColumnAssignments()), updatePlan.getColumNames(), newTableLayout, statisticsMetadata);
    }
    UpdateNode updateNode = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).plan(node);
    TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), updateNode, updateNode.getTarget(), planSymbolAllocator.newSymbol("rows", BIGINT), Optional.empty(), Optional.empty());
    return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputSymbols());
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) UpdateNode(io.prestosql.sql.planner.plan.UpdateNode) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) NewTableLayout(io.prestosql.metadata.NewTableLayout) TableFinishNode(io.prestosql.sql.planner.plan.TableFinishNode) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) IfExpression(io.prestosql.sql.tree.IfExpression) Analysis(io.prestosql.sql.analyzer.Analysis) TableHandle(io.prestosql.spi.metadata.TableHandle) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode)

Example 58 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class QueryPlanner method planDeleteRowAsInsert.

public UpdateDeleteRelationPlan planDeleteRowAsInsert(Delete node) {
    Table table = node.getTable();
    RelationType descriptor = analysis.getOutputDescriptor(node.getTable());
    TableHandle handle = analysis.getTableHandle(node.getTable());
    ColumnHandle rowIdHandle = analysis.getRowIdHandle(table);
    Type rowIdType = metadata.getColumnMetadata(session, handle, rowIdHandle).getType();
    ImmutableList.Builder<Symbol> outputSymbols = ImmutableList.builder();
    ImmutableMap.Builder<Symbol, ColumnHandle> columnsBuilder = ImmutableMap.builder();
    ColumnMetadata rowIdColumnMetadata = metadata.getColumnMetadata(session, handle, rowIdHandle);
    ImmutableList.Builder<Field> fields = ImmutableList.builder();
    ImmutableList.Builder<Field> projectionFields = ImmutableList.builder();
    Symbol orderBySymbol = null;
    // add table columns
    for (Field field : descriptor.getAllFields()) {
        Symbol symbol = planSymbolAllocator.newSymbol(field.getName().get(), field.getType());
        outputSymbols.add(symbol);
        ColumnHandle column = analysis.getColumn(field);
        columnsBuilder.put(symbol, column);
        fields.add(field);
        ColumnMetadata columnMetadata = metadata.getColumnMetadata(session, handle, column);
        if (columnMetadata.isRequired()) {
            projectionFields.add(field);
        }
        if (field.getName().toString().contains("rowId")) {
            projectionFields.add(field);
        }
        if (field.getName().toString().contains("tupleId")) {
            projectionFields.add(field);
        }
    }
    // create table scan
    ImmutableMap<Symbol, ColumnHandle> columns = columnsBuilder.build();
    PlanNode tableScan = TableScanNode.newInstance(idAllocator.getNextId(), handle, outputSymbols.build(), columns, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
    Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build();
    RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
    TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToSymbolMap);
    translations.setFieldMappings(relationPlan.getFieldMappings());
    PlanBuilder builder = new PlanBuilder(translations, relationPlan.getRoot());
    Optional<RowExpression> predicate = Optional.empty();
    if (node.getWhere().isPresent()) {
        builder = filter(builder, node.getWhere().get(), node);
        if (builder.getRoot() instanceof FilterNode) {
            predicate = Optional.of(((FilterNode) builder.getRoot()).getPredicate());
        }
    }
    Assignments.Builder assignments = Assignments.builder();
    TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
    for (Map.Entry<Symbol, ColumnHandle> entry : columns.entrySet()) {
        ColumnMetadata column;
        ColumnHandle columnHandle = entry.getValue();
        Symbol input = entry.getKey();
        if (columnHandle.getColumnName().equals(rowIdHandle.getColumnName())) {
            column = rowIdColumnMetadata;
        } else {
            column = tableMetadata.getColumn(columnHandle.getColumnName());
        }
        if (column != rowIdColumnMetadata && (column.isHidden() || !column.isRequired())) {
            // Skip unnecessary columns as well.
            continue;
        }
        Symbol output = planSymbolAllocator.newSymbol(column.getName(), column.getType());
        Type tableType = column.getType();
        Type queryType = planSymbolAllocator.getTypes().get(input);
        if (queryType.equals(tableType) || typeCoercion.isTypeOnlyCoercion(queryType, tableType)) {
            assignments.put(output, castToRowExpression(toSymbolReference(input)));
        } else {
            Expression cast = new Cast(toSymbolReference(input), tableType.getTypeSignature().toString());
            assignments.put(output, castToRowExpression(cast));
        }
        if (column == rowIdColumnMetadata) {
            orderBySymbol = output;
        }
    }
    ProjectNode projectNode = new ProjectNode(idAllocator.getNextId(), builder.getRoot(), assignments.build());
    builder = new PlanBuilder(translations, projectNode);
    scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(projectionFields.build())).build();
    RelationPlan plan = new RelationPlan(builder.getRoot(), scope, projectNode.getOutputSymbols());
    List<String> visibleTableColumnNames = tableMetadata.getColumns().stream().filter(c -> c.isRequired()).map(ColumnMetadata::getName).collect(Collectors.toList());
    visibleTableColumnNames.add(rowIdColumnMetadata.getName());
    return new UpdateDeleteRelationPlan(plan, visibleTableColumnNames, columns, predicate);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) Assignments(io.prestosql.spi.plan.Assignments) Field(io.prestosql.sql.analyzer.Field) PlanNode(io.prestosql.spi.plan.PlanNode) RelationType(io.prestosql.sql.analyzer.RelationType) UUID(java.util.UUID) TableMetadata(io.prestosql.metadata.TableMetadata) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Table(io.prestosql.sql.tree.Table) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(io.prestosql.spi.relation.RowExpression) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) Type(io.prestosql.spi.type.Type) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) RelationType(io.prestosql.sql.analyzer.RelationType) Scope(io.prestosql.sql.analyzer.Scope) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) Expression(io.prestosql.sql.tree.Expression) RowExpression(io.prestosql.spi.relation.RowExpression) TableHandle(io.prestosql.spi.metadata.TableHandle) ProjectNode(io.prestosql.spi.plan.ProjectNode) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 59 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class QueryPlanner method plan.

public UpdateNode plan(Update node) {
    Table table = node.getTable();
    TableHandle handle = analysis.getTableHandle(table);
    TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
    List<ColumnMetadata> dataColumns = tableMetadata.getMetadata().getColumns().stream().filter(column -> !column.isHidden()).collect(toImmutableList());
    List<String> targetColumnNames = node.getAssignmentItems().stream().map(assignment -> assignment.getName().toString()).collect(toImmutableList());
    // Create lists of columnnames and SET expressions, in table column order
    ImmutableList.Builder<String> updatedColumnNamesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Type> updatedColumnTypesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Expression> orderedColumnValuesBuilder = ImmutableList.builder();
    ImmutableMap.Builder<String, Expression> setExpressions = new ImmutableMap.Builder<>();
    for (ColumnMetadata columnMetadata : dataColumns) {
        String name = columnMetadata.getName();
        Type type = columnMetadata.getType();
        int index = targetColumnNames.indexOf(name);
        if (index >= 0) {
            updatedColumnNamesBuilder.add(name);
            updatedColumnTypesBuilder.add(type);
            orderedColumnValuesBuilder.add(node.getAssignmentItems().get(index).getValue());
            setExpressions.put(name, node.getAssignmentItems().get(index).getValue());
        }
    }
    List<String> updatedColumnNames = updatedColumnNamesBuilder.build();
    List<Type> updatedColumnTypes = updatedColumnTypesBuilder.build();
    List<Expression> orderedColumnValues = orderedColumnValuesBuilder.build();
    // create table scan
    RelationPlan relationPlan = new RelationPlanner(analysis, planSymbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, metadata, session, namedSubPlan, uniqueIdAllocator).process(table, null);
    PlanBuilder builder = planBuilderFor(relationPlan);
    if (node.getWhere().isPresent()) {
        builder = filter(builder, node.getWhere().get(), node);
    }
    builder = builder.appendProjections(orderedColumnValues, planSymbolAllocator, idAllocator);
    PlanAndMappings planAndMappings = coerce(builder, orderedColumnValues, analysis, idAllocator, planSymbolAllocator, typeCoercion);
    builder = planAndMappings.getSubPlan();
    ImmutableList.Builder<Symbol> updatedColumnValuesBuilder = ImmutableList.builder();
    orderedColumnValues.forEach(columnValue -> updatedColumnValuesBuilder.add(planAndMappings.get(columnValue)));
    Symbol rowId = builder.translate(analysis.getRowIdField(table));
    updatedColumnValuesBuilder.add(rowId);
    List<Symbol> outputs = ImmutableList.of(planSymbolAllocator.newSymbol("partialrows", BIGINT), planSymbolAllocator.newSymbol("fragment", VARBINARY));
    Optional<PlanNodeId> tableScanId = getIdForLeftTableScan(relationPlan.getRoot());
    checkArgument(tableScanId.isPresent(), "tableScanId not present");
    // create update node
    return new UpdateNode(idAllocator.getNextId(), builder.getRoot(), new TableWriterNode.UpdateTarget(handle, metadata.getTableMetadata(session, handle).getTable(), updatedColumnNames, updatedColumnTypes), rowId, updatedColumnValuesBuilder.build(), outputs, setExpressions.build());
}
Also used : Table(io.prestosql.sql.tree.Table) SortNode(io.prestosql.sql.planner.plan.SortNode) Property(io.prestosql.sql.tree.Property) SortOrder(io.prestosql.spi.block.SortOrder) AggregationNode(io.prestosql.spi.plan.AggregationNode) Cast(io.prestosql.sql.tree.Cast) HeuristicIndexUtils(io.prestosql.utils.HeuristicIndexUtils) Statement(io.prestosql.sql.tree.Statement) HetuConstant(io.prestosql.spi.HetuConstant) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) FetchFirst(io.prestosql.sql.tree.FetchFirst) Identifier(io.prestosql.sql.tree.Identifier) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) CreateIndexNode(io.prestosql.sql.planner.plan.CreateIndexNode) AssignmentItem(io.prestosql.sql.tree.AssignmentItem) Delete(io.prestosql.sql.tree.Delete) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) NodeRef(io.prestosql.sql.tree.NodeRef) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) SymbolReference(io.prestosql.sql.tree.SymbolReference) StringLiteral(io.prestosql.sql.tree.StringLiteral) LEVEL_PROP_KEY(io.prestosql.spi.connector.CreateIndexMetadata.LEVEL_PROP_KEY) SymbolUtils.from(io.prestosql.sql.planner.SymbolUtils.from) Field(io.prestosql.sql.analyzer.Field) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) GroupIdNode(io.prestosql.spi.plan.GroupIdNode) Iterables(com.google.common.collect.Iterables) TableMetadata(io.prestosql.metadata.TableMetadata) NodeUtils.getSortItemsFromOrderBy(io.prestosql.sql.NodeUtils.getSortItemsFromOrderBy) Node(io.prestosql.sql.tree.Node) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OrderingSchemeUtils.sortItemToSortOrder(io.prestosql.sql.planner.OrderingSchemeUtils.sortItemToSortOrder) MetadataUtil(io.prestosql.metadata.MetadataUtil) Session(io.prestosql.Session) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) DeleteNode(io.prestosql.sql.planner.plan.DeleteNode) AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) Properties(java.util.Properties) Query(io.prestosql.sql.tree.Query) Assignments(io.prestosql.spi.plan.Assignments) Streams.stream(com.google.common.collect.Streams.stream) DeleteTarget(io.prestosql.sql.planner.plan.TableWriterNode.DeleteTarget) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) ValuesNode(io.prestosql.spi.plan.ValuesNode) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) CreateIndexMetadata(io.prestosql.spi.connector.CreateIndexMetadata) WindowNode(io.prestosql.spi.plan.WindowNode) LimitNode(io.prestosql.spi.plan.LimitNode) Expression(io.prestosql.sql.tree.Expression) OffsetNode(io.prestosql.sql.planner.plan.OffsetNode) CURRENT_ROW(io.prestosql.spi.sql.expression.Types.FrameBoundType.CURRENT_ROW) UpdateIndexNode(io.prestosql.sql.planner.plan.UpdateIndexNode) UNBOUNDED_PRECEDING(io.prestosql.spi.sql.expression.Types.FrameBoundType.UNBOUNDED_PRECEDING) QualifiedName(io.prestosql.sql.tree.QualifiedName) FieldReference(io.prestosql.sql.tree.FieldReference) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) FilterNode(io.prestosql.spi.plan.FilterNode) Expressions.call(io.prestosql.sql.relational.Expressions.call) WindowFrame(io.prestosql.sql.tree.WindowFrame) Locale(java.util.Locale) Window(io.prestosql.sql.tree.Window) Type(io.prestosql.spi.type.Type) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) TypeCoercion(io.prestosql.type.TypeCoercion) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) ImmutableSet(com.google.common.collect.ImmutableSet) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) ImmutableMap(com.google.common.collect.ImmutableMap) GroupingOperation(io.prestosql.sql.tree.GroupingOperation) SystemSessionProperties.isSkipRedundantSort(io.prestosql.SystemSessionProperties.isSkipRedundantSort) RANGE(io.prestosql.spi.sql.expression.Types.WindowFrameType.RANGE) CreateIndex(io.prestosql.sql.tree.CreateIndex) PropertyService(io.prestosql.spi.service.PropertyService) UUID(java.util.UUID) RelationType(io.prestosql.sql.analyzer.RelationType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Pair(io.prestosql.spi.heuristicindex.Pair) String.format(java.lang.String.format) Scope(io.prestosql.sql.analyzer.Scope) List(java.util.List) AggregationNode.groupingSets(io.prestosql.spi.plan.AggregationNode.groupingSets) Entry(java.util.Map.Entry) Optional(java.util.Optional) Analysis(io.prestosql.sql.analyzer.Analysis) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FieldId(io.prestosql.sql.analyzer.FieldId) IntStream(java.util.stream.IntStream) UpdateIndex(io.prestosql.sql.tree.UpdateIndex) UpdateIndexMetadata(io.prestosql.spi.connector.UpdateIndexMetadata) HashMap(java.util.HashMap) RelationId(io.prestosql.sql.analyzer.RelationId) TableHandle(io.prestosql.spi.metadata.TableHandle) DecimalLiteral(io.prestosql.sql.tree.DecimalLiteral) INDEX_SUPPORTED_TYPES(io.prestosql.spi.connector.CreateIndexMetadata.INDEX_SUPPORTED_TYPES) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) Objects.requireNonNull(java.util.Objects.requireNonNull) SortItem(io.prestosql.sql.tree.SortItem) Symbol(io.prestosql.spi.plan.Symbol) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) Iterator(java.util.Iterator) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) OrderBy(io.prestosql.sql.tree.OrderBy) UpdateNode(io.prestosql.sql.planner.plan.UpdateNode) LambdaArgumentDeclaration(io.prestosql.sql.tree.LambdaArgumentDeclaration) Update(io.prestosql.sql.tree.Update) Offset(io.prestosql.sql.tree.Offset) AUTOLOAD_PROP_KEY(io.prestosql.spi.connector.CreateIndexMetadata.AUTOLOAD_PROP_KEY) Aggregation(io.prestosql.spi.plan.AggregationNode.Aggregation) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) RowExpression(io.prestosql.spi.relation.RowExpression) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) TableMetadata(io.prestosql.metadata.TableMetadata) UpdateNode(io.prestosql.sql.planner.plan.UpdateNode) Table(io.prestosql.sql.tree.Table) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) Type(io.prestosql.spi.type.Type) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) RelationType(io.prestosql.sql.analyzer.RelationType) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) Expression(io.prestosql.sql.tree.Expression) RowExpression(io.prestosql.spi.relation.RowExpression) TableHandle(io.prestosql.spi.metadata.TableHandle)

Example 60 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TestStarTreeAggregationRule method setupBeforeClass.

@BeforeClass
public void setupBeforeClass() {
    PlanSymbolAllocator symbolAllocator = new PlanSymbolAllocator();
    columnOrderkey = symbolAllocator.newSymbol("orderkey", BIGINT);
    columnOrderDate = symbolAllocator.newSymbol("orderdate", DATE);
    columnCustkey = symbolAllocator.newSymbol("custkey", BIGINT);
    columnTotalprice = symbolAllocator.newSymbol("totalprice", DOUBLE);
    orderkeyHandle = new TpchColumnHandle("orderkey", BIGINT);
    orderdateHandle = new TpchColumnHandle("orderdate", DATE);
    custkeyHandle = new TpchColumnHandle("custkey", BIGINT);
    totalpriceHandle = new TpchColumnHandle("totalprice", DOUBLE);
    ColumnMetadata orderKeyColumnMetadata = new ColumnMetadata(orderkeyHandle.getColumnName(), orderkeyHandle.getType());
    ColumnMetadata orderDateColumnMetadata = new ColumnMetadata(orderdateHandle.getColumnName(), orderdateHandle.getType());
    ColumnMetadata custKeyColumnMetadata = new ColumnMetadata(custkeyHandle.getColumnName(), custkeyHandle.getType());
    ColumnMetadata totalPriceColumnMetadata = new ColumnMetadata(totalpriceHandle.getColumnName(), totalpriceHandle.getType());
    output = symbolAllocator.newSymbol("output", DOUBLE);
    assignments = ImmutableMap.<Symbol, ColumnHandle>builder().put(columnOrderkey, orderkeyHandle).put(columnOrderDate, orderdateHandle).put(columnCustkey, custkeyHandle).put(columnTotalprice, totalpriceHandle).build();
    TpchTableHandle orders = new TpchTableHandle("orders", 1.0);
    ordersTableHandle = new TableHandle(tester().getCurrentConnectorId(), orders, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(orders, TupleDomain.all())));
    baseTableScan = new TableScanNode(newId(), ordersTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
    QualifiedObjectName baseTableName = QualifiedObjectName.valueOf(baseTableScan.getTable().getFullyQualifiedName());
    baseTableMetadata = new TableMetadata(ordersTableHandle.getCatalogName(), new ConnectorTableMetadata(new SchemaTableName(baseTableName.getSchemaName(), baseTableName.getObjectName()), Arrays.asList(orderKeyColumnMetadata, orderDateColumnMetadata, custKeyColumnMetadata, totalPriceColumnMetadata)));
    columnCountAll = symbolAllocator.newSymbol("count_all", BIGINT);
    columnSumTotalPrice = symbolAllocator.newSymbol("sum_totalprice", DOUBLE);
    columnCountOrderKey = symbolAllocator.newSymbol("count_orderkey", BIGINT);
    columnGroupingBitSet = symbolAllocator.newSymbol("grouping_bit_set", BIGINT);
    cubeColumnCustKey = symbolAllocator.newSymbol("custkey", BIGINT);
    cubeColumnOrderDate = symbolAllocator.newSymbol("orderdate", DATE);
    countAllHandle = new TpchColumnHandle("count_all", BIGINT);
    sumTotalPriceHandle = new TpchColumnHandle("sum_totalprice", DOUBLE);
    countOrderKeyHandle = new TpchColumnHandle("count_orderkey", BIGINT);
    groupingBitSetHandle = new TpchColumnHandle("grouping_bit_set", BIGINT);
    custKeyCubeColumnHandle = new TpchColumnHandle("custkey", BIGINT);
    orderDateCubeColumnHandle = new TpchColumnHandle("orderdate", DATE);
    ordersCubeColumnHandles.put(countAllHandle.getColumnName(), countAllHandle);
    ordersCubeColumnHandles.put(sumTotalPriceHandle.getColumnName(), sumTotalPriceHandle);
    ordersCubeColumnHandles.put(countOrderKeyHandle.getColumnName(), countOrderKeyHandle);
    ordersCubeColumnHandles.put(groupingBitSetHandle.getColumnName(), groupingBitSetHandle);
    ordersCubeColumnHandles.put(custKeyCubeColumnHandle.getColumnName(), custKeyCubeColumnHandle);
    ordersCubeColumnHandles.put(orderDateCubeColumnHandle.getColumnName(), orderDateCubeColumnHandle);
    TpchTableHandle ordersCube = new TpchTableHandle("orders_cube", 1.0);
    ordersCubeHandle = new TableHandle(tester().getCurrentConnectorId(), ordersCube, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(ordersCube, TupleDomain.all())));
    countAllColumnMetadata = new ColumnMetadata(countAllHandle.getColumnName(), countAllHandle.getType());
    sumTotalPriceColumnMetadata = new ColumnMetadata(sumTotalPriceHandle.getColumnName(), sumTotalPriceHandle.getType());
    countOrderKeyColumnMetadata = new ColumnMetadata(countOrderKeyHandle.getColumnName(), countOrderKeyHandle.getType());
    groupingBitSetColumnMetadata = new ColumnMetadata(groupingBitSetHandle.getColumnName(), groupingBitSetHandle.getType());
    custKeyCubeColumnMetadata = new ColumnMetadata(custKeyCubeColumnHandle.getColumnName(), custKeyCubeColumnHandle.getType());
    orderDateCubeColumnMetadata = new ColumnMetadata(orderDateCubeColumnHandle.getColumnName(), orderDateCubeColumnHandle.getType());
    config = new FeaturesConfig();
    config.setEnableStarTreeIndex(true);
    cubeManager = Mockito.mock(CubeManager.class);
    provider = Mockito.mock(CubeProvider.class);
    cubeMetaStore = Mockito.mock(CubeMetaStore.class);
    cubeMetadata = Mockito.mock(CubeMetadata.class);
    ordersTableHandleMatcher = new BaseMatcher<TableHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof TableHandle)) {
                return false;
            }
            TableHandle th = (TableHandle) o;
            return th.getFullyQualifiedName().equals(ordersTableHandle.getFullyQualifiedName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
    ordersCubeHandleMatcher = new BaseMatcher<TableHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof TableHandle)) {
                return false;
            }
            TableHandle th = (TableHandle) o;
            return th.getFullyQualifiedName().equals(ordersCubeHandle.getFullyQualifiedName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
    countAllColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(countAllHandle.getColumnName());
        }
    };
    sumTotalPriceColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(sumTotalPriceHandle.getColumnName());
        }
    };
    countOrderKeyColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(countOrderKeyHandle.getColumnName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
    groupingBitSetColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(groupingBitSetHandle.getColumnName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
    orderDateCubeColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(orderDateCubeColumnHandle.getColumnName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
    custKeyCubeColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {

        @Override
        public boolean matches(Object o) {
            if (!(o instanceof ColumnHandle)) {
                return false;
            }
            ColumnHandle ch = (ColumnHandle) o;
            return ch.getColumnName().equalsIgnoreCase(custKeyCubeColumnHandle.getColumnName());
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) Description(org.hamcrest.Description) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) TpchTableLayoutHandle(io.prestosql.plugin.tpch.TpchTableLayoutHandle) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) CubeManager(io.prestosql.cube.CubeManager) TableScanNode(io.prestosql.spi.plan.TableScanNode) CubeProvider(io.prestosql.spi.cube.CubeProvider) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) UUID(java.util.UUID) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

TableMetadata (io.prestosql.metadata.TableMetadata)93 Language (org.intellij.lang.annotations.Language)34 Test (org.testng.annotations.Test)33 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)32 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)23 TableHandle (io.prestosql.spi.metadata.TableHandle)20 Session (io.prestosql.Session)18 Constraint (io.prestosql.spi.connector.Constraint)18 ColumnConstraint (io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint)18 TableScanNode (io.prestosql.spi.plan.TableScanNode)15 Expression (io.prestosql.sql.tree.Expression)15 HashMap (java.util.HashMap)15 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)14 PlanNode (io.prestosql.spi.plan.PlanNode)14 Symbol (io.prestosql.spi.plan.Symbol)14 Map (java.util.Map)14 ImmutableList (com.google.common.collect.ImmutableList)13 ProjectNode (io.prestosql.spi.plan.ProjectNode)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Metadata (io.prestosql.metadata.Metadata)12