use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method doesNotConsumeRemainingPredicateIfNewDomainIsWider.
@Test
public void doesNotConsumeRemainingPredicateIfNewDomainIsWider() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(new LogicalExpression(AND, ImmutableList.of(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44")), LogicalExpression.or(new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "44")), new ComparisonExpression(EQUAL, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "45"))))), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.fromFixedValues(ImmutableMap.of(columnHandle, NullableValue.of(BIGINT, (long) 44)))))).matches(filter(LogicalExpression.and(new ComparisonExpression(EQUAL, FunctionCallBuilder.resolve(tester().getSession(), tester().getMetadata()).setName(QualifiedName.of("rand")).build(), new GenericLiteral("BIGINT", "42")), new ComparisonExpression(EQUAL, new ArithmeticBinaryExpression(MODULUS, new SymbolReference("nationkey"), new GenericLiteral("BIGINT", "17")), new GenericLiteral("BIGINT", "44"))), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", singleValue(BIGINT, (long) 44)), ImmutableMap.of("nationkey", "nationkey"))));
}
use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestRemoveRedundantPredicateAboveTableScan method consumesDeterministicPredicateIfNewDomainIsNarrower.
@Test
public void consumesDeterministicPredicateIfNewDomainIsNarrower() {
ColumnHandle columnHandle = new TpchColumnHandle("nationkey", BIGINT);
tester().assertThat(removeRedundantPredicateAboveTableScan).on(p -> p.filter(expression("nationkey = BIGINT '44' OR nationkey = BIGINT '45' OR nationkey = BIGINT '47'"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), columnHandle), TupleDomain.withColumnDomains(ImmutableMap.of(columnHandle, Domain.multipleValues(BIGINT, ImmutableList.of(44L, 45L, 46L))))))).matches(filter(expression("nationkey IN (BIGINT '44', BIGINT '45')"), constrainedTableScanWithTableLayout("nation", ImmutableMap.of("nationkey", Domain.multipleValues(BIGINT, ImmutableList.of(44L, 45L, 46L))), ImmutableMap.of("nationkey", "nationkey"))));
}
use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestRemoveUnsupportedDynamicFilters method testRemoveUnsupportedCast.
@Test
public void testRemoveUnsupportedCast() {
// Use lineitem with DOUBLE orderkey to simulate the case of implicit casts
// Dynamic filter is removed because there isn't an injective mapping from bigint -> double
Symbol lineitemDoubleOrderKeySymbol = builder.symbol("LINEITEM_DOUBLE_OK", DOUBLE);
PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("CAST(LINEITEM_DOUBLE_OK AS BIGINT)")), builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableMap.of(lineitemDoubleOrderKeySymbol, new TpchColumnHandle("orderkey", DOUBLE)))), ordersTableScanNode, ImmutableList.of(new JoinNode.EquiJoinClause(lineitemDoubleOrderKeySymbol, ordersOrderKeySymbol)), ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableList.of(ordersOrderKeySymbol), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(new DynamicFilterId("DF"), ordersOrderKeySymbol)));
assertPlan(removeUnsupportedDynamicFilters(root), output(join(INNER, ImmutableList.of(equiJoinClause("LINEITEM_DOUBLE_OK", "ORDERS_OK")), ImmutableMap.of(), tableScan("lineitem", ImmutableMap.of("LINEITEM_DOUBLE_OK", "orderkey")), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")))));
}
use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestValidateStreamingAggregations method testValidateSuccessful.
@Test
public void testValidateSuccessful() {
validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("nationkey")).source(p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))));
validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.symbol("unique"), p.symbol("nationkey")).preGroupedSymbols(p.symbol("unique"), p.symbol("nationkey")).source(p.assignUniqueId(p.symbol("unique"), p.tableScan(nationTableHandle, ImmutableList.of(p.symbol("nationkey", BIGINT)), ImmutableMap.of(p.symbol("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))))));
}
use of io.trino.plugin.tpch.TpchColumnHandle 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