Search in sources :

Example 51 with TableHandle

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());
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Example 52 with TableHandle

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());
}
Also used : ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableStatisticsMetadata(com.facebook.presto.spi.statistics.TableStatisticsMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TableStatisticAggregation(com.facebook.presto.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StatisticsWriterNode(com.facebook.presto.sql.planner.plan.StatisticsWriterNode) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) StatisticAggregations(com.facebook.presto.sql.planner.plan.StatisticAggregations) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableHandle(com.facebook.presto.spi.TableHandle)

Example 53 with TableHandle

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());
}
Also used : DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) DeleteHandle(com.facebook.presto.sql.planner.plan.TableWriterNode.DeleteHandle) TableHandle(com.facebook.presto.spi.TableHandle) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode)

Example 54 with TableHandle

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())));
}
Also used : TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 55 with TableHandle

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)))));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Aggregations

TableHandle (com.facebook.presto.spi.TableHandle)70 ConnectorId (com.facebook.presto.spi.ConnectorId)37 ColumnHandle (com.facebook.presto.spi.ColumnHandle)29 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)22 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)21 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)21 ImmutableList (com.google.common.collect.ImmutableList)20 ImmutableMap (com.google.common.collect.ImmutableMap)19 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)18 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)16 Session (com.facebook.presto.Session)15 Type (com.facebook.presto.common.type.Type)15 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)15 Optional (java.util.Optional)15 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)14 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)14 List (java.util.List)14 Metadata (com.facebook.presto.metadata.Metadata)13 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)13 ConnectorSession (com.facebook.presto.spi.ConnectorSession)13