Search in sources :

Example 1 with AccessControlManager

use of com.facebook.presto.security.AccessControlManager in project presto by prestodb.

the class TestQueryStateMachine method createQueryStateMachineWithTicker.

private QueryStateMachine createQueryStateMachineWithTicker(Ticker ticker) {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.beginWithTicker(QUERY_ID, QUERY, TEST_SESSION, LOCATION, false, transactionManager, accessControl, executor, ticker, metadata);
    stateMachine.setInputs(INPUTS);
    stateMachine.setOutput(OUTPUT);
    stateMachine.setOutputFieldNames(OUTPUT_FIELD_NAMES);
    stateMachine.setUpdateType(UPDATE_TYPE);
    stateMachine.setMemoryPool(MEMORY_POOL);
    for (Entry<String, String> entry : SET_SESSION_PROPERTIES.entrySet()) {
        stateMachine.addSetSessionProperties(entry.getKey(), entry.getValue());
    }
    RESET_SESSION_PROPERTIES.forEach(stateMachine::addResetSessionProperties);
    return stateMachine;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl)

Example 2 with AccessControlManager

use of com.facebook.presto.security.AccessControlManager in project presto by prestodb.

the class TestQueryStateMachine method createQueryStateMachineWithTicker.

private QueryStateMachine createQueryStateMachineWithTicker(Ticker ticker, TransactionManager transactionManager) {
    Metadata metadata = MetadataManager.createTestMetadataManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.beginWithTicker(QUERY, Optional.empty(), TEST_SESSION, LOCATION, new ResourceGroupId("test"), QUERY_TYPE, false, transactionManager, accessControl, executor, ticker, metadata, WarningCollector.NOOP);
    stateMachine.setInputs(INPUTS);
    stateMachine.setOutput(OUTPUT);
    stateMachine.setColumns(OUTPUT_FIELD_NAMES, OUTPUT_FIELD_TYPES);
    stateMachine.setUpdateType(UPDATE_TYPE);
    stateMachine.setMemoryPool(MEMORY_POOL);
    for (Entry<String, String> entry : SET_SESSION_PROPERTIES.entrySet()) {
        stateMachine.addSetSessionProperties(entry.getKey(), entry.getValue());
    }
    RESET_SESSION_PROPERTIES.forEach(stateMachine::addResetSessionProperties);
    return stateMachine;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl)

Example 3 with AccessControlManager

use of com.facebook.presto.security.AccessControlManager in project presto by prestodb.

the class ConnectorManager method addCatalogConnector.

