Search in sources :

Example 11 with CatalogManager

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

the class TestSetRoleTask method setUp.

@BeforeClass
public void setUp() throws Exception {
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    accessControl = new AllowAllAccessControl();
    metadata = MetadataManager.createTestMetadataManager(transactionManager, new FeaturesConfig());
    catalogManager.registerCatalog(createBogusTestingCatalog(CATALOG_NAME));
    executor = newCachedThreadPool(daemonThreadsNamed("test-set-role-task-executor-%s"));
    parser = new SqlParser();
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) SqlParser(com.facebook.presto.sql.parser.SqlParser) CatalogManager(com.facebook.presto.metadata.CatalogManager) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with CatalogManager

use of com.facebook.presto.metadata.CatalogManager 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)

Example 13 with CatalogManager

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

the class TestStartTransactionTask method testStartTransactionIdleExpiration.

@Test
public void testStartTransactionIdleExpiration() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
    new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    long start = System.nanoTime();
    while (!transactionManager.getAllTransactionInfos().isEmpty()) {
        if (Duration.nanosSince(start).toMillis() > 10_000) {
            fail("Transaction did not expire in the allotted time");
        }
        TimeUnit.MILLISECONDS.sleep(10);
    }
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManagerConfig(com.facebook.presto.transaction.TransactionManagerConfig) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Duration(io.airlift.units.Duration) CatalogManager(com.facebook.presto.metadata.CatalogManager) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

CatalogManager (com.facebook.presto.metadata.CatalogManager)13 Test (org.testng.annotations.Test)7 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)3 SystemConnector (com.facebook.presto.connector.system.SystemConnector)3 TablePropertyManager (com.facebook.presto.metadata.TablePropertyManager)3 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)3 Connector (com.facebook.presto.spi.connector.Connector)3 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)3 TestingConnectorContext (com.facebook.presto.testing.TestingConnectorContext)3 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)3 BeforeClass (org.testng.annotations.BeforeClass)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 AbstractMockMetadata (com.facebook.presto.metadata.AbstractMockMetadata)2 Catalog (com.facebook.presto.metadata.Catalog)2 ColumnPropertyManager (com.facebook.presto.metadata.ColumnPropertyManager)2 ViewDefinition (com.facebook.presto.metadata.ViewDefinition)2 AccessControlManager (com.facebook.presto.security.AccessControlManager)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 ConnectorId (com.facebook.presto.spi.ConnectorId)2