Search in sources :

Example 1 with TpchTableHandle

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

the class TestLogicalPlanner method testLikePredicate.

@Test
public void testLikePredicate() {
    assertPlan("SELECT type FROM part WHERE type LIKE 'LARGE PLATED %'", anyTree(tableScan(tableHandle -> {
        Map<ColumnHandle, Domain> domains = ((TpchTableHandle) tableHandle).getConstraint().getDomains().orElseThrow(() -> new AssertionError("Unexpected none TupleDomain"));
        Domain domain = domains.entrySet().stream().filter(entry -> ((TpchColumnHandle) entry.getKey()).getColumnName().equals("type")).map(Entry::getValue).collect(toOptional()).orElseThrow(() -> new AssertionError("No domain for 'type'"));
        assertEquals(domain, Domain.multipleValues(createVarcharType(25), ImmutableList.of("LARGE PLATED BRASS", "LARGE PLATED COPPER", "LARGE PLATED NICKEL", "LARGE PLATED STEEL", "LARGE PLATED TIN").stream().map(Slices::utf8Slice).collect(toImmutableList())));
        return true;
    }, TupleDomain.withColumnDomains(ImmutableMap.of(tableHandle -> ((TpchColumnHandle) tableHandle).getColumnName().equals("type"), Domain.create(ValueSet.ofRanges(Range.range(createVarcharType(25), utf8Slice("LARGE PLATED "), true, utf8Slice("LARGE PLATED!"), false)), false))), ImmutableMap.of())));
}
Also used : CREATED(io.trino.sql.planner.LogicalPlanner.Stage.CREATED) PlanMatchPattern.aggregation(io.trino.sql.planner.assertions.PlanMatchPattern.aggregation) ROW_NUMBER(io.trino.sql.planner.plan.TopNRankingNode.RankingType.ROW_NUMBER) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) CorrelatedJoinNode(io.trino.sql.planner.plan.CorrelatedJoinNode) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanMatchPattern.assignUniqueId(io.trino.sql.planner.assertions.PlanMatchPattern.assignUniqueId) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) PlanMatchPattern.markDistinct(io.trino.sql.planner.assertions.PlanMatchPattern.markDistinct) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) AddLocalExchanges(io.trino.sql.planner.optimizations.AddLocalExchanges) LongLiteral(io.trino.sql.tree.LongLiteral) Slices(io.airlift.slice.Slices) Map(java.util.Map) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Assert.assertFalse(org.testng.Assert.assertFalse) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) Range(io.trino.spi.predicate.Range) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) Domain(io.trino.spi.predicate.Domain) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanMatchPattern.aliasToIndex(io.trino.sql.planner.assertions.PlanMatchPattern.aliasToIndex) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) QueryTemplate.queryTemplate(io.trino.tests.QueryTemplate.queryTemplate) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) ValueSet(io.trino.spi.predicate.ValueSet) PlanMatchPattern.strictConstrainedTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictConstrainedTableScan) PlanMatchPattern.apply(io.trino.sql.planner.assertions.PlanMatchPattern.apply) ValuesNode(io.trino.sql.planner.plan.ValuesNode) TASK_CONCURRENCY(io.trino.SystemSessionProperties.TASK_CONCURRENCY) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) REAL(io.trino.spi.type.RealType.REAL) Session(io.trino.Session) OPTIMIZE_HASH_GENERATION(io.trino.SystemSessionProperties.OPTIMIZE_HASH_GENERATION) PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) PARTITIONED(io.trino.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) LimitNode(io.trino.sql.planner.plan.LimitNode) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.patternRecognition(io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition) REPLICATE(io.trino.sql.planner.plan.ExchangeNode.Type.REPLICATE) DISTRIBUTED_SORT(io.trino.SystemSessionProperties.DISTRIBUTED_SORT) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) ColumnHandle(io.trino.spi.connector.ColumnHandle) AggregationNode(io.trino.sql.planner.plan.AggregationNode) JOIN_REORDERING_STRATEGY(io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) StringLiteral(io.trino.sql.tree.StringLiteral) MorePredicates(io.trino.util.MorePredicates) QueryTemplate(io.trino.tests.QueryTemplate) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) RANK(io.trino.sql.planner.plan.TopNRankingNode.RankingType.RANK) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) SortOrder(io.trino.spi.connector.SortOrder) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.windowFrame(io.trino.sql.planner.assertions.PlanMatchPattern.windowFrame) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) MorePredicates.isInstanceOfAny(io.trino.util.MorePredicates.isInstanceOfAny) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) Domain.multipleValues(io.trino.spi.predicate.Domain.multipleValues) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) SUBQUERY_MULTIPLE_ROWS(io.trino.spi.StandardErrorCode.SUBQUERY_MULTIPLE_ROWS) PlanMatchPattern.strictTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.strictTableScan) PlanMatchPattern.any(io.trino.sql.planner.assertions.PlanMatchPattern.any) CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) PlanMatchPattern.constrainedTableScan(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScan) REPLICATED(io.trino.sql.planner.plan.JoinNode.DistributionType.REPLICATED) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) WINDOW(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.WINDOW) JoinNode(io.trino.sql.planner.plan.JoinNode) INTEGER(io.trino.spi.type.IntegerType.INTEGER) FunctionCall(io.trino.sql.tree.FunctionCall) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ExpressionMatcher(io.trino.sql.planner.assertions.ExpressionMatcher) RowNumberSymbolMatcher(io.trino.sql.planner.assertions.RowNumberSymbolMatcher) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RowType(io.trino.spi.type.RowType) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) EnforceSingleRowNode(io.trino.sql.planner.plan.EnforceSingleRowNode) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode) FORCE_SINGLE_NODE_OUTPUT(io.trino.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) String.format(java.lang.String.format) IrQuantifier.oneOrMore(io.trino.sql.planner.rowpattern.ir.IrQuantifier.oneOrMore) GenericLiteral(io.trino.sql.tree.GenericLiteral) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) List(java.util.List) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.constrainedTableScanWithTableLayout(io.trino.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) FILTERING_SEMI_JOIN_TO_INNER(io.trino.SystemSessionProperties.FILTERING_SEMI_JOIN_TO_INNER) Entry(java.util.Map.Entry) ApplyNode(io.trino.sql.planner.plan.ApplyNode) Optional(java.util.Optional) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) PlanMatchPattern.rowNumber(io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber) UNBOUNDED_FOLLOWING(io.trino.sql.tree.FrameBound.Type.UNBOUNDED_FOLLOWING) PlanMatchPattern.anyNot(io.trino.sql.planner.assertions.PlanMatchPattern.anyNot) DESCENDING(io.trino.sql.tree.SortItem.Ordering.DESCENDING) PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Assert.assertEquals(org.testng.Assert.assertEquals) IrQuantified(io.trino.sql.planner.rowpattern.ir.IrQuantified) OPTIMIZED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED) SortNode(io.trino.sql.planner.plan.SortNode) PlanMatchPattern.specification(io.trino.sql.planner.assertions.PlanMatchPattern.specification) Cast(io.trino.sql.tree.Cast) ImmutableList(com.google.common.collect.ImmutableList) JoinReorderingStrategy(io.trino.sql.planner.OptimizerConfig.JoinReorderingStrategy) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) DynamicFilterPattern(io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern) ProjectNode(io.trino.sql.planner.plan.ProjectNode) LAST(io.trino.sql.tree.SortItem.NullOrdering.LAST) PARTIAL(io.trino.sql.planner.plan.AggregationNode.Step.PARTIAL) PlanMatchPattern.identityProject(io.trino.sql.planner.assertions.PlanMatchPattern.identityProject) TopNNode(io.trino.sql.planner.plan.TopNNode) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) TupleDomain(io.trino.spi.predicate.TupleDomain) PlanMatchPattern.singleGroupingSet(io.trino.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) QualifiedName(io.trino.sql.tree.QualifiedName) Consumer(java.util.function.Consumer) DistributionType(io.trino.sql.planner.plan.SemiJoinNode.DistributionType) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) CheckSubqueryNodesAreRewritten(io.trino.sql.planner.optimizations.CheckSubqueryNodesAreRewritten) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) DistinctLimitNode(io.trino.sql.planner.plan.DistinctLimitNode) Row(io.trino.sql.tree.Row) FINAL(io.trino.sql.planner.plan.AggregationNode.Step.FINAL) ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Entry(java.util.Map.Entry) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 2 with TpchTableHandle

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

