Search in sources :

Example 1 with ConnectorMetadata

use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.

the class TestTransactionManager method testAbortedTransactionWorkflow.

@Test
public void testAbortedTransactionWorkflow() {
    try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
        CatalogManager catalogManager = new CatalogManager();
        TransactionManager transactionManager = InMemoryTransactionManager.create(new TransactionManagerConfig(), executor.getExecutor(), catalogManager, finishingExecutor);
        Connector c1 = new TpchConnectorFactory().create(CATALOG, ImmutableMap.of(), new TestingConnectorContext());
        registerConnector(catalogManager, transactionManager, CATALOG, CATALOG_NAME, c1);
        TransactionId transactionId = transactionManager.beginTransaction(false);
        assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
        TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertFalse(transactionInfo.isAutoCommitContext());
        assertTrue(transactionInfo.getCatalogNames().isEmpty());
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        ConnectorMetadata metadata = transactionManager.getOptionalCatalogMetadata(transactionId, CATALOG).get().getMetadata();
        metadata.listSchemaNames(TEST_SESSION.toConnectorSession(CATALOG_NAME));
        transactionInfo = transactionManager.getTransactionInfo(transactionId);
        assertEquals(transactionInfo.getCatalogNames(), ImmutableList.of(CATALOG_NAME, INFORMATION_SCHEMA_ID, SYSTEM_TABLES_ID));
        assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
        getFutureValue(transactionManager.asyncAbort(transactionId));
        assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    }
}
Also used : Connector(io.prestosql.spi.connector.Connector) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) SystemConnector(io.prestosql.connector.system.SystemConnector) TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) TestingConnectorContext(io.prestosql.testing.TestingConnectorContext) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) CatalogManager(io.prestosql.metadata.CatalogManager) Test(org.testng.annotations.Test)

Example 2 with ConnectorMetadata

use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.

the class TestCarbonAutoVacuum method testAutoVacuum.

@Test
public void testAutoVacuum() throws SQLException {
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable4");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable1(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable1 VALUES (10, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable2(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable2 VALUES (30, 11)");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable3 as select a, b from  carbontestdb1.autovacuumtable2 ");
    hetuServer.execute("CREATE TABLE carbontestdb1.autovacuumtable4(a int, b int)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (10, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (20, 11)");
    hetuServer.execute("INSERT INTO carbontestdb1.autovacuumtable4 VALUES (30, 12)");
    hetuServer.execute("INSERT INTO carbontestdb1.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;
    List<String> tablesNames = new ArrayList<>();
    try {
        CarbondataAutoVacuumThread.enableTracingVacuumTask(true);
        assertNotNull(catalog);
        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("carbontestdb1.autovacuumtable4"));
    assertTrue(tablesNames.contains("carbontestdb1.autovacuumtable2"));
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable1");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable2");
    hetuServer.execute("drop table if exists carbontestdb1.autovacuumtable3");
    hetuServer.execute("drop table if exists carbontestdb1.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 3 with ConnectorMetadata

use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.

the class TestHiveView method tesHiveView.

@Test(enabled = false)
public void tesHiveView() {
    SchemaTableName temporaryCreateView = temporaryTable("hive_view");
    String viewData = "test hive view";
    String expectedvViewData = "{\n" + "  \"originalSql\" : \"test hive view\",\n" + "  \"catalog\" : \"hive\",\n" + "  \"columns\" : [ {\n" + "    \"name\" : \"dummy\",\n" + "    \"type\" : \"varchar\"\n" + "  } ],\n" + "  \"owner\" : \"test\",\n" + "  \"runAsInvoker\" : false\n" + "}";
    String owner = "test";
    ConnectorSession session = newSession();
    HiveIdentity identity = new HiveIdentity(session);
    metastoreClient.createTable(identity, buildHiveView(temporaryCreateView, owner, viewData), buildInitialPrivilegeSet(owner));
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Optional<ConnectorViewDefinition> views = metadata.getView(newSession(), temporaryCreateView);
        assertEquals(views.get().getOriginalSql(), expectedvViewData);
        assertTrue(metadata.listViews(newSession(), Optional.of(temporaryCreateView.getSchemaName())).contains(temporaryCreateView));
    } finally {
        metastoreClient.dropTable(identity, temporaryCreateView.getSchemaName(), temporaryCreateView.getTableName(), true);
    }
}
Also used : ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 4 with ConnectorMetadata

