use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.
the class RelationPlanner method visitTable.
@Override
protected RelationPlan visitTable(Table node, Void context) {
Scope scope = analysis.getScope(node);
Query namedQuery = analysis.getNamedQuery(node);
if (namedQuery != null) {
RelationPlan subPlan = process(namedQuery, null);
// Add implicit coercions if view query produces types that don't match the declared output types
// of the view (e.g., if the underlying tables referenced by the view changed)
Type[] types = scope.getRelationType().getAllFields().stream().map(Field::getType).toArray(Type[]::new);
RelationPlan withCoercions = addCoercions(subPlan, types);
if ((!isCTEReuseEnabled(session) || getExecutionPolicy(session).equals("phased")) || (getCteMaxQueueSize(session) < getTaskConcurrency(session) * 2) || !(analysis.getStatement() instanceof Query) || !((Query) analysis.getStatement()).getWith().isPresent()) {
if (getCteMaxQueueSize(session) < getTaskConcurrency(session) * 2) {
LOG.info("Main queue size " + getCteMaxQueueSize(session) + "should be more than 2 times of concurrent task " + getTaskConcurrency(session));
}
return new RelationPlan(withCoercions.getRoot(), scope, withCoercions.getFieldMappings());
}
Integer commonCTERefNum;
if (namedSubPlan.containsKey(node.getName())) {
commonCTERefNum = namedSubPlan.get(node.getName());
} else {
commonCTERefNum = uniqueIdAllocator.getNextId();
namedSubPlan.put(node.getName(), commonCTERefNum);
}
PlanNode cteNode = new CTEScanNode(idAllocator.getNextId(), withCoercions.getRoot(), withCoercions.getFieldMappings(), Optional.empty(), node.getName().toString(), new HashSet<>(), commonCTERefNum);
subPlan = new RelationPlan(cteNode, scope, withCoercions.getFieldMappings());
return subPlan;
}
TableHandle handle = analysis.getTableHandle(node);
ImmutableList.Builder<Symbol> outputSymbolsBuilder = ImmutableList.builder();
ImmutableMap.Builder<Symbol, ColumnHandle> columns = ImmutableMap.builder();
for (Field field : scope.getRelationType().getAllFields()) {
Symbol symbol = planSymbolAllocator.newSymbol(field.getName().get(), field.getType());
outputSymbolsBuilder.add(symbol);
columns.put(symbol, analysis.getColumn(field));
}
List<Symbol> outputSymbols = outputSymbolsBuilder.build();
boolean isDeleteTarget = analysis.isDeleteTarget(createQualifiedObjectName(session, node, node.getName()));
PlanNode root = TableScanNode.newInstance(idAllocator.getNextId(), handle, outputSymbols, columns.build(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, isDeleteTarget);
RelationPlan tableScan = new RelationPlan(root, scope, outputSymbols);
tableScan = addRowFilters(node, tableScan);
tableScan = addColumnMasks(node, tableScan);
return tableScan;
}
use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.
the class MemoryLocalQueryRunner method dropTable.
public void dropTable(String tableName) {
Session session = localQueryRunner.getDefaultSession();
Metadata metadata = localQueryRunner.getMetadata();
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, QualifiedObjectName.valueOf(tableName));
assertTrue(tableHandle.isPresent(), "Table " + tableName + " does not exist");
metadata.dropTable(session, tableHandle.get());
}
use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.
the class SplitFiltering method isSplitFilterApplicable.
public static boolean isSplitFilterApplicable(SqlStageExecution stage) {
List<PlanNode> filterNodeOptional = getFilterNode(stage);
if (filterNodeOptional.isEmpty()) {
return false;
}
PlanNode node = filterNodeOptional.get(0);
if (node instanceof FilterNode) {
FilterNode filterNode = (FilterNode) node;
PlanNode sourceNode = filterNode.getSource();
if (!(sourceNode instanceof TableScanNode)) {
return false;
}
// if a catalog name starts with a $, it's not an normal query, could be something like show tables;
TableHandle table = ((TableScanNode) sourceNode).getTable();
String catalogName = table.getCatalogName().getCatalogName();
if (catalogName.startsWith("$")) {
return false;
}
if (!table.getConnectorHandle().isFilterSupported()) {
return false;
}
if (!isSupportedExpression(filterNode.getPredicate()) && (!((TableScanNode) sourceNode).getPredicate().isPresent() || !isSupportedExpression(((TableScanNode) sourceNode).getPredicate().get()))) {
return false;
}
}
if (node instanceof TableScanNode) {
TableScanNode tableScanNode = (TableScanNode) node;
// if a catalog name starts with a $, it's not an normal query, could be something like show tables;
TableHandle table = tableScanNode.getTable();
String catalogName = table.getCatalogName().getCatalogName();
if (catalogName.startsWith("$")) {
return false;
}
if (!table.getConnectorHandle().isFilterSupported()) {
return false;
}
if (!tableScanNode.getPredicate().isPresent() || !isSupportedExpression(tableScanNode.getPredicate().get())) {
return false;
}
}
return true;
}
use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.
the class ExtractSpatialJoins method loadKdbTree.
private static KdbTree loadKdbTree(String tableName, Session session, Metadata metadata, SplitManager splitManager, PageSourceManager pageSourceManager, PlanNodeId nodeId) {
QualifiedObjectName name = toQualifiedObjectName(tableName, session.getCatalog().get(), session.getSchema().get());
TableHandle tableHandle = metadata.getTableHandle(session, name).orElseThrow(() -> new PrestoException(INVALID_SPATIAL_PARTITIONING, format("Table not found: %s", name)));
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
List<ColumnHandle> visibleColumnHandles = columnHandles.values().stream().filter(handle -> !metadata.getColumnMetadata(session, tableHandle, handle).isHidden()).collect(toImmutableList());
checkSpatialPartitioningTable(visibleColumnHandles.size() == 1, "Expected single column for table %s, but found %s columns", name, columnHandles.size());
ColumnHandle kdbTreeColumn = Iterables.getOnlyElement(visibleColumnHandles);
Optional<KdbTree> kdbTree = Optional.empty();
try (SplitSource splitSource = splitManager.getSplits(session, tableHandle, UNGROUPED_SCHEDULING, null, Optional.empty(), Collections.emptyMap(), ImmutableSet.of(), false, nodeId)) {
while (!Thread.currentThread().isInterrupted()) {
SplitBatch splitBatch = getFutureValue(splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), 1000));
List<Split> splits = splitBatch.getSplits();
for (Split split : splits) {
try (ConnectorPageSource pageSource = pageSourceManager.createPageSource(session, split, tableHandle, ImmutableList.of(kdbTreeColumn), Optional.empty())) {
do {
getFutureValue(pageSource.isBlocked());
Page page = pageSource.getNextPage();
if (page != null && page.getPositionCount() > 0) {
checkSpatialPartitioningTable(!kdbTree.isPresent(), "Expected exactly one row for table %s, but found more", name);
checkSpatialPartitioningTable(page.getPositionCount() == 1, "Expected exactly one row for table %s, but found %s rows", name, page.getPositionCount());
String kdbTreeJson = VARCHAR.getSlice(page.getBlock(0), 0).toStringUtf8();
try {
kdbTree = Optional.of(KdbTreeUtils.fromJson(kdbTreeJson));
} catch (IllegalArgumentException e) {
checkSpatialPartitioningTable(false, "Invalid JSON string for KDB tree: %s", e.getMessage());
}
}
} while (!pageSource.isFinished());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
if (splitBatch.isLastBatch()) {
break;
}
}
}
checkSpatialPartitioningTable(kdbTree.isPresent(), "Expected exactly one row for table %s, but got none", name);
return kdbTree.get();
}
use of io.prestosql.spi.metadata.TableHandle in project hetu-core by openlookeng.
the class TestCubeStatementGenerator method setup.
@BeforeClass
public void setup() {
planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
symbolAllocator = new PlanSymbolAllocator();
builder = CubeStatement.newBuilder();
columnOrderkey = symbolAllocator.newSymbol("orderkey", BIGINT);
columnTotalprice = symbolAllocator.newSymbol("totalprice", DOUBLE);
columnAvgPrice = symbolAllocator.newSymbol("avgprice", DOUBLE);
orderkeyHandle = new TpchColumnHandle("orderkey", BIGINT);
totalpriceHandle = new TpchColumnHandle("totalprice", DOUBLE);
columnMapping = new HashMap<>();
columnMapping.put("orderkey", orderkeyHandle);
columnMapping.put("totalprice", totalpriceHandle);
columnMapping.put("avgprice", columnAvgPrice);
Map<Symbol, ColumnHandle> assignments = ImmutableMap.<Symbol, ColumnHandle>builder().put(columnOrderkey, orderkeyHandle).put(columnTotalprice, totalpriceHandle).build();
TpchTableHandle orders = new TpchTableHandle("orders", 1.0);
TableHandle ordersTableHandle = new TableHandle(new CatalogName("test"), orders, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(orders, TupleDomain.all())));
baseTableScan = new TableScanNode(new PlanNodeId(UUID.randomUUID().toString()), ordersTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
}
Aggregations