Search in sources :

Example 11 with TpchTableHandle

use of io.trino.plugin.tpch.TpchTableHandle 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 12 with TpchTableHandle

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

the class TestRemoveEmptyDeleteRuleSet method testDoesNotFire.

@Test(dataProvider = "rules")
public void testDoesNotFire(Rule<?> rule) {
    tester().assertThat(rule).on(p -> p.tableDelete(new SchemaTableName("sch", "tab"), p.tableScan(new TableHandle(CONNECTOR_ID, new TpchTableHandle("sf1", "nation", 1.0), TpchTransactionHandle.INSTANCE), ImmutableList.of(), ImmutableMap.of()), p.symbol("a", BigintType.BIGINT))).doesNotFire();
    tester().assertThat(rule).on(p -> p.tableWithExchangeDelete(new SchemaTableName("sch", "tab"), p.tableScan(new TableHandle(CONNECTOR_ID, new TpchTableHandle("sf1", "nation", 1.0), TpchTransactionHandle.INSTANCE), ImmutableList.of(), ImmutableMap.of()), p.symbol("a", BigintType.BIGINT))).doesNotFire();
}
Also used : DataProvider(org.testng.annotations.DataProvider) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) CONNECTOR_ID(io.trino.sql.planner.iterative.rule.test.RuleTester.CONNECTOR_ID) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) SchemaTableName(io.trino.spi.connector.SchemaTableName) RemoveEmptyDeleteRuleSet.removeEmptyDeleteWithExchangeRule(io.trino.sql.planner.iterative.rule.RemoveEmptyDeleteRuleSet.removeEmptyDeleteWithExchangeRule) TpchTransactionHandle(io.trino.plugin.tpch.TpchTransactionHandle) BigintType(io.trino.spi.type.BigintType) TableHandle(io.trino.metadata.TableHandle) DataProviders.toDataProvider(io.trino.testing.DataProviders.toDataProvider) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Rule(io.trino.sql.planner.iterative.Rule) RemoveEmptyDeleteRuleSet.remoteEmptyDeleteRule(io.trino.sql.planner.iterative.rule.RemoveEmptyDeleteRuleSet.remoteEmptyDeleteRule) TableHandle(io.trino.metadata.TableHandle) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 13 with TpchTableHandle

use of io.trino.plugin.tpch.TpchTableHandle 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)

Example 14 with TpchTableHandle

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

the class TpchIndexMetadata method resolveIndex.

@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle;
    // Keep the fixed values that don't overlap with the indexableColumns
    // Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()).entrySet().stream().filter(entry -> !indexableColumns.contains(entry.getKey())).filter(// strip nulls since meaningless in index join lookups
    entry -> !entry.getValue().isNull()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    // determine all columns available for index lookup
    Set<String> lookupColumnNames = ImmutableSet.<String>builder().addAll(handleToNames(ImmutableList.copyOf(indexableColumns))).addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build();
    // do we have an index?
    if (indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isEmpty()) {
        return Optional.empty();
    }
    TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain.filter((column, domain) -> !fixedValues.containsKey(column));
    TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
    return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Also used : ConnectorResolvedIndex(io.trino.spi.connector.ConnectorResolvedIndex) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) NullableValue(io.trino.spi.predicate.NullableValue) Set(java.util.Set) TpchIndexProvider.handleToNames(io.trino.testing.tpch.TpchIndexProvider.handleToNames) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) Collectors(java.util.stream.Collectors) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Optional(java.util.Optional) TpchMetadata(io.trino.plugin.tpch.TpchMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) ConnectorResolvedIndex(io.trino.spi.connector.ConnectorResolvedIndex) NullableValue(io.trino.spi.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle)

Aggregations

TpchTableHandle (io.trino.plugin.tpch.TpchTableHandle)14 TableHandle (io.trino.metadata.TableHandle)11 CatalogName (io.trino.connector.CatalogName)9 TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)7 BeforeClass (org.testng.annotations.BeforeClass)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableList (com.google.common.collect.ImmutableList)4 ColumnHandle (io.trino.spi.connector.ColumnHandle)4 TupleDomain (io.trino.spi.predicate.TupleDomain)3 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)3 Symbol (io.trino.sql.planner.Symbol)3 PlanMatchPattern (io.trino.sql.planner.assertions.PlanMatchPattern)3 PlanBuilder (io.trino.sql.planner.iterative.rule.test.PlanBuilder)3 Test (org.testng.annotations.Test)3 TEST_SESSION (io.trino.SessionTestUtils.TEST_SESSION)2 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)2 SchemaTableName (io.trino.spi.connector.SchemaTableName)2 SortOrder (io.trino.spi.connector.SortOrder)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 RowType (io.trino.spi.type.RowType)2