Search in sources :

Example 6 with CatalogManager

use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.

the class TestDropCacheTask method setUp.

@BeforeMethod
public void setUp() {
    PropertyService.setProperty(HetuConstant.SPLIT_CACHE_MAP_ENABLED, true);
    SplitCacheMap splitCacheMap = createNew();
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    TablePropertyManager tablePropertyManager = new TablePropertyManager();
    ColumnPropertyManager columnPropertyManager = new ColumnPropertyManager();
    Catalog testCatalog = createBogusTestingCatalog(CATALOG_NAME);
    catalogManager.registerCatalog(testCatalog);
    tablePropertyManager.addProperties(testCatalog.getConnectorCatalogName(), ImmutableList.of(stringProperty("baz", "test property", null, false)));
    columnPropertyManager.addProperties(testCatalog.getConnectorCatalogName(), ImmutableList.of());
    testSession = testSessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    ColumnMetadata columnMetadataA = new ColumnMetadata("a", BIGINT);
    TupleDomain tupleDomainA = TupleDomain.withColumnDomains(ImmutableMap.of(columnMetadataA, Domain.singleValue(BIGINT, 23L)));
    ColumnMetadata columnMetadataB = new ColumnMetadata("b", BIGINT);
    TupleDomain tupleDomainB = TupleDomain.withColumnDomains(ImmutableMap.of(columnMetadataB, Domain.singleValue(BIGINT, 88L)));
    ColumnMetadata columnMetadataC = new ColumnMetadata("c", BIGINT);
    TupleDomain tupleDomainC = TupleDomain.withColumnDomains(ImmutableMap.of(columnMetadataC, Domain.singleValue(BIGINT, 66L)));
    // Adding entries into SplitCacheMap
    SplitCacheMap.getInstance().addCache(QualifiedName.of(CATALOG_NAME, schema, table), tupleDomainA, "a = 23");
    SplitCacheMap.getInstance().addCache(QualifiedName.of(CATALOG_NAME, schema, table2), tupleDomainB, "b = 88");
    SplitCacheMap.getInstance().addCache(QualifiedName.of(CATALOG_NAME, schema, table3), tupleDomainC, "b = 66");
    stateMachine = createQueryStateMachine("START TRANSACTION", testSession, transactionManager);
}
Also used : ColumnPropertyManager(io.prestosql.metadata.ColumnPropertyManager) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) TablePropertyManager(io.prestosql.metadata.TablePropertyManager) CatalogManager(io.prestosql.metadata.CatalogManager) TestingSession.createBogusTestingCatalog(io.prestosql.testing.TestingSession.createBogusTestingCatalog) Catalog(io.prestosql.metadata.Catalog) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with CatalogManager

use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.

the class TestSetRoleTask method setUp.

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

Example 8 with CatalogManager

use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.

the class TestCarbonAutoVacuum method testAutoVacuumDiffDB.

@Test
public void testAutoVacuumDiffDB() throws SQLException, InterruptedException {
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb2.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb3.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb4.autovacuumtable4");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable1(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable1 VALUES (10, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb2.autovacuumtable2(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb2.autovacuumtable2 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb2.autovacuumtable2 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb2.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("INSERT INTO carbontestdb2.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb3.autovacuumtable3 as select a, b from  carbontestdb2.autovacuumtable2 ");
    hetuServer.execute("CREATE TABLE carbontestdb4.autovacuumtable4(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb4.autovacuumtable4 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb4.autovacuumtable4 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb4.autovacuumtable4 VALUES (30, 12)");
    hetuServer.execute("INSERT INTO carbontestdb4.autovacuumtable4 VALUES (40, 13)");
    CatalogManager catalogManager = hetuServer.getCatalog();
    List<Catalog> catalogs = catalogManager.getCatalogs();
    Catalog catalog = null;
    for (Catalog catalog1 : catalogs) {
        if (catalog1.getConnectorCatalogName().getCatalogName().equals("carbondata")) {
            catalog = catalog1;
            break;
        }
    }
    Connector connector;
    ConnectorMetadata connectorMetadata = null;
    List<ConnectorVacuumTableInfo> tables = null;
    List<String> tablesNames = new ArrayList<>();
    try {
        CarbondataAutoVacuumThread.enableTracingVacuumTask(true);
        connector = catalog.getConnector(catalog.getConnectorCatalogName());
        connectorMetadata = connector.getConnectorMetadata();
        connectorMetadata.getTablesForVacuum();
    } catch (Exception e) {
        logger.debug(e.getMessage());
    }
    CarbondataAutoVacuumThread.waitForSubmittedVacuumTasksFinish();
    CarbondataAutoVacuumThread.enableTracingVacuumTask(false);
    tables = connectorMetadata.getTablesForVacuum();
    if (tables != null && 0 != tables.size()) {
        for (ConnectorVacuumTableInfo vacuumTable : tables) {
            tablesNames.add(vacuumTable.getSchemaTableName());
        }
    }
    assertTrue(tablesNames.contains("carbontestdb4.autovacuumtable4"));
    assertTrue(tablesNames.contains("carbontestdb2.autovacuumtable2"));
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb2.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb3.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb4.autovacuumtable4");
}
Also used : ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) Connector(io.prestosql.spi.connector.Connector) ArrayList(java.util.ArrayList) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) CatalogManager(io.prestosql.metadata.CatalogManager) Catalog(io.prestosql.metadata.Catalog) SQLException(java.sql.SQLException) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 9 with CatalogManager

