use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestDynamicFiltersChecker method testUnmatchedDynamicFilterInSemiJoin.
@Test
public void testUnmatchedDynamicFilterInSemiJoin() {
PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.semiJoin(builder.filter(combineConjuncts(metadata, expression("ORDERS_OK > 0"), createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, ordersOrderKeySymbol.toSymbolReference())), ordersTableScanNode), lineitemTableScanNode, ordersOrderKeySymbol, lineitemOrderKeySymbol, new Symbol("SEMIJOIN_OUTPUT"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessage("All consumed dynamic filters could not be matched with a join/semi-join.");
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestDynamicFiltersChecker method testUnmatchedDynamicFilter.
@Test
public void testUnmatchedDynamicFilter() {
PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, ordersTableScanNode, builder.filter(combineConjuncts(metadata, expression("LINEITEM_OK > 0"), createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, lineitemOrderKeySymbol.toSymbolReference())), lineitemTableScanNode), ImmutableList.of(new JoinNode.EquiJoinClause(ordersOrderKeySymbol, lineitemOrderKeySymbol)), ImmutableList.of(ordersOrderKeySymbol), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessageMatching("All consumed dynamic filters could not be matched with a join/semi-join.");
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestDynamicFiltersChecker method testUnsupportedCastExpression.
@Test
public void testUnsupportedCastExpression() {
PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("CAST(CAST(LINEITEM_OK AS INT) AS BIGINT)")), lineitemTableScanNode), ordersTableScanNode, ImmutableList.of(new JoinNode.EquiJoinClause(lineitemOrderKeySymbol, ordersOrderKeySymbol)), ImmutableList.of(lineitemOrderKeySymbol), ImmutableList.of(ordersOrderKeySymbol), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(new DynamicFilterId("DF"), ordersOrderKeySymbol)));
assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessageMatching("The expression CAST\\(\"LINEITEM_OK\" AS INT\\) within in a CAST in dynamic filter must be a SymbolReference.");
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestDynamicFiltersCollector method testDynamicFiltersCollector.
@Test
public void testDynamicFiltersCollector() {
DynamicFilterId filter = new DynamicFilterId("filter");
DynamicFiltersCollector collector = new DynamicFiltersCollector(() -> {
});
VersionedDynamicFilterDomains domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
// there should be no domains initially
assertEquals(domains.getVersion(), INITIAL_DYNAMIC_FILTERS_VERSION);
assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of());
Domain initialDomain = multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L));
collector.updateDomains(ImmutableMap.of(filter, initialDomain));
domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
assertEquals(domains.getVersion(), 1L);
assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, initialDomain));
// make sure domains are still available when requested again with old version
domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
assertEquals(domains.getVersion(), 1L);
assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, initialDomain));
// make sure domains are intersected
collector.updateDomains(ImmutableMap.of(filter, multipleValues(BIGINT, ImmutableList.of(2L))));
collector.updateDomains(ImmutableMap.of(filter, multipleValues(BIGINT, ImmutableList.of(3L, 4L))));
domains = collector.acknowledgeAndGetNewDomains(1L);
assertEquals(domains.getVersion(), 3L);
assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, Domain.none(BIGINT)));
// make sure old domains are removed
DynamicFilterId filter2 = new DynamicFilterId("filter2");
collector.updateDomains(ImmutableMap.of(filter2, singleValue(BIGINT, 1L)));
domains = collector.acknowledgeAndGetNewDomains(3L);
assertEquals(domains.getVersion(), 4L);
assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter2, singleValue(BIGINT, 1L)));
}
use of io.trino.sql.planner.plan.DynamicFilterId 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")))));
}
Aggregations