Search in sources :

Example 11 with TpchColumnHandle

use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.

the class TestRemoveRedundantPredicateAboveTableScan method doesNotConsumeRemainingPredicateIfNewDomainIsWider.

@Test
public void doesNotConsumeRemainingPredicateIfNewDomainIsWider() {
    ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
    tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(new LogicalExpression(AND, ImmutableList.of(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44")), LogicalExpression.or(new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "44")), new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "45"))))), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.fromFixedValues(ImmutableMap.of(columnHandle, NullableValue.of(BIGINT, (long) 44)))))).matches(filter(LogicalExpression.and(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44"))), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", singleValue(BIGINT, (long) 44)), ImmutableMap.of("nationkey", "nationkey"))));
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) NullableValue(io.trino.spi.predicate.NullableValue) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) FunctionCallBuilder(io.trino.sql.planner.FunctionCallBuilder) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Slices(io.airlift.slice.Slices) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) TupleDomain(io.trino.spi.predicate.TupleDomain) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) GenericLiteral(io.trino.sql.tree.GenericLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) LogicalExpression(io.trino.sql.tree.LogicalExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) SymbolReference(io.trino.sql.tree.SymbolReference) GenericLiteral(io.trino.sql.tree.GenericLiteral) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 12 with TpchColumnHandle

use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.

the class TestRemoveRedundantPredicateAboveTableScan method consumesDeterministicPredicateIfNewDomainIsNarrower.

@Test
public void consumesDeterministicPredicateIfNewDomainIsNarrower() {
    ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
    tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(expression("nationkey = BIGINT '44' OR nationkey = BIGINT '45' OR nationkey = BIGINT '47'"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.withColumnDomains(ImmutableMap.of(columnHandle, Domain.multipleValues(BIGINT, ImmutableList.of(44L, 45L, 46L))))))).matches(filter(expression("nationkey IN (BIGINT '44', BIGINT '45')"), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", Domain.multipleValues(BIGINT, ImmutableList.of(44L, 45L, 46L))), ImmutableMap.of("nationkey", "nationkey"))));
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) NullableValue(io.trino.spi.predicate.NullableValue) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) FunctionCallBuilder(io.trino.sql.planner.FunctionCallBuilder) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Slices(io.airlift.slice.Slices) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) TupleDomain(io.trino.spi.predicate.TupleDomain) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) GenericLiteral(io.trino.sql.tree.GenericLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 13 with TpchColumnHandle

use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.

the class TestRemoveUnsupportedDynamicFilters method testRemoveUnsupportedCast.

@Test
public void testRemoveUnsupportedCast() {
    // Use lineitem with DOUBLE orderkey to simulate the case of implicit casts
    // Dynamic filter is removed because there isn't an injective mapping from bigint -> double
    Symbol lineitemDoubleOrderKeySymbol = builder.symbol("LINEITEM_DOUBLE_OK", DOUBLE);
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("CAST(LINEITEM_DOUBLE_OK AS BIGINT)")), builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableMap.of(lineitemDoubleOrderKeySymbol, new TpchColumnHandle("orderkey", DOUBLE)))), ordersTableScanNode, ImmutableList.of(new JoinNode.EquiJoinClause(lineitemDoubleOrderKeySymbol, ordersOrderKeySymbol)), ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableList.of(ordersOrderKeySymbol), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(new DynamicFilterId("DF"), ordersOrderKeySymbol)));
    assertPlan(removeUnsupportedDynamicFilters(root), output(join(INNER, ImmutableList.of(equiJoinClause("LINEITEM_DOUBLE_OK", "ORDERS_OK")), ImmutableMap.of(), tableScan("lineitem", ImmutableMap.of("LINEITEM_DOUBLE_OK", "orderkey")), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")))));
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Symbol(io.trino.sql.planner.Symbol) SpatialJoinNode(io.trino.sql.planner.plan.SpatialJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 14 with TpchColumnHandle

use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.

the class TestValidateStreamingAggregations method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("nationkey")).source(p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))));
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("unique"), p.symbol("nationkey")).preGroupedSymbols(p.symbol("unique"), p.symbol("nationkey")).source(p.assignUniqueId(p.symbol("unique"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))))));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Test(org.testng.annotations.Test) Function(java.util.function.Function) PlanNode(io.trino.sql.planner.plan.PlanNode) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) CatalogName(io.trino.connector.CatalogName) TableHandle(io.trino.metadata.TableHandle) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) WarningCollector(io.trino.execution.warnings.WarningCollector) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TypeProvider(io.trino.sql.planner.TypeProvider) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlannerContext(io.trino.sql.PlannerContext) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 15 with TpchColumnHandle