private synchronized void addCatalogConnector(String catalogName, ConnectorId connectorId, ConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    MaterializedConnector connector = new MaterializedConnector(connectorId, createConnector(connectorId, factory, properties));
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager, connector.getSessionProperties()));
    ConnectorId systemId = createSystemTablesConnectorId(connectorId);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new DelegatingSystemTablesProvider(new StaticSystemTablesProvider(connector.getSystemTables()), new MetadataBasedSystemTablesProvider(metadataManager, catalogName));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(systemId, nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId), connector.getSessionProperties()));
    Catalog catalog = new Catalog(catalogName, connector.getConnectorId(), connector.getConnector(), informationSchemaConnector.getConnectorId(), informationSchemaConnector.getConnector(), systemConnector.getConnectorId(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getConnectorId());
        removeConnectorInternal(informationSchemaConnector.getConnectorId());
        removeConnectorInternal(connector.getConnectorId());
        throw e;
    }
}
Also used : SystemConnector(com.facebook.presto.connector.system.SystemConnector) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) MetadataManager(com.facebook.presto.metadata.MetadataManager) ConnectorFilterStatsCalculatorService(com.facebook.presto.cost.ConnectorFilterStatsCalculatorService) RecordPageSourceProvider(com.facebook.presto.split.RecordPageSourceProvider) RowExpressionOptimizer(com.facebook.presto.sql.relational.RowExpressionOptimizer) ConnectorPlanOptimizerManager(com.facebook.presto.sql.planner.ConnectorPlanOptimizerManager) PropertyMetadata(com.facebook.presto.spi.session.PropertyMetadata) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ConnectorRecordSetProvider(com.facebook.presto.spi.connector.ConnectorRecordSetProvider) Map(java.util.Map) PageIndexerFactory(com.facebook.presto.spi.PageIndexerFactory) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorMetadataUpdaterManager(com.facebook.presto.metadata.ConnectorMetadataUpdaterManager) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) FilterStatsCalculator(com.facebook.presto.cost.FilterStatsCalculator) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) PageSinkManager(com.facebook.presto.split.PageSinkManager) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DomainTranslator(com.facebook.presto.spi.relation.DomainTranslator) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) SplitManager(com.facebook.presto.split.SplitManager) GuardedBy(javax.annotation.concurrent.GuardedBy) String.format(java.lang.String.format) SystemTablesProvider(com.facebook.presto.connector.system.SystemTablesProvider) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Procedure(com.facebook.presto.spi.procedure.Procedure) List(java.util.List) Catalog(com.facebook.presto.metadata.Catalog) Optional(java.util.Optional) SystemConnector(com.facebook.presto.connector.system.SystemConnector) PredicateCompiler(com.facebook.presto.spi.relation.PredicateCompiler) ConnectorId(com.facebook.presto.spi.ConnectorId) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) ConnectorRowExpressionService(com.facebook.presto.sql.relational.ConnectorRowExpressionService) DeterminismEvaluator(com.facebook.presto.spi.relation.DeterminismEvaluator) Logger(com.facebook.airlift.log.Logger) NodeInfo(com.facebook.airlift.node.NodeInfo) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) AccessControlManager(com.facebook.presto.security.AccessControlManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) ConnectorPlanOptimizerProvider(com.facebook.presto.spi.connector.ConnectorPlanOptimizerProvider) Inject(javax.inject.Inject) RowExpressionFormatter(com.facebook.presto.sql.planner.planPrinter.RowExpressionFormatter) ImmutableList(com.google.common.collect.ImmutableList) PageSourceManager(com.facebook.presto.split.PageSourceManager) TypeManager(com.facebook.presto.common.type.TypeManager) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId) IndexManager(com.facebook.presto.index.IndexManager) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PageSorter(com.facebook.presto.spi.PageSorter) ConnectorContext(com.facebook.presto.spi.connector.ConnectorContext) ConnectorPageSinkProvider(com.facebook.presto.spi.connector.ConnectorPageSinkProvider) TransactionManager(com.facebook.presto.transaction.TransactionManager) Connector(com.facebook.presto.spi.connector.Connector) ConnectorIndexProvider(com.facebook.presto.spi.connector.ConnectorIndexProvider) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) CatalogManager(com.facebook.presto.metadata.CatalogManager) ConnectorMetadataUpdaterProvider(com.facebook.presto.spi.connector.ConnectorMetadataUpdaterProvider) HandleResolver(com.facebook.presto.metadata.HandleResolver) ConnectorAccessControl(com.facebook.presto.spi.connector.ConnectorAccessControl) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(com.facebook.presto.connector.informationSchema.InformationSchemaConnector) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) MetadataBasedSystemTablesProvider(com.facebook.presto.connector.system.MetadataBasedSystemTablesProvider) SystemTablesProvider(com.facebook.presto.connector.system.SystemTablesProvider) StaticSystemTablesProvider(com.facebook.presto.connector.system.StaticSystemTablesProvider) DelegatingSystemTablesProvider(com.facebook.presto.connector.system.DelegatingSystemTablesProvider) Catalog(com.facebook.presto.metadata.Catalog) ConnectorId.createInformationSchemaConnectorId(com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorId.createSystemTablesConnectorId(com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId)

Example 4 with AccessControlManager

use of com.facebook.presto.security.AccessControlManager in project presto by prestodb.

the class TestAnalyzer method setup.

@BeforeMethod(alwaysRun = true)
public void setup() throws Exception {
    TypeManager typeManager = new TypeRegistry();
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    accessControl = new AccessControlManager(transactionManager);
    metadata = new MetadataManager(new FeaturesConfig(), typeManager, new BlockEncodingManager(typeManager), new SessionPropertyManager(), new SchemaPropertyManager(), new TablePropertyManager(), transactionManager);
    metadata.getFunctionRegistry().addFunctions(ImmutableList.of(APPLY_FUNCTION));
    catalogManager.registerCatalog(createTestingCatalog(TPCH_CATALOG, TPCH_CONNECTOR_ID));
    catalogManager.registerCatalog(createTestingCatalog(SECOND_CATALOG, SECOND_CONNECTOR_ID));
    catalogManager.registerCatalog(createTestingCatalog(THIRD_CATALOG, THIRD_CONNECTOR_ID));
    SchemaTableName table1 = new SchemaTableName("s1", "t1");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table1, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT)))));
    SchemaTableName table2 = new SchemaTableName("s1", "t2");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table2, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT)))));
    SchemaTableName table3 = new SchemaTableName("s1", "t3");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table3, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("x", BIGINT, null, true)))));
    // table in different catalog
    SchemaTableName table4 = new SchemaTableName("s2", "t4");
    inSetupTransaction(session -> metadata.createTable(session, SECOND_CATALOG, new ConnectorTableMetadata(table4, ImmutableList.of(new ColumnMetadata("a", BIGINT)))));
    // table with a hidden column
    SchemaTableName table5 = new SchemaTableName("s1", "t5");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table5, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT, null, true)))));
    // table with a varchar column
    SchemaTableName table6 = new SchemaTableName("s1", "t6");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table6, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", VARCHAR), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT)))));
    // table with bigint, double, array of bigints and array of doubles column
    SchemaTableName table7 = new SchemaTableName("s1", "t7");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table7, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", DOUBLE), new ColumnMetadata("c", new ArrayType(BIGINT)), new ColumnMetadata("d", new ArrayType(DOUBLE))))));
    // valid view referencing table in same schema
    String viewData1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT)), Optional.of("user")));
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v1"), viewData1, false));
    // stale view (different column type)
    String viewData2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", VARCHAR)), Optional.of("user")));
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v2"), viewData2, false));
    // view referencing table in different schema from itself and session
    String viewData3 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t4", Optional.of(SECOND_CATALOG), Optional.of("s2"), ImmutableList.of(new ViewColumn("a", BIGINT)), Optional.of("owner")));
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(THIRD_CATALOG, "s3", "v3"), viewData3, false));
    // valid view with uppercase column name
    String viewData4 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select A from t1", Optional.of("tpch"), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT)), Optional.of("user")));
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName("tpch", "s1", "v4"), viewData4, false));
    // recursive view referencing to itself
    String viewData5 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select * from v5", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT)), Optional.of("user")));
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v5"), viewData5, false));
    this.metadata = metadata;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) TypeRegistry(com.facebook.presto.type.TypeRegistry) SchemaTableName(com.facebook.presto.spi.SchemaTableName) CatalogManager(com.facebook.presto.metadata.CatalogManager) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) ArrayType(com.facebook.presto.type.ArrayType) MetadataManager(com.facebook.presto.metadata.MetadataManager) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) TypeManager(com.facebook.presto.spi.type.TypeManager) TablePropertyManager(com.facebook.presto.metadata.TablePropertyManager) SchemaPropertyManager(com.facebook.presto.metadata.SchemaPropertyManager) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with AccessControlManager