use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.

the class MetadataManager method getTableProperties.

@Override
public TableProperties getTableProperties(Session session, TableHandle handle) {
    CatalogName catalogName = handle.getCatalogName();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    TableProperties tableProperties;
    ConcurrentHashMap<ConnectorTableHandle, TableProperties> tablePropertiesMap;
    String queryId = session.getQueryId().getId();
    if (metadata.usesLegacyTableLayouts()) {
        return handle.getLayout().map(layout -> new TableProperties(catalogName, handle.getTransaction(), new ConnectorTableProperties(metadata.getTableLayout(connectorSession, layout)))).orElseGet(() -> getLayout(session, handle, Constraint.alwaysTrue(), Optional.empty()).get().getTableProperties());
    }
    if (!handle.getConnectorHandle().isTablePropertiesCacheSupported()) {
        return new TableProperties(catalogName, handle.getTransaction(), metadata.getTableProperties(connectorSession, handle.getConnectorHandle()));
    }
    if (tablePropertiesQueryCache.get(queryId) != null && tablePropertiesQueryCache.get(queryId).get(handle.getConnectorHandle()) != null) {
        return tablePropertiesQueryCache.get(queryId).get(handle.getConnectorHandle());
    } else {
        tableProperties = new TableProperties(catalogName, handle.getTransaction(), metadata.getTableProperties(connectorSession, handle.getConnectorHandle()));
        if (tablePropertiesQueryCache.containsKey(queryId)) {
            tablePropertiesMap = tablePropertiesQueryCache.get(queryId);
        } else {
            tablePropertiesMap = new ConcurrentHashMap<>();
        }
        tablePropertiesMap.put(handle.getConnectorHandle(), tableProperties);
        tablePropertiesQueryCache.put(queryId, tablePropertiesMap);
    }
    return tableProperties;
}
Also used : TableStatistics(io.prestosql.spi.statistics.TableStatistics) PartialAndFinalAggregationType(io.prestosql.spi.PartialAndFinalAggregationType) LongSupplier(java.util.function.LongSupplier) RoleGrant(io.prestosql.spi.security.RoleGrant) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) LimitApplicationResult(io.prestosql.spi.connector.LimitApplicationResult) LESS_THAN(io.prestosql.spi.function.OperatorType.LESS_THAN) Collections.singletonList(java.util.Collections.singletonList) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) Map(java.util.Map) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableLayoutHandle(io.prestosql.spi.connector.ConnectorTableLayoutHandle) EQUAL(io.prestosql.spi.function.OperatorType.EQUAL) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) SystemTable(io.prestosql.spi.connector.SystemTable) GrantInfo(io.prestosql.spi.security.GrantInfo) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) Set(java.util.Set) GuardedBy(javax.annotation.concurrent.GuardedBy) Privilege(io.prestosql.spi.security.Privilege) BETWEEN(io.prestosql.spi.function.OperatorType.BETWEEN) LESS_THAN_OR_EQUAL(io.prestosql.spi.function.OperatorType.LESS_THAN_OR_EQUAL) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) Joiner(com.google.common.base.Joiner) Slice(io.airlift.slice.Slice) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) TransactionManager(io.prestosql.transaction.TransactionManager) ProjectionApplicationResult(io.prestosql.spi.connector.ProjectionApplicationResult) TypeNotFoundException(io.prestosql.spi.type.TypeNotFoundException) ComputedStatistics(io.prestosql.spi.statistics.ComputedStatistics) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) GREATER_THAN_OR_EQUAL(io.prestosql.spi.function.OperatorType.GREATER_THAN_OR_EQUAL) LinkedHashMap(java.util.LinkedHashMap) OptionalLong(java.util.OptionalLong) Session(io.prestosql.Session) ConnectorPartitioningHandle(io.prestosql.spi.connector.ConnectorPartitioningHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) LinkedHashSet(java.util.LinkedHashSet) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) MetadataUtil.toSchemaTableName(io.prestosql.metadata.MetadataUtil.toSchemaTableName) PartitioningHandle(io.prestosql.sql.planner.PartitioningHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) SYNTAX_ERROR(io.prestosql.spi.StandardErrorCode.SYNTAX_ERROR) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) DataCenterConnectorManager(io.prestosql.connector.DataCenterConnectorManager) Kryo(com.esotericsoftware.kryo.Kryo) MetadataUtil.convertFromSchemaTableName(io.prestosql.metadata.MetadataUtil.convertFromSchemaTableName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Locale(java.util.Locale) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) SqlFunction(io.prestosql.spi.function.SqlFunction) ConnectorTableLayoutResult(io.prestosql.spi.connector.ConnectorTableLayoutResult) Constraint(io.prestosql.spi.connector.Constraint) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) CatalogName(io.prestosql.spi.connector.CatalogName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConnectorResolvedIndex(io.prestosql.spi.connector.ConnectorResolvedIndex) SampleType(io.prestosql.spi.connector.SampleType) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Entry(java.util.Map.Entry) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) ConnectorExpression(io.prestosql.spi.expression.ConnectorExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) HASH_CODE(io.prestosql.spi.function.OperatorType.HASH_CODE) ConnectorCapabilities(io.prestosql.spi.connector.ConnectorCapabilities) ConnectorOutputMetadata(io.prestosql.spi.connector.ConnectorOutputMetadata) NOT_EQUAL(io.prestosql.spi.function.OperatorType.NOT_EQUAL) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) NOT_FOUND(io.prestosql.spi.StandardErrorCode.NOT_FOUND) TableHandle(io.prestosql.spi.metadata.TableHandle) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) ViewColumn(io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn) Objects.requireNonNull(java.util.Objects.requireNonNull) GREATER_THAN(io.prestosql.spi.function.OperatorType.GREATER_THAN) QueryId(io.prestosql.spi.QueryId) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ConnectorTableLayout(io.prestosql.spi.connector.ConnectorTableLayout) INVALID_VIEW(io.prestosql.spi.StandardErrorCode.INVALID_VIEW) Provider(com.google.inject.Provider) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle)

