use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestPushProjectionIntoTableScan method testPartitioningChanged.
@Test
public void testPartitioningChanged() {
try (RuleTester ruleTester = defaultRuleTester()) {
String columnName = "col0";
ColumnHandle columnHandle = new TpchColumnHandle(columnName, VARCHAR);
// Create catalog with applyProjection enabled
MockConnectorFactory factory = createMockFactory(ImmutableMap.of(columnName, columnHandle), Optional.of(this::mockApplyProjection));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, factory, ImmutableMap.of());
assertThatThrownBy(() -> ruleTester.assertThat(createRule(ruleTester)).on(p -> p.project(Assignments.of(), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(p.symbol("col", VARCHAR)), ImmutableMap.of(p.symbol("col", VARCHAR), columnHandle), Optional.of(true)))).withSession(MOCK_SESSION).matches(anyTree())).hasMessage("Partitioning must not change after projection is pushed down");
}
}
use of io.trino.plugin.tpch.TpchColumnHandle 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))))));
}
use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestPushPredicateIntoTableScan method nonDeterministicPredicate.
@Test
public void nonDeterministicPredicate() {
Type orderStatusType = createVarcharType(1);
tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(LogicalExpression.and(new ComparisonExpression(EQUAL, new SymbolReference("orderstatus"), new StringLiteral("O")), new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0"))), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", orderStatusType)), ImmutableMap.of(p.symbol("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))))).matches(filter(new ComparisonExpression(EQUAL, functionResolution.functionCallBuilder(QualifiedName.of("rand")).build(), new LongLiteral("0")), constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus"))));
}
use of io.trino.plugin.tpch.TpchColumnHandle in project trino by trinodb.
the class TestPushPredicateIntoTableScan method ruleAddedTableLayoutToFilterTableScan.
@Test
public void ruleAddedTableLayoutToFilterTableScan() {
Map<String, Domain> filterConstraint = ImmutableMap.<String, Domain>builder().put("orderstatus", singleValue(createVarcharType(1), utf8Slice("F"))).buildOrThrow();
tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(expression("orderstatus = 'F'"), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", createVarcharType(1))), ImmutableMap.of(p.symbol("orderstatus", createVarcharType(1)), new TpchColumnHandle("orderstatus", createVarcharType(1)))))).matches(constrainedTableScanWithTableLayout("orders", filterConstraint, ImmutableMap.of("orderstatus", "orderstatus")));
}
use of io.trino.plugin.tpch.TpchColumnHandle 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)));
}
Aggregations