Search in sources :

Example 16 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestMetastoreUtil method testComputePartitionKeyFilter.

@Test
public void testComputePartitionKeyFilter() {
    HiveColumnHandle dsColumn = partitionColumn("ds");
    HiveColumnHandle typeColumn = partitionColumn("type");
    List<HiveColumnHandle> partitionKeys = ImmutableList.of(dsColumn, typeColumn);
    Domain dsDomain = Domain.create(ValueSet.ofRanges(Range.lessThan(VARCHAR, utf8Slice("2018-05-06"))), false);
    Domain typeDomain = Domain.create(ValueSet.of(VARCHAR, utf8Slice("fruit")), false);
    TupleDomain<HiveColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<HiveColumnHandle, Domain>builder().put(bucketColumnHandle(), Domain.create(ValueSet.of(INTEGER, 123L), false)).put(dsColumn, dsDomain).put(typeColumn, typeDomain).buildOrThrow());
    TupleDomain<String> filter = computePartitionKeyFilter(partitionKeys, tupleDomain);
    assertThat(filter.getDomains()).as("output contains only the partition keys").contains(ImmutableMap.<String, Domain>builder().put("ds", dsDomain).put("type", typeDomain).buildOrThrow());
}
Also used : Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) Test(org.testng.annotations.Test)

Example 17 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues.

@Test
public void testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues() {
    int maxDistinctValues = 100;
    Page largePage = new Page(createLongSequenceBlock(0, 101), createColorRepeatBlock(100, 101), createLongRepeatBlock(200, 101));
    List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.ofRanges(range(BIGINT, 0L, true, 100L, true)), false), new DynamicFilterId("2"), Domain.create(ValueSet.ofRanges(equal(BIGINT, 200L)), false))));
    assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT, COLOR, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Page(io.trino.spi.Page) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Example 18 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectBelowDistinctValuesLimit.

@Test
public void testMultipleColumnsCollectBelowDistinctValuesLimit() {
    int maxDistinctValues = 101;
    Page largePage = new Page(createLongSequenceBlock(0, 101), createLongSequenceBlock(100, 201), createLongSequenceBlock(200, 301));
    List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(0L, 100L).boxed().collect(toImmutableList())), false), new DynamicFilterId("1"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(100L, 200L).boxed().collect(toImmutableList())), false), new DynamicFilterId("2"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(200L, 300L).boxed().collect(toImmutableList())), false))));
    assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT, BIGINT, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Page(io.trino.spi.Page) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Example 19 with TupleDomain

use of io.trino.spi.predicate.TupleDomain 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 20 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestLocalDynamicFilterConsumer method testMultiplePartitionsAndColumns.

@Test
public void testMultiplePartitionsAndColumns() throws Exception {
    LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer(ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1), ImmutableMap.of(new DynamicFilterId("123"), INTEGER, new DynamicFilterId("456"), BIGINT), 2);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1));
    Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<Map<DynamicFilterId, Domain>> result = filter.getDynamicFilterDomains();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 10L), new DynamicFilterId("456"), Domain.singleValue(BIGINT, 100L))));
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 20L), new DynamicFilterId("456"), Domain.singleValue(BIGINT, 200L))));
    assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.multipleValues(INTEGER, ImmutableList.of(10L, 20L)), new DynamicFilterId("456"), Domain.multipleValues(BIGINT, ImmutableList.of(100L, 200L))));
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

TupleDomain (io.trino.spi.predicate.TupleDomain)97 Domain (io.trino.spi.predicate.Domain)77 Map (java.util.Map)50 ColumnHandle (io.trino.spi.connector.ColumnHandle)48 ImmutableMap (com.google.common.collect.ImmutableMap)43 ImmutableList (com.google.common.collect.ImmutableList)41 List (java.util.List)40 Optional (java.util.Optional)36 Set (java.util.Set)33 Test (org.testng.annotations.Test)33 Objects.requireNonNull (java.util.Objects.requireNonNull)32 ConnectorSession (io.trino.spi.connector.ConnectorSession)29 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)28 ImmutableSet (com.google.common.collect.ImmutableSet)26 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)23 Range (io.trino.spi.predicate.Range)22 String.format (java.lang.String.format)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)20 TrinoException (io.trino.spi.TrinoException)20 Type (io.trino.spi.type.Type)19