Search in sources :

Example 26 with TpchColumnHandle

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

the class TestPushProjectionIntoTableScan method testPartitioningChanged.

@Test
public void testPartitioningChanged() {
    try (RuleTester ruleTester = defaultRuleTester()) {
        String columnName = "col0";
        ColumnHandle columnHandle = new TpchColumnHandle(columnName, VARCHAR);
        // Create catalog with applyProjection enabled
        MockConnectorFactory factory = createMockFactory(ImmutableMap.of(columnName, columnHandle), Optional.of(this::mockApplyProjection));
        ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, factory, ImmutableMap.of());
        assertThatThrownBy(() -> ruleTester.assertThat(createRule(ruleTester)).on(p -> p.project(Assignments.of(), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(p.symbol("col", VARCHAR)), ImmutableMap.of(p.symbol("col", VARCHAR), columnHandle), Optional.of(true)))).withSession(MOCK_SESSION).matches(anyTree())).hasMessage("Partitioning must not change after projection is pushed down");
    }
}
Also used : TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) Test(org.testng.annotations.Test)

Example 27 with TpchColumnHandle

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

the class TestPushDownDereferencesRules method testExtractDereferencesFromFilterAboveScan.

@Test
public void testExtractDereferencesFromFilterAboveScan() {
    TableHandle testTable = new TableHandle(new CatalogName(CATALOG_ID), new TpchTableHandle("sf1", "orders", 1.0), TestingTransactionHandle.create());
    RowType nestedRowType = RowType.from(ImmutableList.of(new RowType.Field(Optional.of("nested"), ROW_TYPE)));
    tester().assertThat(new ExtractDereferencesFromFilterAboveScan(tester().getTypeAnalyzer())).on(p -> p.filter(expression("a[1][1] != 5 AND b[2] = 2 AND CAST(a[1] as JSON) is not null"), p.tableScan(testTable, ImmutableList.of(p.symbol("a", nestedRowType), p.symbol("b", ROW_TYPE)), ImmutableMap.of(p.symbol("a", nestedRowType), new TpchColumnHandle("a", nestedRowType), p.symbol("b", ROW_TYPE), new TpchColumnHandle("b", ROW_TYPE))))).matches(project(filter("expr != 5 AND expr_0 = 2 AND CAST(expr_1 as JSON) is not null", strictProject(ImmutableMap.of("expr", PlanMatchPattern.expression("a[1][1]"), "expr_0", PlanMatchPattern.expression("b[2]"), "expr_1", PlanMatchPattern.expression("a[1]"), "a", PlanMatchPattern.expression("a"), "b", PlanMatchPattern.expression("b")), tableScan(testTable.getConnectorHandle()::equals, TupleDomain.all(), ImmutableMap.of("a", new TpchColumnHandle("a", nestedRowType)::equals, "b", new TpchColumnHandle("b", ROW_TYPE)::equals))))));
}
Also used : ROW_NUMBER(io.trino.sql.planner.plan.TopNRankingNode.RankingType.ROW_NUMBER) CATALOG_ID(io.trino.sql.planner.iterative.rule.test.RuleTester.CATALOG_ID) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) PlanMatchPattern.assignUniqueId(io.trino.sql.planner.assertions.PlanMatchPattern.assignUniqueId) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) CatalogName(io.trino.connector.CatalogName) PlanMatchPattern.markDistinct(io.trino.sql.planner.assertions.PlanMatchPattern.markDistinct) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ExpressionMatcher(io.trino.sql.planner.assertions.ExpressionMatcher) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RowType(io.trino.spi.type.RowType) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) Assignments(io.trino.sql.planner.plan.Assignments) ArrayType(io.trino.spi.type.ArrayType) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) SortItem(io.trino.sql.tree.SortItem) ASC_NULLS_FIRST(io.trino.spi.connector.SortOrder.ASC_NULLS_FIRST) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) BIGINT(io.trino.spi.type.BigintType.BIGINT) MetadataManager.createTestMetadataManager(io.trino.metadata.MetadataManager.createTestMetadataManager) WindowFrame(io.trino.sql.tree.WindowFrame) Optional(java.util.Optional) RowType.field(io.trino.spi.type.RowType.field) WindowNode(io.trino.sql.planner.plan.WindowNode) PlanMatchPattern.rowNumber(io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) PlanMatchPattern.window(io.trino.sql.planner.assertions.PlanMatchPattern.window) Type(io.trino.spi.type.Type) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) ImmutableList(com.google.common.collect.ImmutableList) RowType.rowType(io.trino.spi.type.RowType.rowType) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.unnest(io.trino.sql.planner.assertions.PlanMatchPattern.unnest) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TupleDomain(io.trino.spi.predicate.TupleDomain) OrderingScheme(io.trino.sql.planner.OrderingScheme) UnnestNode(io.trino.sql.planner.plan.UnnestNode) SortOrder(io.trino.spi.connector.SortOrder) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) QualifiedName(io.trino.sql.tree.QualifiedName) TableHandle(io.trino.metadata.TableHandle) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) FrameBound(io.trino.sql.tree.FrameBound) UnnestMapping.unnestMapping(io.trino.sql.planner.assertions.PlanMatchPattern.UnnestMapping.unnestMapping) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RowType(io.trino.spi.type.RowType) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TableHandle(io.trino.metadata.TableHandle) CatalogName(io.trino.connector.CatalogName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 28 with TpchColumnHandle

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

the class TestPushPredicateIntoTableScan method nonDeterministicPredicate.

@Test
public void nonDeterministicPredicate() {
    Type orderStatusType = createVarcharType(1);
    tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(LogicalExpression.and(new ComparisonExpression(EQUAL, new SymbolReference("orderstatus"), new StringLiteral("O")), new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0"))), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", orderStatusType)), ImmutableMap.of(p.symbol("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))))).matches(filter(new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0")), constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus"))));
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Test(org.testng.annotations.Test) CatalogName(io.trino.connector.CatalogName) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) SchemaTableName(io.trino.spi.connector.SchemaTableName) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) BIGINT(io.trino.spi.type.BigintType.BIGINT) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) Optional(java.util.Optional) ConnectorTablePartitioning(io.trino.spi.connector.ConnectorTablePartitioning) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) Session(io.trino.Session) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) TupleDomain(io.trino.spi.predicate.TupleDomain) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) QualifiedName(io.trino.sql.tree.QualifiedName) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 29 with TpchColumnHandle

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