the class H2QueryRunner method insertRows.

private void insertRows(TpchMetadata tpchMetadata, TpchTable<?> tpchTable) {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(null, new SchemaTableName(TINY_SCHEMA_NAME, tpchTable.getTableName()));
    insertRows(tpchMetadata.getTableMetadata(null, tableHandle), handle, createTpchRecordSet(tpchTable, tableHandle.getScaleFactor()));
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle)

Example 3 with TpchTableHandle

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

the class TestRemoveUnsupportedDynamicFilters method setup.

@BeforeClass
public void setup() {
    plannerContext = getQueryRunner().getPlannerContext();
    metadata = plannerContext.getMetadata();
    builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata, TEST_SESSION);
    CatalogName catalogName = getCurrentConnectorId();
    lineitemTableHandle = new TableHandle(catalogName, new TpchTableHandle("sf1", "lineitem", 1.0), TestingTransactionHandle.create());
    lineitemOrderKeySymbol = builder.symbol("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeySymbol), ImmutableMap.of(lineitemOrderKeySymbol, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(catalogName, new TpchTableHandle("sf1", "orders", 1.0), TestingTransactionHandle.create());
    ordersOrderKeySymbol = builder.symbol("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeySymbol), ImmutableMap.of(ordersOrderKeySymbol, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) CatalogName(io.trino.connector.CatalogName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TableHandle(io.trino.metadata.TableHandle) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with TpchTableHandle

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

the class TestRuleTester method testReportNoFireWithTableScan.

@Test
public void testReportNoFireWithTableScan() {
    try (RuleTester tester = defaultRuleTester()) {
        RuleAssert ruleAssert = tester.assertThat(rule("testReportNoFireWithTableScan rule", Pattern.typeOf(PlanNode.class), (node, captures, context) -> Result.empty())).on(p -> p.tableScan(new TableHandle(tester.getCurrentConnectorId(), new TpchTableHandle("sf1", "nation", 1.0), TestingTransactionHandle.create()), List.of(p.symbol("x")), Map.of(p.symbol("x"), new TestingColumnHandle("column"))));
        PlanMatchPattern expected = values(List.of("whatever"), List.of());
        assertThatThrownBy(() -> ruleAssert.matches(expected)).isInstanceOf(AssertionError.class).hasMessageMatching("testReportNoFireWithTableScan rule did not fire for:\n" + "(?s:.*)" + "\\QEstimates: {rows: 25 (225B), cpu: 225, memory: 0B, network: 0B}\\E\n" + "(?s:.*)");
    }
}
Also used : TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) PlanNode(io.trino.sql.planner.plan.PlanNode) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) TableHandle(io.trino.metadata.TableHandle) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Test(org.testng.annotations.Test)

Example 5 with TpchTableHandle

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

the class TestRemoveRedundantPredicateAboveTableScan method setUpBeforeClass.

@BeforeClass
public void setUpBeforeClass() {
    removeRedundantPredicateAboveTableScan = new RemoveRedundantPredicateAboveTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer());
    CatalogName catalogName = tester().getCurrentConnectorId();
    TpchTableHandle nation = new TpchTableHandle("sf1", "nation", 1.0);
    nationTableHandle = new TableHandle(catalogName, nation, TpchTransactionHandle.INSTANCE);
    TpchTableHandle orders = new TpchTableHandle("sf1", "orders", 1.0);
    ordersTableHandle = new TableHandle(catalogName, orders, TpchTransactionHandle.INSTANCE);
}
Also used : CatalogName(io.trino.connector.CatalogName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TableHandle(io.trino.metadata.TableHandle) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

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