use of io.trino.plugin.tpch.TpchTableHandle 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.TpchTableHandle in project trino by trinodb.
the class TestRemoveEmptyDeleteRuleSet method testDoesNotFire.
@Test(dataProvider = "rules")
public void testDoesNotFire(Rule<?> rule) {
tester().assertThat(rule).on(p -> p.tableDelete(new SchemaTableName("sch", "tab"), p.tableScan(new TableHandle(CONNECTOR_ID, new TpchTableHandle("sf1", "nation", 1.0), TpchTransactionHandle.INSTANCE), ImmutableList.of(), ImmutableMap.of()), p.symbol("a", BigintType.BIGINT))).doesNotFire();
tester().assertThat(rule).on(p -> p.tableWithExchangeDelete(new SchemaTableName("sch", "tab"), p.tableScan(new TableHandle(CONNECTOR_ID, new TpchTableHandle("sf1", "nation", 1.0), TpchTransactionHandle.INSTANCE), ImmutableList.of(), ImmutableMap.of()), p.symbol("a", BigintType.BIGINT))).doesNotFire();
}
use of io.trino.plugin.tpch.TpchTableHandle 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)));
}
use of io.trino.plugin.tpch.TpchTableHandle in project trino by trinodb.
the class TpchIndexMetadata method resolveIndex.
@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle;
// Keep the fixed values that don't overlap with the indexableColumns
// Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now
Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()).entrySet().stream().filter(entry -> !indexableColumns.contains(entry.getKey())).filter(// strip nulls since meaningless in index join lookups
entry -> !entry.getValue().isNull()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// determine all columns available for index lookup
Set<String> lookupColumnNames = ImmutableSet.<String>builder().addAll(handleToNames(ImmutableList.copyOf(indexableColumns))).addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build();
// do we have an index?
if (indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isEmpty()) {
return Optional.empty();
}
TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain.filter((column, domain) -> !fixedValues.containsKey(column));
TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Aggregations