Refine search
List<LocalProperty<ColumnHandle>> localProperties = ImmutableList.of(); if (tableHandle.getTableName().equals(TpchTable.ORDERS.getTableName())) { if (partitioningEnabled) { ColumnHandle orderKeyColumn = columns.get(columnNaming.getName(OrderColumn.ORDER_KEY)); tablePartitioning = Optional.of(new ConnectorTablePartitioning( new TpchPartitioningHandle( TpchTable.ORDERS.getTableName(), calculateTotalRows(OrderGenerator.SCALE_BASE, tableHandle.getScaleFactor())), ImmutableList.of(orderKeyColumn))); partitioningColumns = Optional.of(ImmutableSet.of(orderKeyColumn)); localProperties = ImmutableList.of(new SortingProperty<>(orderKeyColumn, SortOrder.ASC_NULLS_FIRST)); else if (predicatePushdownEnabled && tableHandle.getTableName().equals(TpchTable.PART.getTableName())) { predicate = toTupleDomain(ImmutableMap.of( toColumnHandle(PartColumn.CONTAINER), filterValues(PART_CONTAINER_NULLABLE_VALUES, PartColumn.CONTAINER, constraint), else if (tableHandle.getTableName().equals(TpchTable.LINE_ITEM.getTableName())) { if (partitioningEnabled) { ColumnHandle orderKeyColumn = columns.get(columnNaming.getName(LineItemColumn.ORDER_KEY)); new TpchPartitioningHandle( TpchTable.ORDERS.getTableName(), calculateTotalRows(OrderGenerator.SCALE_BASE, tableHandle.getScaleFactor())), ImmutableList.of(orderKeyColumn))); partitioningColumns = Optional.of(ImmutableSet.of(orderKeyColumn));
@Override public TpchTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { requireNonNull(tableName, "tableName is null"); if (!tableNames.contains(tableName.getTableName())) { return null; } // parse the scale factor double scaleFactor = schemaNameToScaleFactor(tableName.getSchemaName()); if (scaleFactor < 0) { return null; } return new TpchTableHandle(tableName.getTableName(), scaleFactor); }
@Override public String toString() { return table.toString(); } }
@Override public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) { TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle; TpchTable<?> tpchTable = TpchTable.getTable(tpchTableHandle.getTableName()); String schemaName = scaleFactorSchemaName(tpchTableHandle.getScaleFactor()); return getTableMetadata(schemaName, tpchTable, columnNaming); }
@Override public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTableHandle tableHandle, Constraint<ColumnHandle> constraint) { TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle; String tableName = tpchTableHandle.getTableName(); TpchTable<?> tpchTable = TpchTable.getTable(tableName); Map<TpchColumn<?>, List<Object>> columnValuesRestrictions = ImmutableMap.of(); if (predicatePushdownEnabled) { columnValuesRestrictions = getColumnValuesRestrictions(tpchTable, constraint); } Optional<TableStatisticsData> optionalTableStatisticsData = statisticsEstimator.estimateStats(tpchTable, columnValuesRestrictions, tpchTableHandle.getScaleFactor()); Map<String, ColumnHandle> columnHandles = getColumnHandles(session, tpchTableHandle); return optionalTableStatisticsData .map(tableStatisticsData -> toTableStatistics(optionalTableStatisticsData.get(), tpchTableHandle, columnHandles)) .orElse(TableStatistics.empty()); }
Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()) .entrySet().stream() .filter(entry -> !indexableColumns.contains(entry.getKey())) .addAll(handleToNames(ImmutableList.copyOf(indexableColumns))) .addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))) .build(); if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) { return Optional.empty(); tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
@Test public void testDoesNotFire() { tester().assertThat(new RemoveEmptyDelete()) .on(p -> p.tableDelete( new SchemaTableName("sch", "tab"), p.tableScan( new TableHandle(CONNECTOR_ID, new TpchTableHandle("nation", 1.0)), ImmutableList.of(), ImmutableMap.of()), p.symbol("a", BigintType.BIGINT))) .doesNotFire(); }
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 ConnectorId("local"), new TpchTableHandle("orders", TINY_SCALE_FACTOR)), ImmutableSet.of(orderkey, custkey), ImmutableList.of(orderkey, custkey, totalprice), ImmutableMap.of( orderkey, orderkeyHandle, custkey, custkeyHandle, totalprice, totalpriceHandle), TupleDomain.fromFixedValues(ImmutableMap.of(totalpriceHandle, asNull(DOUBLE))))); } }
private TableScanNode tableScan(String id, String... symbols) { List<Symbol> symbolsList = Arrays.stream(symbols).map(Symbol::new).collect(toImmutableList()); ImmutableMap.Builder<Symbol, ColumnHandle> assignments = ImmutableMap.builder(); for (Symbol symbol : symbolsList) { assignments.put(symbol, new TpchColumnHandle("orderkey", BIGINT)); } TpchTableHandle tableHandle = new TpchTableHandle("orders", 1.0); return new TableScanNode( new PlanNodeId(id), new TableHandle(new ConnectorId("tpch"), new TpchTableHandle("orders", 1.0)), symbolsList, assignments.build(), Optional.of(new TableLayoutHandle(new ConnectorId("tpch"), INSTANCE, new TpchTableLayoutHandle(tableHandle, TupleDomain.all()))), TupleDomain.all(), TupleDomain.all()); }
private void insertRows(TpchMetadata tpchMetadata, TpchTable tpchTable) { TpchTableHandle tableHandle = tpchMetadata.getTableHandle(null, new SchemaTableName(TINY_SCHEMA_NAME, tpchTable.getTableName())); insertRows(tpchMetadata.getTableMetadata(null, tableHandle), handle, createTpchRecordSet(tpchTable, tableHandle.getScaleFactor())); }
private ColumnHandle getColumnHandle(TpchTableHandle tpchTableHandle, Map<String, ColumnHandle> columnHandles, String columnName) { TpchTable<?> table = TpchTable.getTable(tpchTableHandle.getTableName()); return columnHandles.get(columnNaming.getName(table.getColumn(columnName))); }
@Override public Void visitTableScan(TableScanNode node, Integer indent) { ConnectorTableHandle connectorTableHandle = node.getTable().getConnectorHandle(); if (connectorTableHandle instanceof TpcdsTableHandle) { output(indent, "scan %s", ((TpcdsTableHandle) connectorTableHandle).getTableName()); } else if (connectorTableHandle instanceof TpchTableHandle) { output(indent, "scan %s", ((TpchTableHandle) connectorTableHandle).getTableName()); } else { throw new IllegalStateException(format("Unexpected ConnectorTableHandle: %s", connectorTableHandle.getClass())); } return null; }
public String getConnectorId() { return table.getConnectorId(); }
@BeforeClass public void setup() { metadata = getQueryRunner().getMetadata(); builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata); ConnectorId connectorId = getCurrentConnectorId(); TableHandle nationTableHandle = new TableHandle( connectorId, new TpchTableHandle("nation", 1.0)); TableLayoutHandle nationTableLayoutHandle = new TableLayoutHandle(connectorId, TestingTransactionHandle.create(), new TpchTableLayoutHandle((TpchTableHandle) nationTableHandle.getConnectorHandle(), TupleDomain.all())); TpchColumnHandle nationkeyColumnHandle = new TpchColumnHandle("nationkey", BIGINT); symbol = new Symbol("nationkey"); tableScanNode = builder.tableScan(nationTableHandle, ImmutableList.of(symbol), ImmutableMap.of(symbol, nationkeyColumnHandle), Optional.of(nationTableLayoutHandle)); }
Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()) .entrySet().stream() .filter(entry -> !indexableColumns.contains(entry.getKey())) .addAll(handleToNames(ImmutableList.copyOf(indexableColumns))) .addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))) .build(); if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) { return Optional.empty(); tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
@Override public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTableHandle tableHandle, Constraint<ColumnHandle> constraint) { TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle; String tableName = tpchTableHandle.getTableName(); TpchTable<?> tpchTable = TpchTable.getTable(tableName); Map<TpchColumn<?>, List<Object>> columnValuesRestrictions = ImmutableMap.of(); if (predicatePushdownEnabled) { columnValuesRestrictions = getColumnValuesRestrictions(tpchTable, constraint); } Optional<TableStatisticsData> optionalTableStatisticsData = statisticsEstimator.estimateStats(tpchTable, columnValuesRestrictions, tpchTableHandle.getScaleFactor()); Map<String, ColumnHandle> columnHandles = getColumnHandles(session, tpchTableHandle); return optionalTableStatisticsData .map(tableStatisticsData -> toTableStatistics(optionalTableStatisticsData.get(), tpchTableHandle, columnHandles)) .orElse(TableStatistics.empty()); }
private void insertRows(TpchMetadata tpchMetadata, TpchTable tpchTable) { TpchTableHandle tableHandle = tpchMetadata.getTableHandle(null, new SchemaTableName(TINY_SCHEMA_NAME, tpchTable.getTableName())); insertRows(tpchMetadata.getTableMetadata(null, tableHandle), handle, createTpchRecordSet(tpchTable, tableHandle.getScaleFactor())); }
@Override public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) { TpchSplit tpchSplit = (TpchSplit) split; String tableName = tpchSplit.getTableHandle().getTableName(); TpchTable<?> tpchTable = TpchTable.getTable(tableName); return getRecordSet(tpchTable, columns, tpchSplit.getTableHandle().getScaleFactor(), tpchSplit.getPartNumber(), tpchSplit.getTotalParts(), tpchSplit.getPredicate()); }
private ColumnHandle getColumnHandle(TpchTableHandle tpchTableHandle, Map<String, ColumnHandle> columnHandles, String columnName) { TpchTable<?> table = TpchTable.getTable(tpchTableHandle.getTableName()); return columnHandles.get(columnNaming.getName(table.getColumn(columnName))); }
@Test public void testRewrite() { tester().assertThat(new TransformCorrelatedSingleRowSubqueryToProject()) .on(p -> p.lateral( ImmutableList.of(p.symbol("l_nationkey")), p.tableScan(new TableHandle( new ConnectorId("local"), new TpchTableHandle("nation", TINY_SCALE_FACTOR)), ImmutableList.of(p.symbol("l_nationkey")), ImmutableMap.of(p.symbol("l_nationkey"), new TpchColumnHandle("nationkey", BIGINT))), p.project( Assignments.of(p.symbol("l_expr2"), expression("l_nationkey + 1")), p.values( ImmutableList.of(), ImmutableList.of( ImmutableList.of()))))) .matches(project( ImmutableMap.of( ("l_expr2"), PlanMatchPattern.expression("l_nationkey + 1"), "l_nationkey", PlanMatchPattern.expression("l_nationkey")), tableScan("nation", ImmutableMap.of("l_nationkey", "nationkey")))); }