use of com.facebook.presto.security.AccessControlManager in project presto by prestodb.

the class AbstractAnalyzerTest method setup.

@BeforeClass
public void setup() {
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    accessControl = new AccessControlManager(transactionManager);
    metadata = createTestMetadataManager(transactionManager, new FeaturesConfig());
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(APPLY_FUNCTION));
    metadata.getFunctionAndTypeManager().addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql")));
    metadata.getFunctionAndTypeManager().createFunction(SQL_FUNCTION_SQUARE, true);
    Catalog tpchTestCatalog = createTestingCatalog(TPCH_CATALOG, TPCH_CONNECTOR_ID);
    catalogManager.registerCatalog(tpchTestCatalog);
    metadata.getAnalyzePropertyManager().addProperties(TPCH_CONNECTOR_ID, tpchTestCatalog.getConnector(TPCH_CONNECTOR_ID).getAnalyzeProperties());
    catalogManager.registerCatalog(createTestingCatalog(SECOND_CATALOG, SECOND_CONNECTOR_ID));
    catalogManager.registerCatalog(createTestingCatalog(THIRD_CATALOG, THIRD_CONNECTOR_ID));
    SchemaTableName table1 = new SchemaTableName("s1", "t1");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table1, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    SchemaTableName table2 = new SchemaTableName("s1", "t2");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table2, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT))), false));
    SchemaTableName table3 = new SchemaTableName("s1", "t3");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table3, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("x", BIGINT, null, true))), false));
    // table in different catalog
    SchemaTableName table4 = new SchemaTableName("s2", "t4");
    inSetupTransaction(session -> metadata.createTable(session, SECOND_CATALOG, new ConnectorTableMetadata(table4, ImmutableList.of(new ColumnMetadata("a", BIGINT))), false));
    // table with a hidden column
    SchemaTableName table5 = new SchemaTableName("s1", "t5");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table5, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT, null, true))), false));
    // table with a varchar column
    SchemaTableName table6 = new SchemaTableName("s1", "t6");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table6, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", VARCHAR), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    // table with bigint, double, array of bigints and array of doubles column
    SchemaTableName table7 = new SchemaTableName("s1", "t7");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table7, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", DOUBLE), new ColumnMetadata("c", new ArrayType(BIGINT)), new ColumnMetadata("d", new ArrayType(DOUBLE)))), false));
    // table with double, array of bigints, real, and bigint
    SchemaTableName table8 = new SchemaTableName("s1", "t8");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table8, ImmutableList.of(new ColumnMetadata("a", DOUBLE), new ColumnMetadata("b", new ArrayType(BIGINT)), new ColumnMetadata("c", RealType.REAL), new ColumnMetadata("d", BIGINT))), false));
    // table with double, array of bigints, real, and bigint
    SchemaTableName table9 = new SchemaTableName("s1", "t9");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table9, ImmutableList.of(new ColumnMetadata("a", DOUBLE), new ColumnMetadata("b", new ArrayType(BIGINT)), new ColumnMetadata("c", RealType.REAL), new ColumnMetadata("d", BIGINT))), false));
    // table with nested struct
    SchemaTableName table10 = new SchemaTableName("s1", "t10");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table10, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("w"), BIGINT), new RowType.Field(Optional.of("x"), RowType.from(ImmutableList.of(new RowType.Field(Optional.of("y"), BIGINT), new RowType.Field(Optional.of("z"), DOUBLE))))))), new ColumnMetadata("c", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("d"), BIGINT)))))), false));
    // valid view referencing table in same schema
    String viewData1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata1 = new ConnectorTableMetadata(new SchemaTableName("s1", "v1"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata1, viewData1, false));
    // stale view (different column type)
    String viewData2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", VARCHAR)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata2 = new ConnectorTableMetadata(new SchemaTableName("s1", "v2"), ImmutableList.of(new ColumnMetadata("a", VARCHAR)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata2, viewData2, false));
    // view referencing table in different schema from itself and session
    String viewData3 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select a from t4", Optional.of(SECOND_CATALOG), Optional.of("s2"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("owner"), false));
    ConnectorTableMetadata viewMetadata3 = new ConnectorTableMetadata(new SchemaTableName("s3", "v3"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, THIRD_CATALOG, viewMetadata3, viewData3, false));
    // valid view with uppercase column name
    String viewData4 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select A from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata4 = new ConnectorTableMetadata(new SchemaTableName("s1", "v4"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata4, viewData4, false));
    // recursive view referencing to itself
    String viewData5 = JsonCodec.jsonCodec(ViewDefinition.class).toJson(new ViewDefinition("select * from v5", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewDefinition.ViewColumn("a", BIGINT)), Optional.of("user"), false));
    ConnectorTableMetadata viewMetadata5 = new ConnectorTableMetadata(new SchemaTableName("s1", "v5"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
    inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata5, viewData5, false));
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) ViewDefinition(com.facebook.presto.metadata.ViewDefinition) RowType(com.facebook.presto.common.type.RowType) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) SchemaTableName(com.facebook.presto.spi.SchemaTableName) CatalogManager(com.facebook.presto.metadata.CatalogManager) Catalog(com.facebook.presto.metadata.Catalog) ArrayType(com.facebook.presto.common.type.ArrayType) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

AccessControlManager (com.facebook.presto.security.AccessControlManager)5 CatalogManager (com.facebook.presto.metadata.CatalogManager)3 Catalog (com.facebook.presto.metadata.Catalog)2 Metadata (com.facebook.presto.metadata.Metadata)2 MetadataManager (com.facebook.presto.metadata.MetadataManager)2 ViewDefinition (com.facebook.presto.metadata.ViewDefinition)2 AccessControl (com.facebook.presto.security.AccessControl)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 TransactionManager (com.facebook.presto.transaction.TransactionManager)2 Logger (com.facebook.airlift.log.Logger)1 NodeInfo (com.facebook.airlift.node.NodeInfo)1 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)1 BlockEncodingSerde (com.facebook.presto.common.block.BlockEncodingSerde)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 RowType (com.facebook.presto.common.type.RowType)1 TypeManager (com.facebook.presto.common.type.TypeManager)1 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)1 DelegatingSystemTablesProvider (com.facebook.presto.connector.system.DelegatingSystemTablesProvider)1