Example 5 with ConnectorMetadata

use of io.prestosql.spi.connector.ConnectorMetadata in project hetu-core by openlookeng.

the class MetadataManager method applyFilter.

@Override
public Optional<ConstraintApplicationResult<TableHandle>> applyFilter(Session session, TableHandle table, Constraint constraint, List<Constraint> disjunctConstraints, Set<ColumnHandle> allColumnHandles, boolean pushPartitionsOnly) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    if (metadata.usesLegacyTableLayouts()) {
        return Optional.empty();
    }
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyFilter(connectorSession, table.getConnectorHandle(), constraint, disjunctConstraints, allColumnHandles, pushPartitionsOnly).map(result -> new ConstraintApplicationResult<>(new TableHandle(catalogName, result.getHandle(), table.getTransaction(), Optional.empty()), result.getRemainingFilter()));
}
Also used : CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Aggregations

ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)163 CatalogName (io.prestosql.spi.connector.CatalogName)80 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)77 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)60 Test (org.testng.annotations.Test)58 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)48 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)35 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)29 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)29 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)28 ConnectorOutputTableHandle (io.prestosql.spi.connector.ConnectorOutputTableHandle)27 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)23 HiveColumnHandle.bucketColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle)22 MaterializedResult (io.prestosql.testing.MaterializedResult)21 PrestoException (io.prestosql.spi.PrestoException)20 Constraint (io.prestosql.spi.connector.Constraint)20 Slice (io.airlift.slice.Slice)18 ConnectorDeleteAsInsertTableHandle (io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle)18 ConnectorTransactionHandle (io.prestosql.spi.connector.ConnectorTransactionHandle)18 ConnectorUpdateTableHandle (io.prestosql.spi.connector.ConnectorUpdateTableHandle)17