use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.

the class TestAnalyzer method setup.

@BeforeClass
public void setup() {
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    transactionManager.beginTransaction(false);
    List<TransactionInfo> transactionInfos = transactionManager.getAllTransactionInfos();
    TransactionId transactionId = transactionInfos.get(0).getTransactionId();
    implicitConversionSession = testSessionBuilder().setCatalog(TPCH_CATALOG).setSchema("s1").setSystemProperty("implicit_conversion", "true").setTransactionId(transactionId).build();
    accessControl = new AccessControlManager(transactionManager);
    metadata = createTestMetadataManager(transactionManager, new FeaturesConfig());
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(APPLY_FUNCTION));
    Catalog tpchTestCatalog = createTestingCatalog(TPCH_CATALOG, TPCH_CATALOG_NAME);
    catalogManager.registerCatalog(tpchTestCatalog);
    metadata.getAnalyzePropertyManager().addProperties(TPCH_CATALOG_NAME, tpchTestCatalog.getConnector(TPCH_CATALOG_NAME).getAnalyzeProperties());
    catalogManager.registerCatalog(createTestingCatalog(SECOND_CATALOG, SECOND_CATALOG_NAME));
    catalogManager.registerCatalog(createTestingCatalog(THIRD_CATALOG, THIRD_CATALOG_NAME));
    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 for implicit conversion
    SchemaTableName table8 = new SchemaTableName("s1", "t8");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table8, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", INTEGER), new ColumnMetadata("c", SMALLINT), new ColumnMetadata("d", TINYINT), new ColumnMetadata("e", createDecimalType(10, 3)), new ColumnMetadata("f", REAL), new ColumnMetadata("g", DOUBLE), new ColumnMetadata("h", VARCHAR), new ColumnMetadata("i", VARBINARY), new ColumnMetadata("j", DATE), new ColumnMetadata("K", CharType.createCharType(3)))), false));
    // valid view referencing table in same schema
    ConnectorViewDefinition viewData1 = new ConnectorViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v1"), viewData1, false));
    // stale view (different column type)
    ConnectorViewDefinition viewData2 = new ConnectorViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", parseTypeSignature("varchar"))), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v2"), viewData2, false));
    // view referencing table in different schema from itself and session
    ConnectorViewDefinition viewData3 = new ConnectorViewDefinition("select a from t4", Optional.of(SECOND_CATALOG), Optional.of("s2"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("owner"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(THIRD_CATALOG, "s3", "v3"), viewData3, false));
    // valid view with uppercase column name
    ConnectorViewDefinition viewData4 = new ConnectorViewDefinition("select A from t1", Optional.of("tpch"), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName("tpch", "s1", "v4"), viewData4, false));
    // recursive view referencing to itself
    ConnectorViewDefinition viewData5 = new ConnectorViewDefinition("select * from v5", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v5"), viewData5, false));
}
Also used : AccessControlManager(io.prestosql.security.AccessControlManager) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ViewColumn(io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) CatalogManager(io.prestosql.metadata.CatalogManager) Catalog(io.prestosql.metadata.Catalog) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TransactionId(io.prestosql.transaction.TransactionId) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) ArrayType(io.prestosql.spi.type.ArrayType) TransactionInfo(io.prestosql.transaction.TransactionInfo) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with CatalogManager

use of io.prestosql.metadata.CatalogManager in project hetu-core by openlookeng.

the class TestAccessControlManager method testDenySystemAccessControl.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Access Denied: Cannot select from table secured_catalog.schema.table")
public void testDenySystemAccessControl() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
    TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
    accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
    registerBogusConnector(catalogManager, transactionManager, accessControlManager, "connector");
    accessControlManager.addCatalogAccessControl(new CatalogName("connector"), new DenyConnectorAccessControl());
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanSelectFromColumns(transactionId, new Identity(USER_NAME, Optional.of(PRINCIPAL)), new QualifiedObjectName("secured_catalog", "schema", "table"), ImmutableSet.of("column"));
    });
}
Also used : TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) CatalogName.createSystemTablesCatalogName(io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) Identity(io.prestosql.spi.security.Identity) CatalogManager(io.prestosql.metadata.CatalogManager) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

CatalogManager (io.prestosql.metadata.CatalogManager)14 Test (org.testng.annotations.Test)10 Catalog (io.prestosql.metadata.Catalog)5 Connector (io.prestosql.spi.connector.Connector)5 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)5 InMemoryTransactionManager.createTestTransactionManager (io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager)5 TransactionManager (io.prestosql.transaction.TransactionManager)5 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)4 InformationSchemaConnector (io.prestosql.connector.informationschema.InformationSchemaConnector)3 SystemConnector (io.prestosql.connector.system.SystemConnector)3 TpchConnectorFactory (io.prestosql.plugin.tpch.TpchConnectorFactory)3 CatalogName (io.prestosql.spi.connector.CatalogName)3 CatalogName.createInformationSchemaCatalogName (io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName)3 CatalogName.createSystemTablesCatalogName (io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName)3 ConnectorIdentity (io.prestosql.spi.security.ConnectorIdentity)3 Identity (io.prestosql.spi.security.Identity)3 TestingConnectorContext (io.prestosql.testing.TestingConnectorContext)3 Duration (io.airlift.units.Duration)2 ColumnPropertyManager (io.prestosql.metadata.ColumnPropertyManager)2 TablePropertyManager (io.prestosql.metadata.TablePropertyManager)2