Search in sources :

Example 6 with AccessControl

use of io.trino.security.AccessControl in project trino by trinodb.

the class TableProceduresPropertyManager method getProperties.

public Map<String, Object> getProperties(CatalogName catalog, String procedureName, Map<String, Expression> sqlPropertyValues, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters) {
    Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(new Key(catalog, procedureName));
    if (supportedProperties == null) {
        throw new TrinoException(NOT_FOUND, format("Catalog '%s' table procedure '%s' property not found", catalog, procedureName));
    }
    Map<String, Optional<Object>> propertyValues = evaluateProperties(sqlPropertyValues.entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList()), session, plannerContext, accessControl, parameters, true, supportedProperties, INVALID_PROCEDURE_ARGUMENT, format("catalog '%s' table procedure '%s' property", catalog, procedureName));
    return propertyValues.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
}
Also used : PropertyUtil.evaluateProperties(io.trino.metadata.PropertyUtil.evaluateProperties) ConcurrentMap(java.util.concurrent.ConcurrentMap) INVALID_PROCEDURE_ARGUMENT(io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) CatalogName(io.trino.connector.CatalogName) NodeRef(io.trino.sql.tree.NodeRef) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Property(io.trino.sql.tree.Property) Identifier(io.trino.sql.tree.Identifier) NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) PropertyMetadata(io.trino.spi.session.PropertyMetadata) Maps(com.google.common.collect.Maps) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AccessControl(io.trino.security.AccessControl) Parameter(io.trino.sql.tree.Parameter) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) Identifier(io.trino.sql.tree.Identifier) Optional(java.util.Optional) PropertyMetadata(io.trino.spi.session.PropertyMetadata) TrinoException(io.trino.spi.TrinoException) Property(io.trino.sql.tree.Property)

Example 7 with AccessControl

use of io.trino.security.AccessControl in project trino by trinodb.

the class CreateMaterializedViewTask method execute.

@Override
public ListenableFuture<Void> execute(CreateMaterializedView statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
    Map<NodeRef<Parameter>, Expression> parameterLookup = parameterExtractor(statement, parameters);
    String sql = getFormattedSql(statement.getQuery(), sqlParser);
    Analysis analysis = analyzerFactory.createAnalyzer(session, parameters, parameterLookup, stateMachine.getWarningCollector()).analyze(statement);
    List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType().getTypeId())).collect(toImmutableList());
    CatalogName catalogName = getRequiredCatalogHandle(plannerContext.getMetadata(), session, statement, name.getCatalogName());
    Map<String, Object> properties = materializedViewPropertyManager.getProperties(catalogName, statement.getProperties(), session, plannerContext, accessControl, parameterLookup, true);
    MaterializedViewDefinition definition = new MaterializedViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, statement.getComment(), session.getIdentity(), Optional.empty(), properties);
    accessControl.checkCanCreateMaterializedView(session.toSecurityContext(), name, properties);
    plannerContext.getMetadata().createMaterializedView(session, name, definition, statement.isReplace(), statement.isNotExists());
    stateMachine.setOutput(analysis.getTarget());
    stateMachine.setReferencedTables(analysis.getReferencedTables());
    return immediateVoidFuture();
}
Also used : ViewColumn(io.trino.metadata.ViewColumn) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) ParameterUtils.parameterExtractor(io.trino.sql.ParameterUtils.parameterExtractor) Inject(javax.inject.Inject) CatalogName(io.trino.connector.CatalogName) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) NodeRef(io.trino.sql.tree.NodeRef) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) SqlParser(io.trino.sql.parser.SqlParser) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MetadataUtil.getRequiredCatalogHandle(io.trino.metadata.MetadataUtil.getRequiredCatalogHandle) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) List(java.util.List) FeaturesConfig(io.trino.FeaturesConfig) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AccessControl(io.trino.security.AccessControl) Parameter(io.trino.sql.tree.Parameter) SqlFormatterUtil.getFormattedSql(io.trino.sql.SqlFormatterUtil.getFormattedSql) WarningCollector(io.trino.execution.warnings.WarningCollector) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) Analysis(io.trino.sql.analyzer.Analysis) ViewColumn(io.trino.metadata.ViewColumn) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) NodeRef(io.trino.sql.tree.NodeRef) Expression(io.trino.sql.tree.Expression) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) Analysis(io.trino.sql.analyzer.Analysis) CatalogName(io.trino.connector.CatalogName) Session(io.trino.Session)

Aggregations

AccessControl (io.trino.security.AccessControl)7 Map (java.util.Map)6 Session (io.trino.Session)5 PlannerContext (io.trino.sql.PlannerContext)5 List (java.util.List)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 CatalogName (io.trino.connector.CatalogName)4 WarningCollector (io.trino.execution.warnings.WarningCollector)4 Expression (io.trino.sql.tree.Expression)4 NodeRef (io.trino.sql.tree.NodeRef)4 Parameter (io.trino.sql.tree.Parameter)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)3 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)3