the class TestPushPredicateIntoTableScan method ruleAddedTableLayoutToFilterTableScan.

@Test
public void ruleAddedTableLayoutToFilterTableScan() {
    Map<String, Domain> filterConstraint = ImmutableMap.<String, Domain>builder().put("orderstatus", singleValue(createVarcharType(1), utf8Slice("F"))).buildOrThrow();
    tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(expression("orderstatus = 'F'"), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", createVarcharType(1))), ImmutableMap.of(p.symbol("orderstatus", createVarcharType(1)), new TpchColumnHandle("orderstatus", createVarcharType(1)))))).matches(constrainedTableScanWithTableLayout("orders", filterConstraint, ImmutableMap.of("orderstatus", "orderstatus")));
}
Also used : AND(io.trino.sql.tree.LogicalExpression.Operator.AND) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Test(org.testng.annotations.Test) CatalogName(io.trino.connector.CatalogName) MockConnectorFactory(io.trino.connector.MockConnectorFactory) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) BeforeClass(org.testng.annotations.BeforeClass) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) MODULUS(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.MODULUS) SchemaTableName(io.trino.spi.connector.SchemaTableName) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) BIGINT(io.trino.spi.type.BigintType.BIGINT) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) SymbolReference(io.trino.sql.tree.SymbolReference) Domain.singleValue(io.trino.spi.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) Optional(java.util.Optional) ConnectorTablePartitioning(io.trino.spi.connector.ConnectorTablePartitioning) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) Session(io.trino.Session) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) MockConnectorColumnHandle(io.trino.connector.MockConnectorColumnHandle) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) TupleDomain(io.trino.spi.predicate.TupleDomain) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) QualifiedName(io.trino.sql.tree.QualifiedName) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) LogicalExpression(io.trino.sql.tree.LogicalExpression) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 30 with TpchColumnHandle

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

the class TestPruneIndexSourceColumns method buildProjectedIndexSource.

private static PlanNode buildProjectedIndexSource(PlanBuilder p, Predicate<Symbol> projectionFilter) {
    Symbol orderkey = p.symbol("orderkey", INTEGER);
    Symbol custkey = p.symbol("custkey", INTEGER);
    Symbol totalprice = p.symbol("totalprice", DOUBLE);
    ColumnHandle orderkeyHandle = new TpchColumnHandle(orderkey.getName(), INTEGER);
    ColumnHandle custkeyHandle = new TpchColumnHandle(custkey.getName(), INTEGER);
    ColumnHandle totalpriceHandle = new TpchColumnHandle(totalprice.getName(), DOUBLE);
    return p.project(Assignments.identity(ImmutableList.of(orderkey, custkey, totalprice).stream().filter(projectionFilter).collect(toImmutableList())), p.indexSource(new TableHandle(new CatalogName("local"), new TpchTableHandle(TINY_SCHEMA_NAME, "orders", TINY_SCALE_FACTOR), TpchTransactionHandle.INSTANCE), ImmutableSet.of(orderkey, custkey), ImmutableList.of(orderkey, custkey, totalprice), ImmutableMap.of(orderkey, orderkeyHandle, custkey, custkeyHandle, totalprice, totalpriceHandle)));
}
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) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TableHandle(io.trino.metadata.TableHandle) CatalogName(io.trino.connector.CatalogName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle)

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