Search in sources :

Example 56 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestHiveLogicalPlanner method assertTableLayout.

private void assertTableLayout(Plan plan, String tableName, TupleDomain<Subfield> domainPredicate, RowExpression remainingPredicate, Set<String> predicateColumnNames) {
    TableScanNode tableScan = searchFrom(plan.getRoot()).where(node -> isTableScanNode(node, tableName)).findOnlyElement();
    assertTrue(tableScan.getTable().getLayout().isPresent());
    HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) tableScan.getTable().getLayout().get();
    assertEquals(layoutHandle.getPredicateColumns().keySet(), predicateColumnNames);
    assertEquals(layoutHandle.getDomainPredicate(), domainPredicate);
    assertEquals(layoutHandle.getRemainingPredicate(), remainingPredicate);
    assertEquals(layoutHandle.getRemainingPredicate(), remainingPredicate);
}
Also used : TestingAccessControlManager.privilege(com.facebook.presto.testing.TestingAccessControlManager.privilege) Arrays(java.util.Arrays) SELECT_COLUMN(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.SELECT_COLUMN) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) MatchResult(com.facebook.presto.sql.planner.assertions.MatchResult) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) TupleDomain.withColumnDomains(com.facebook.presto.common.predicate.TupleDomain.withColumnDomains) OPTIMIZE_METADATA_QUERIES_IGNORE_STATS(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES_IGNORE_STATS) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) Slices(io.airlift.slice.Slices) Map(java.util.Map) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) CUSTOMER(io.airlift.tpch.TpchTable.CUSTOMER) Assert.assertFalse(org.testng.Assert.assertFalse) PrincipalPrivileges(com.facebook.presto.hive.metastore.PrincipalPrivileges) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE(com.facebook.presto.hive.HiveSessionProperties.SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE) Set(java.util.Set) PlanMatchPattern.anySymbol(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anySymbol) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) MATERIALIZED_VIEW_MISSING_PARTITIONS_THRESHOLD(com.facebook.presto.hive.HiveSessionProperties.MATERIALIZED_VIEW_MISSING_PARTITIONS_THRESHOLD) PlanMatchPattern.unnest(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.unnest) Collectors.joining(java.util.stream.Collectors.joining) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FileHiveMetastore(com.facebook.presto.hive.metastore.file.FileHiveMetastore) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) PARTIAL_AGGREGATION_PUSHDOWN_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_ENABLED) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Domain.notNull(com.facebook.presto.common.predicate.Domain.notNull) Table(com.facebook.presto.hive.metastore.Table) Slice(io.airlift.slice.Slice) GATHER(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) ArrayList(java.util.ArrayList) ParquetTypeUtils.pushdownColumnNameForSubfield(com.facebook.presto.parquet.ParquetTypeUtils.pushdownColumnNameForSubfield) Identity(com.facebook.presto.spi.security.Identity) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ArrayType(com.facebook.presto.common.type.ArrayType) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) OPTIMIZE_METADATA_QUERIES(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES) Functions(com.google.common.base.Functions) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SymbolAliases(com.facebook.presto.sql.planner.assertions.SymbolAliases) AbstractTestQueryFramework(com.facebook.presto.tests.AbstractTestQueryFramework) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Session(com.facebook.presto.Session) ELIMINATE_CROSS_JOINS(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy.ELIMINATE_CROSS_JOINS) StatsProvider(com.facebook.presto.cost.StatsProvider) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) Domain(com.facebook.presto.common.predicate.Domain) COLLECT_COLUMN_STATISTICS_ON_WRITE(com.facebook.presto.hive.HiveSessionProperties.COLLECT_COLUMN_STATISTICS_ON_WRITE) ColumnHandle(com.facebook.presto.spi.ColumnHandle) PUSHDOWN_FILTER_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) ValueSet(com.facebook.presto.common.predicate.ValueSet) Metadata(com.facebook.presto.metadata.Metadata) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) HiveColumnHandle.isPushedDownSubfield(com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED(com.facebook.presto.SystemSessionProperties.QUERY_OPTIMIZATION_WITH_MATERIALIZED_VIEW_ENABLED) LINE_ITEM(io.airlift.tpch.TpchTable.LINE_ITEM) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ValueSet.ofRanges(com.facebook.presto.common.predicate.ValueSet.ofRanges) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) PUSHDOWN_DEREFERENCE_ENABLED(com.facebook.presto.SystemSessionProperties.PUSHDOWN_DEREFERENCE_ENABLED) Path(org.apache.hadoop.fs.Path) CallExpression(com.facebook.presto.spi.relation.CallExpression) URI(java.net.URI) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) PlanMatchPattern.globalAggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.globalAggregation) ImmutableSet(com.google.common.collect.ImmutableSet) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Domain.singleValue(com.facebook.presto.common.predicate.Domain.singleValue) VarcharType(com.facebook.presto.common.type.VarcharType) Collectors(java.util.stream.Collectors) TRUE_CONSTANT(com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT) PARQUET_DEREFERENCE_PUSHDOWN_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARQUET_DEREFERENCE_PUSHDOWN_ENABLED) String.format(java.lang.String.format) Range(com.facebook.presto.common.predicate.Range) REMOTE_STREAMING(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.REMOTE_STREAMING) Objects(java.util.Objects) List(java.util.List) Range.greaterThan(com.facebook.presto.common.predicate.Range.greaterThan) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) Domain.create(com.facebook.presto.common.predicate.Domain.create) RANGE_FILTERS_ON_SUBSCRIPTS_ENABLED(com.facebook.presto.hive.HiveSessionProperties.RANGE_FILTERS_ON_SUBSCRIPTS_ENABLED) MetastoreUtil.toPartitionValues(com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionValues) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ExpectedValueProvider(com.facebook.presto.sql.planner.assertions.ExpectedValueProvider) OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD(com.facebook.presto.SystemSessionProperties.OPTIMIZE_METADATA_QUERIES_CALL_THRESHOLD) NoHdfsAuthentication(com.facebook.presto.hive.authentication.NoHdfsAuthentication) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) NATION(io.airlift.tpch.TpchTable.NATION) PARTIAL_AGGREGATION_PUSHDOWN_FOR_VARIABLE_LENGTH_DATATYPES_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PARTIAL_AGGREGATION_PUSHDOWN_FOR_VARIABLE_LENGTH_DATATYPES_ENABLED) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) ORDERS(io.airlift.tpch.TpchTable.ORDERS) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Partition(com.facebook.presto.hive.metastore.Partition) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) LOCAL(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) Objects.requireNonNull(java.util.Objects.requireNonNull) PlanMatchPattern.any(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.any) PlanMatchPattern.strictTableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan) Plan(com.facebook.presto.sql.planner.Plan) Domain.multipleValues(com.facebook.presto.common.predicate.Domain.multipleValues) PlanNodeSearcher.searchFrom(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom) RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) INSERT_TABLE(com.facebook.presto.testing.TestingAccessControlManager.TestingPrivilegeType.INSERT_TABLE) Matcher(com.facebook.presto.sql.planner.assertions.Matcher) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Consumer(java.util.function.Consumer) PlanNode(com.facebook.presto.spi.plan.PlanNode) MaterializedResult(com.facebook.presto.testing.MaterializedResult) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) SYNTHESIZED(com.facebook.presto.hive.HiveColumnHandle.ColumnType.SYNTHESIZED) Assert.assertTrue(org.testng.Assert.assertTrue) REFERENCED_MATERIALIZED_VIEWS(com.facebook.presto.hive.HiveMetadata.REFERENCED_MATERIALIZED_VIEWS) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) TestHiveIntegrationSmokeTest.assertRemoteExchangesCount(com.facebook.presto.hive.TestHiveIntegrationSmokeTest.assertRemoteExchangesCount) TableScanNode(com.facebook.presto.spi.plan.TableScanNode)

