Search in sources :

Example 11 with TableHandle

use of com.facebook.presto.metadata.TableHandle in project presto by prestodb.

the class TestMinimalFunctionality method testTableExists.

@Test
public void testTableExists() throws Exception {
    QualifiedObjectName name = new QualifiedObjectName("redis", "default", tableName);
    transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
        Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
        assertTrue(handle.isPresent());
    });
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TableHandle(com.facebook.presto.metadata.TableHandle) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 12 with TableHandle

use of com.facebook.presto.metadata.TableHandle in project presto by prestodb.

the class RelationPlanner method visitTable.

@Override
protected RelationPlan visitTable(Table node, Void context) {
    Query namedQuery = analysis.getNamedQuery(node);
    Scope scope = analysis.getScope(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);
        return new RelationPlan(withCoercions.getRoot(), scope, withCoercions.getFieldMappings());
    }
    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 = symbolAllocator.newSymbol(field.getName().get(), field.getType());
        outputSymbolsBuilder.add(symbol);
        columns.put(symbol, analysis.getColumn(field));
    }
    List<Symbol> outputSymbols = outputSymbolsBuilder.build();
    PlanNode root = new TableScanNode(idAllocator.getNextId(), handle, outputSymbols, columns.build(), Optional.empty(), TupleDomain.all(), null);
    return new RelationPlan(root, scope, outputSymbols);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Query(com.facebook.presto.sql.tree.Query) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Field(com.facebook.presto.sql.analyzer.Field) ComparisonExpressionType(com.facebook.presto.sql.tree.ComparisonExpressionType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) RelationType(com.facebook.presto.sql.analyzer.RelationType) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Scope(com.facebook.presto.sql.analyzer.Scope) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) TableHandle(com.facebook.presto.metadata.TableHandle)

Example 13 with TableHandle

use of com.facebook.presto.metadata.TableHandle in project presto by prestodb.

the class QueryPlanner method plan.

public DeleteNode plan(Delete node) {
    RelationType descriptor = analysis.getOutputDescriptor(node.getTable());
    TableHandle handle = analysis.getTableHandle(node.getTable());
    ColumnHandle rowIdHandle = metadata.getUpdateRowIdColumnHandle(session, handle);
    Type rowIdType = metadata.getColumnMetadata(session, handle, rowIdHandle).getType();
    // add table columns
    ImmutableList.Builder<Symbol> outputSymbols = ImmutableList.builder();
    ImmutableMap.Builder<Symbol, ColumnHandle> columns = ImmutableMap.builder();
    ImmutableList.Builder<Field> fields = ImmutableList.builder();
    for (Field field : descriptor.getAllFields()) {
        Symbol symbol = symbolAllocator.newSymbol(field.getName().get(), field.getType());
        outputSymbols.add(symbol);
        columns.put(symbol, analysis.getColumn(field));
        fields.add(field);
    }
    // add rowId column
    Field rowIdField = Field.newUnqualified(Optional.empty(), rowIdType);
    Symbol rowIdSymbol = symbolAllocator.newSymbol("$rowId", rowIdField.getType());
    outputSymbols.add(rowIdSymbol);
    columns.put(rowIdSymbol, rowIdHandle);
    fields.add(rowIdField);
    // create table scan
    PlanNode tableScan = new TableScanNode(idAllocator.getNextId(), handle, outputSymbols.build(), columns.build(), Optional.empty(), TupleDomain.all(), null);
    Scope scope = Scope.builder().withRelationType(new RelationType(fields.build())).build();
    RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputSymbols.build());
    TranslationMap translations = new TranslationMap(relationPlan, analysis, lambdaDeclarationToSymbolMap);
    translations.setFieldMappings(relationPlan.getFieldMappings());
    PlanBuilder builder = new PlanBuilder(translations, relationPlan.getRoot(), analysis.getParameters());
    if (node.getWhere().isPresent()) {
        builder = filter(builder, node.getWhere().get(), node);
    }
    // create delete node
    Symbol rowId = builder.translate(new FieldReference(relationPlan.getDescriptor().indexOf(rowIdField)));
    List<Symbol> outputs = ImmutableList.of(symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY));
    return new DeleteNode(idAllocator.getNextId(), builder.getRoot(), new DeleteHandle(handle, metadata.getTableMetadata(session, handle).getTable()), rowId, outputs);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) FieldReference(com.facebook.presto.sql.tree.FieldReference) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Field(com.facebook.presto.sql.analyzer.Field) DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) Type(com.facebook.presto.spi.type.Type) RelationType(com.facebook.presto.sql.analyzer.RelationType) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) Scope(com.facebook.presto.sql.analyzer.Scope) RelationType(com.facebook.presto.sql.analyzer.RelationType) DeleteHandle(com.facebook.presto.sql.planner.plan.TableWriterNode.DeleteHandle) TableHandle(com.facebook.presto.metadata.TableHandle)

Example 14 with TableHandle

use of com.facebook.presto.metadata.TableHandle in project presto by prestodb.

the class TestHiveIntegrationSmokeTest method getHiveTableProperty.

private Object getHiveTableProperty(String tableName, Function<HiveTableLayoutHandle, Object> propertyGetter) {
    Session session = getSession();
    Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
    return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
        Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName));
        assertTrue(tableHandle.isPresent());
        List<TableLayoutResult> layouts = metadata.getLayouts(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty());
        TableLayout layout = getOnlyElement(layouts).getLayout();
        return propertyGetter.apply((HiveTableLayoutHandle) layout.getHandle().getConnectorHandle());
    });
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Metadata(com.facebook.presto.metadata.Metadata) TableHandle(com.facebook.presto.metadata.TableHandle) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) TableLayout(com.facebook.presto.metadata.TableLayout) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session)

Example 15 with TableHandle

use of com.facebook.presto.metadata.TableHandle in project presto by prestodb.

the class DropTableTask method execute.

@Override
public ListenableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        if (!statement.isExists()) {
            throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
        }
        return immediateFuture(null);
    }
    accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);
    metadata.dropTable(session, tableHandle.get());
    return immediateFuture(null);
}
Also used : TableHandle(com.facebook.presto.metadata.TableHandle) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Aggregations

TableHandle (com.facebook.presto.metadata.TableHandle)20 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)13 Session (com.facebook.presto.Session)9 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)7 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)7 ColumnHandle (com.facebook.presto.spi.ColumnHandle)6 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)6 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)6 ConnectorId (com.facebook.presto.connector.ConnectorId)5 Type (com.facebook.presto.spi.type.Type)5 Symbol (com.facebook.presto.sql.planner.Symbol)4 TestingColumnHandle (com.facebook.presto.sql.planner.TestingColumnHandle)4 TestingTableHandle (com.facebook.presto.sql.planner.TestingTableHandle)4 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)4 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)4 TableLayoutResult (com.facebook.presto.metadata.TableLayoutResult)3 TableMetadata (com.facebook.presto.metadata.TableMetadata)3 ImmutableList (com.google.common.collect.ImmutableList)3 HiveQueryRunner.createBucketedSession (com.facebook.presto.hive.HiveQueryRunner.createBucketedSession)2 Metadata (com.facebook.presto.metadata.Metadata)2