Search in sources :

Example 11 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class KafkaQueryRunner method loadTpchTopic.

private static void loadTpchTopic(EmbeddedKafka embeddedKafka, TestingPrestoClient prestoClient, TpchTable<?> table) {
    long start = System.nanoTime();
    log.info("Running import for %s", table.getTableName());
    TestUtils.loadTpchTopic(embeddedKafka, prestoClient, kafkaTopicName(table), new QualifiedObjectName("tpch", TINY_SCHEMA_NAME, table.getTableName().toLowerCase(ENGLISH)));
    log.info("Imported %s in %s", 0, table.getTableName(), nanosSince(start).convertToMostSuccinctTimeUnit());
}
Also used : QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 12 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class TestMinimalFunctionality method testTopicExists.

@Test
public void testTopicExists() {
    QualifiedObjectName name = new QualifiedObjectName("kafka", "default", topicName);
    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.spi.TableHandle) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 13 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class RenameColumnTask method execute.

@Override
public ListenableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
    Optional<TableHandle> tableHandleOptional = metadata.getTableHandle(session, tableName);
    if (!tableHandleOptional.isPresent()) {
        if (!statement.isTableExists()) {
            throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
        }
        return immediateFuture(null);
    }
    Optional<ConnectorMaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, tableName);
    if (optionalMaterializedView.isPresent()) {
        if (!statement.isTableExists()) {
            throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and rename column is not supported", tableName);
        }
        return immediateFuture(null);
    }
    TableHandle tableHandle = tableHandleOptional.get();
    String source = statement.getSource().getValue().toLowerCase(ENGLISH);
    String target = statement.getTarget().getValue().toLowerCase(ENGLISH);
    accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
    ColumnHandle columnHandle = columnHandles.get(source);
    if (columnHandle == null) {
        if (!statement.isColumnExists()) {
            throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
        }
        return immediateFuture(null);
    }
    if (columnHandles.containsKey(target)) {
        throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
    }
    if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {
        throw new SemanticException(NOT_SUPPORTED, statement, "Cannot rename hidden column");
    }
    metadata.renameColumn(session, tableHandle, columnHandle, target);
    return immediateFuture(null);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) TableHandle(com.facebook.presto.spi.TableHandle) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 14 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class RenameTableTask method execute.

@Override
public ListenableFuture<?> execute(RenameTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
    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);
    }
    Optional<ConnectorMaterializedViewDefinition> optionalMaterializedView = metadata.getMaterializedView(session, tableName);
    if (optionalMaterializedView.isPresent()) {
        if (!statement.isExists()) {
            throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and rename is not supported", tableName);
        }
        return immediateFuture(null);
    }
    QualifiedObjectName target = createQualifiedObjectName(session, statement, statement.getTarget());
    if (!metadata.getCatalogHandle(session, target.getCatalogName()).isPresent()) {
        throw new SemanticException(MISSING_CATALOG, statement, "Target catalog '%s' does not exist", target.getCatalogName());
    }
    if (metadata.getTableHandle(session, target).isPresent()) {
        throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Target table '%s' already exists", target);
    }
    if (!tableName.getCatalogName().equals(target.getCatalogName())) {
        throw new SemanticException(NOT_SUPPORTED, statement, "Table rename across catalogs is not supported");
    }
    accessControl.checkCanRenameTable(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName, target);
    metadata.renameTable(session, tableHandle.get(), target);
    return immediateFuture(null);
}
Also used : ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) TableHandle(com.facebook.presto.spi.TableHandle) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Example 15 with QualifiedObjectName

use of com.facebook.presto.common.QualifiedObjectName in project presto by prestodb.

the class RevokeTask method execute.

@Override
public ListenableFuture<?> execute(Revoke statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
    }
    Set<Privilege> privileges;
    if (statement.getPrivileges().isPresent()) {
        privileges = statement.getPrivileges().get().stream().map(privilege -> parsePrivilege(statement, privilege)).collect(toImmutableSet());
    } else {
        // All privileges
        privileges = EnumSet.allOf(Privilege.class);
    }
    // verify current identity has permissions to revoke permissions
    for (Privilege privilege : privileges) {
        accessControl.checkCanRevokeTablePrivilege(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), privilege, tableName, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
    }
    metadata.revokeTablePrivileges(session, tableName, privileges, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
    return immediateFuture(null);
}
Also used : TableHandle(com.facebook.presto.spi.TableHandle) Privilege(com.facebook.presto.spi.security.Privilege) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) SemanticException(com.facebook.presto.sql.analyzer.SemanticException)

Aggregations

QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)59 TableHandle (com.facebook.presto.spi.TableHandle)20 Metadata (com.facebook.presto.metadata.Metadata)15 Session (com.facebook.presto.Session)14 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)14 List (java.util.List)13 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)12 ConnectorId (com.facebook.presto.spi.ConnectorId)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 Map (java.util.Map)11 Objects.requireNonNull (java.util.Objects.requireNonNull)11 Optional (java.util.Optional)11 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)10 TransactionManager (com.facebook.presto.transaction.TransactionManager)10 Type (com.facebook.presto.common.type.Type)9 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 PrestoException (com.facebook.presto.spi.PrestoException)9 WarningCollector (com.facebook.presto.spi.WarningCollector)9 Expression (com.facebook.presto.sql.tree.Expression)9 ImmutableList (com.google.common.collect.ImmutableList)9