Search in sources :

Example 1 with INVOKER

use of com.facebook.presto.sql.tree.CreateView.Security.INVOKER in project presto by prestodb.

the class CreateViewTask method execute.

@Override
public ListenableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
    accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), name);
    String sql = getFormattedSql(statement.getQuery(), sqlParser, Optional.of(parameters));
    Analysis analysis = analyzeStatement(statement, session, metadata, accessControl, parameters, warningCollector);
    List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType())).collect(toImmutableList());
    List<ColumnMetadata> columnMetadata = columns.stream().map(column -> new ColumnMetadata(column.getName(), column.getType())).collect(toImmutableList());
    ConnectorTableMetadata viewMetadata = new ConnectorTableMetadata(toSchemaTableName(name), columnMetadata);
    // use DEFINER security by default
    Optional<String> owner = Optional.of(session.getUser());
    if (statement.getSecurity().orElse(null) == INVOKER) {
        owner = Optional.empty();
    }
    String data = codec.toJson(new ViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, owner, !owner.isPresent()));
    metadata.createView(session, name.getCatalogName(), viewMetadata, data, statement.isReplace());
    return immediateFuture(null);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) JsonCodec(com.facebook.airlift.json.JsonCodec) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) INVOKER(com.facebook.presto.sql.tree.CreateView.Security.INVOKER) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) Inject(javax.inject.Inject) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) TransactionManager(com.facebook.presto.transaction.TransactionManager) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SqlParser(com.facebook.presto.sql.parser.SqlParser) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) SqlFormatterUtil.getFormattedSql(com.facebook.presto.sql.SqlFormatterUtil.getFormattedSql) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Expression(com.facebook.presto.sql.tree.Expression) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) Analysis(com.facebook.presto.sql.analyzer.Analysis) Optional(java.util.Optional) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) CreateView(com.facebook.presto.sql.tree.CreateView) Statement(com.facebook.presto.sql.tree.Statement) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Analysis(com.facebook.presto.sql.analyzer.Analysis) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Aggregations

JsonCodec (com.facebook.airlift.json.JsonCodec)1 Session (com.facebook.presto.Session)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 Metadata (com.facebook.presto.metadata.Metadata)1 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)1 MetadataUtil.toSchemaTableName (com.facebook.presto.metadata.MetadataUtil.toSchemaTableName)1 ViewDefinition (com.facebook.presto.metadata.ViewDefinition)1 ViewColumn (com.facebook.presto.metadata.ViewDefinition.ViewColumn)1 AccessControl (com.facebook.presto.security.AccessControl)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 SqlFormatterUtil.getFormattedSql (com.facebook.presto.sql.SqlFormatterUtil.getFormattedSql)1 Analysis (com.facebook.presto.sql.analyzer.Analysis)1 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)1 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 CreateView (com.facebook.presto.sql.tree.CreateView)1 INVOKER (com.facebook.presto.sql.tree.CreateView.Security.INVOKER)1 Expression (com.facebook.presto.sql.tree.Expression)1