Example 57 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestHiveLogicalPlanner method testPushdownFilter.

@Test
public void testPushdownFilter() {
    Session pushdownFilterEnabled = pushdownFilterEnabled();
    // Only domain predicates
    assertPlan("SELECT linenumber FROM lineitem WHERE partkey = 10", output(exchange(project(filter("partkey = 10", strictTableScan("lineitem", identityMap("linenumber", "partkey")))))));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE partkey = 10", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), TRUE_CONSTANT, ImmutableSet.of("partkey")));
    assertPlan(pushdownFilterEnabled, "SELECT partkey, linenumber FROM lineitem WHERE partkey = 10", output(exchange(strictTableScan("lineitem", identityMap("partkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), TRUE_CONSTANT, ImmutableSet.of("partkey")));
    // Only remaining predicate
    assertPlan("SELECT linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(project(filter("mod(orderkey, 2) = 1", strictTableScan("lineitem", identityMap("linenumber", "orderkey")))))));
    // Remaining predicate is NULL
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE cardinality(NULL) > 0", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey > 10 AND cardinality(NULL) > 0", output(values("linenumber")));
    // Remaining predicate is always FALSE
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE cardinality(ARRAY[1]) > 1", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey > 10 AND cardinality(ARRAY[1]) > 1", output(values("linenumber")));
    // TupleDomain predicate is always FALSE
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey = 1 AND orderkey = 2", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey = 1 AND orderkey = 2 AND linenumber % 2 = 1", output(values("linenumber")));
    FunctionAndTypeManager functionAndTypeManager = getQueryRunner().getMetadata().getFunctionAndTypeManager();
    FunctionResolution functionResolution = new FunctionResolution(functionAndTypeManager);
    RowExpression remainingPredicate = new CallExpression(EQUAL.name(), functionResolution.comparisonFunction(EQUAL, BIGINT, BIGINT), BOOLEAN, ImmutableList.of(new CallExpression("mod", functionAndTypeManager.lookupFunction("mod", fromTypes(BIGINT, BIGINT)), BIGINT, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey", BIGINT), constant(2))), constant(1)));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", TupleDomain.all(), remainingPredicate, ImmutableSet.of("orderkey")));
    assertPlan(pushdownFilterEnabled, "SELECT orderkey, linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("orderkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", TupleDomain.all(), remainingPredicate, ImmutableSet.of("orderkey")));
    // A mix of domain and remaining predicates
    assertPlan("SELECT linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(project(filter("partkey = 10 AND mod(orderkey, 2) = 1", strictTableScan("lineitem", identityMap("linenumber", "orderkey", "partkey")))))));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), remainingPredicate, ImmutableSet.of("partkey", "orderkey")));
    assertPlan(pushdownFilterEnabled, "SELECT partkey, orderkey, linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("partkey", "orderkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), remainingPredicate, ImmutableSet.of("partkey", "orderkey")));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) CallExpression(com.facebook.presto.spi.relation.CallExpression) ParquetTypeUtils.pushdownColumnNameForSubfield(com.facebook.presto.parquet.ParquetTypeUtils.pushdownColumnNameForSubfield) HiveColumnHandle.isPushedDownSubfield(com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield) Subfield(com.facebook.presto.common.Subfield) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 58 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class RelationPlanner method visitValues.

@Override
protected RelationPlan visitValues(Values node, Void context) {
    Scope scope = analysis.getScope(node);
    ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
    for (Field field : scope.getRelationType().getVisibleFields()) {
        outputVariablesBuilder.add(variableAllocator.newVariable(field));
    }
    ImmutableList.Builder<List<RowExpression>> rowsBuilder = ImmutableList.builder();
    for (Expression row : node.getRows()) {
        ImmutableList.Builder<RowExpression> values = ImmutableList.builder();
        if (row instanceof Row) {
            for (Expression item : ((Row) row).getItems()) {
                values.add(rewriteRow(item));
            }
        } else {
            values.add(rewriteRow(row));
        }
        rowsBuilder.add(values.build());
    }
    ValuesNode valuesNode = new ValuesNode(getSourceLocation(node), idAllocator.getNextId(), outputVariablesBuilder.build(), rowsBuilder.build());
    return new RelationPlan(valuesNode, scope, outputVariablesBuilder.build());
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Field(com.facebook.presto.sql.analyzer.Field) Scope(com.facebook.presto.sql.analyzer.Scope) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) ExpressionTreeUtils.isEqualComparisonExpression(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.isEqualComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Row(com.facebook.presto.sql.tree.Row)

Example 59 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class Partitioning method translateToCoalesce.

// Maps VariableReferenceExpression in both partitions to an COALESCE expression, keeps constant arguments unchanged.
public Optional<Partitioning> translateToCoalesce(Partitioning other, Metadata metadata, Session session) {
    checkArgument(arePartitionHandlesCompatibleForCoalesce(this.handle, other.handle, metadata, session), "incompatible partitioning handles: cannot coalesce %s and %s", this.handle, other.handle);
    checkArgument(this.arguments.size() == other.arguments.size(), "incompatible number of partitioning arguments: %s != %s", this.arguments.size(), other.arguments.size());
    ImmutableList.Builder<RowExpression> arguments = ImmutableList.builder();
    for (int i = 0; i < this.arguments.size(); i++) {
        RowExpression leftArgument = this.arguments.get(i);
        RowExpression rightArgument = other.arguments.get(i);
        if (leftArgument instanceof ConstantExpression) {
            arguments.add(leftArgument);
        } else if (rightArgument instanceof ConstantExpression) {
            arguments.add(rightArgument);
        } else if (leftArgument instanceof VariableReferenceExpression && rightArgument instanceof VariableReferenceExpression) {
            VariableReferenceExpression leftVariable = (VariableReferenceExpression) leftArgument;
            VariableReferenceExpression rightVariable = (VariableReferenceExpression) rightArgument;
            checkArgument(leftVariable.getType().equals(rightVariable.getType()), "incompatible types: %s != %s", leftVariable.getType(), rightVariable.getType());
            arguments.add(new SpecialFormExpression(COALESCE, leftVariable.getType(), ImmutableList.of(leftVariable, rightVariable)));
        } else {
            return Optional.empty();
        }
    }
    return Optional.of(new Partitioning(metadata.isRefinedPartitioningOver(session, other.handle, this.handle) ? this.handle : other.handle, arguments.build()));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression)

Example 60 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestScanFilterAndProjectOperator method testPageSourceLazyLoad.

@Test
public void testPageSourceLazyLoad() {
    Block inputBlock = BlockAssertions.createLongSequenceBlock(0, 100);
    // If column 1 is loaded, test will fail
    Page input = new Page(100, inputBlock, new LazyBlock(100, lazyBlock -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new PageProjectionWithOutputs(new LazyPagePageProjection(), new int[] { 0 })));
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> new SinglePagePageSource(input), cursorProcessor, () -> pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(BIGINT), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), ImmutableList.of(new Page(inputBlock)));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) RecordPageSource(com.facebook.presto.spi.RecordPageSource) Page(com.facebook.presto.common.Page) MetadataManager(com.facebook.presto.metadata.MetadataManager) Test(org.testng.annotations.Test) FixedPageSource(com.facebook.presto.spi.FixedPageSource) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) BlockAssertions(com.facebook.presto.block.BlockAssertions) Expressions.field(com.facebook.presto.sql.relational.Expressions.field) CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) KILOBYTE(io.airlift.units.DataSize.Unit.KILOBYTE) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) PageProjectionWithOutputs(com.facebook.presto.operator.project.PageProjectionWithOutputs) Assert.assertNotNull(org.testng.Assert.assertNotNull) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) DataSize(io.airlift.units.DataSize) List(java.util.List) LazyBlockLoader(com.facebook.presto.common.block.LazyBlockLoader) Optional(java.util.Optional) LazyPagePageProjection(com.facebook.presto.operator.project.TestPageProcessor.LazyPagePageProjection) ConnectorId(com.facebook.presto.spi.ConnectorId) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) LazyBlock(com.facebook.presto.common.block.LazyBlock) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) SequencePageBuilder(com.facebook.presto.SequencePageBuilder) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) MAX_BATCH_SIZE(com.facebook.presto.operator.project.PageProcessor.MAX_BATCH_SIZE) PageAssertions.assertPageEquals(com.facebook.presto.operator.PageAssertions.assertPageEquals) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PageRecordSet(com.facebook.presto.operator.index.PageRecordSet) Supplier(java.util.function.Supplier) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) Iterators(com.google.common.collect.Iterators) TestingSplit(com.facebook.presto.testing.TestingSplit) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) TableHandle(com.facebook.presto.spi.TableHandle) ExecutorService(java.util.concurrent.ExecutorService) RowExpression(com.facebook.presto.spi.relation.RowExpression) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SelectAllFilter(com.facebook.presto.operator.project.TestPageProcessor.SelectAllFilter) Iterator(java.util.Iterator) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) AbstractTestFunctions(com.facebook.presto.operator.scalar.AbstractTestFunctions) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) BlockAssertions.toValues(com.facebook.presto.block.BlockAssertions.toValues) Split(com.facebook.presto.metadata.Split) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Metadata(com.facebook.presto.metadata.Metadata) CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PageProjectionWithOutputs(com.facebook.presto.operator.project.PageProjectionWithOutputs) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) LazyBlock(com.facebook.presto.common.block.LazyBlock) PageProcessor(com.facebook.presto.operator.project.PageProcessor) LazyPagePageProjection(com.facebook.presto.operator.project.TestPageProcessor.LazyPagePageProjection) DataSize(io.airlift.units.DataSize) LazyBlock(com.facebook.presto.common.block.LazyBlock) Block(com.facebook.presto.common.block.Block) SelectAllFilter(com.facebook.presto.operator.project.TestPageProcessor.SelectAllFilter) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Aggregations

RowExpression (com.facebook.presto.spi.relation.RowExpression)237 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)97 Test (org.testng.annotations.Test)87 ImmutableList (com.google.common.collect.ImmutableList)58 CallExpression (com.facebook.presto.spi.relation.CallExpression)52 Map (java.util.Map)49 List (java.util.List)42 Type (com.facebook.presto.common.type.Type)41 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)40 ImmutableMap (com.google.common.collect.ImmutableMap)38 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)37 SpecialFormExpression (com.facebook.presto.spi.relation.SpecialFormExpression)35 Optional (java.util.Optional)35 Expression (com.facebook.presto.sql.tree.Expression)31 ColumnHandle (com.facebook.presto.spi.ColumnHandle)27 Objects.requireNonNull (java.util.Objects.requireNonNull)27 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)24 Set (java.util.Set)24 ArrayList (java.util.ArrayList)23