use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.

the class TestUnaliasSymbolReferences method testDynamicFilterIdUnAliased.

@Test
public void testDynamicFilterIdUnAliased() {
    String probeTable = "supplier";
    String buildTable = "nation";
    assertOptimizedPlan(new UnaliasSymbolReferences(getQueryRunner().getMetadata()), (p, session, metadata) -> {
        ColumnHandle column = new TpchColumnHandle("nationkey", BIGINT);
        Symbol buildColumnSymbol = p.symbol("nationkey");
        Symbol buildAlias1 = p.symbol("buildAlias1");
        Symbol buildAlias2 = p.symbol("buildAlias2");
        Symbol probeColumn1 = p.symbol("s_nationkey");
        Symbol probeColumn2 = p.symbol("s_suppkey");
        DynamicFilterId dynamicFilterId1 = new DynamicFilterId("df1");
        DynamicFilterId dynamicFilterId2 = new DynamicFilterId("df2");
        return p.join(INNER, p.filter(// additional filter to test recursive call
        TRUE_LITERAL, p.filter(ExpressionUtils.and(dynamicFilterExpression(metadata, session, probeColumn1, dynamicFilterId1), dynamicFilterExpression(metadata, session, probeColumn2, dynamicFilterId2)), p.tableScan(tableHandle(session, probeTable), ImmutableList.of(probeColumn1, probeColumn2), ImmutableMap.of(probeColumn1, new TpchColumnHandle("nationkey", BIGINT), probeColumn2, new TpchColumnHandle("suppkey", BIGINT))))), p.project(Assignments.of(buildAlias1, buildColumnSymbol.toSymbolReference(), buildAlias2, buildColumnSymbol.toSymbolReference()), p.tableScan(tableHandle(session, buildTable), ImmutableList.of(buildColumnSymbol), ImmutableMap.of(buildColumnSymbol, column))), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(buildAlias1, buildAlias2), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(dynamicFilterId1, buildAlias1, dynamicFilterId2, buildAlias2));
    }, join(INNER, ImmutableList.of(), ImmutableMap.of("probeColumn1", "column", "probeColumn2", "column"), filter(TRUE_LITERAL, filter(TRUE_LITERAL, tableScan(probeTable, ImmutableMap.of("probeColumn1", "suppkey", "probeColumn2", "nationkey")))), project(tableScan(buildTable, ImmutableMap.of("column", "nationkey")))));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Symbol(io.trino.sql.planner.Symbol) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)31 CatalogName (io.trino.connector.CatalogName)25 TableHandle (io.trino.metadata.TableHandle)25 ColumnHandle (io.trino.spi.connector.ColumnHandle)25 TpchTableHandle (io.trino.plugin.tpch.TpchTableHandle)24 Test (org.testng.annotations.Test)24 ImmutableList (com.google.common.collect.ImmutableList)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 TupleDomain (io.trino.spi.predicate.TupleDomain)21 BIGINT (io.trino.spi.type.BigintType.BIGINT)21 QualifiedName (io.trino.sql.tree.QualifiedName)20 BeforeClass (org.testng.annotations.BeforeClass)20 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)19 PlanMatchPattern.filter (io.trino.sql.planner.assertions.PlanMatchPattern.filter)18 SymbolReference (io.trino.sql.tree.SymbolReference)18 Slices (io.airlift.slice.Slices)17 TpchTransactionHandle (io.trino.plugin.tpch.TpchTransactionHandle)17 Domain (io.trino.spi.predicate.Domain)17 NullableValue (io.trino.spi.predicate.NullableValue)17 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)17