use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class MetadataManager method beginDelete.
@Override
public TableHandle beginDelete(Session session, TableHandle tableHandle) {
ConnectorId connectorId = tableHandle.getConnectorId();
CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, connectorId);
ConnectorTableHandle newHandle = catalogMetadata.getMetadata().beginDelete(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle());
return new TableHandle(tableHandle.getConnectorId(), newHandle, tableHandle.getTransaction(), Optional.empty());
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class LogicalPlanner method createAnalyzePlan.
private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStatement) {
TableHandle targetTable = analysis.getAnalyzeTarget().get();
// Plan table scan
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, targetTable);
ImmutableList.Builder<VariableReferenceExpression> tableScanOutputsBuilder = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> variableToColumnHandle = ImmutableMap.builder();
ImmutableMap.Builder<String, VariableReferenceExpression> columnNameToVariable = ImmutableMap.builder();
TableMetadata tableMetadata = metadata.getTableMetadata(session, targetTable);
for (ColumnMetadata column : tableMetadata.getColumns()) {
VariableReferenceExpression variable = variableAllocator.newVariable(getSourceLocation(analyzeStatement), column.getName(), column.getType());
tableScanOutputsBuilder.add(variable);
variableToColumnHandle.put(variable, columnHandles.get(column.getName()));
columnNameToVariable.put(column.getName(), variable);
}
List<VariableReferenceExpression> tableScanOutputs = tableScanOutputsBuilder.build();
TableStatisticsMetadata tableStatisticsMetadata = metadata.getStatisticsCollectionMetadata(session, targetTable.getConnectorId().getCatalogName(), tableMetadata.getMetadata());
TableStatisticAggregation tableStatisticAggregation = statisticsAggregationPlanner.createStatisticsAggregation(tableStatisticsMetadata, columnNameToVariable.build(), true);
StatisticAggregations statisticAggregations = tableStatisticAggregation.getAggregations();
PlanNode planNode = new StatisticsWriterNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), new AggregationNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), new TableScanNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), targetTable, tableScanOutputs, variableToColumnHandle.build(), TupleDomain.all(), TupleDomain.all()), statisticAggregations.getAggregations(), singleGroupingSet(statisticAggregations.getGroupingVariables()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()), targetTable, variableAllocator.newVariable(getSourceLocation(analyzeStatement), "rows", BIGINT), tableStatisticsMetadata.getTableStatistics().contains(ROW_COUNT), tableStatisticAggregation.getDescriptor());
return new RelationPlan(planNode, analysis.getScope(analyzeStatement), planNode.getOutputVariables());
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class LogicalPlanner method createDeletePlan.
private RelationPlan createDeletePlan(Analysis analysis, Delete node) {
DeleteNode deleteNode = new QueryPlanner(analysis, variableAllocator, idAllocator, buildLambdaDeclarationToVariableMap(analysis, variableAllocator), metadata, session).plan(node);
TableHandle handle = analysis.getTableHandle(node.getTable());
DeleteHandle deleteHandle = new DeleteHandle(handle, metadata.getTableMetadata(session, handle).getTable());
TableFinishNode commitNode = new TableFinishNode(deleteNode.getSourceLocation(), idAllocator.getNextId(), deleteNode, Optional.of(deleteHandle), variableAllocator.newVariable("rows", BIGINT), Optional.empty(), Optional.empty());
return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputVariables());
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestPickTableLayout method setUpBeforeClass.
@BeforeClass
public void setUpBeforeClass() {
pickTableLayout = new PickTableLayout(tester().getMetadata());
connectorId = tester().getCurrentConnectorId();
TpchTableHandle nationTpchTableHandle = new TpchTableHandle("nation", 1.0);
TpchTableHandle orderTpchTableHandle = new TpchTableHandle("orders", 1.0);
nationTableHandle = new TableHandle(connectorId, nationTpchTableHandle, TestingTransactionHandle.create(), Optional.of(new TpchTableLayoutHandle(nationTpchTableHandle, TupleDomain.all())));
ordersTableHandle = new TableHandle(connectorId, orderTpchTableHandle, TestingTransactionHandle.create(), Optional.of(new TpchTableLayoutHandle(orderTpchTableHandle, TupleDomain.all())));
}
use of com.facebook.presto.spi.TableHandle in project presto by prestodb.
the class TestPruneIndexSourceColumns method buildProjectedIndexSource.
private static PlanNode buildProjectedIndexSource(PlanBuilder p, Predicate<VariableReferenceExpression> projectionFilter) {
VariableReferenceExpression orderkey = p.variable("orderkey", INTEGER);
VariableReferenceExpression custkey = p.variable("custkey", INTEGER);
VariableReferenceExpression totalprice = p.variable("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(identityAssignmentsAsSymbolReferences(ImmutableList.of(orderkey, custkey, totalprice).stream().filter(projectionFilter).collect(toImmutableList())), p.indexSource(new TableHandle(new ConnectorId("local"), new TpchTableHandle("orders", TINY_SCALE_FACTOR), TestingTransactionHandle.create(), Optional.empty()), ImmutableSet.of(orderkey, custkey), ImmutableList.of(orderkey, custkey, totalprice), ImmutableMap.of(orderkey, orderkeyHandle, custkey, custkeyHandle, totalprice, totalpriceHandle), TupleDomain.fromFixedValues(ImmutableMap.of(totalpriceHandle, asNull(DOUBLE)))));
}
Aggregations