Search in sources :

Example 1 with ConnectorTransactionHandle

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

the class TpcdsConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : NodeManager(io.prestosql.spi.NodeManager) Connector(io.prestosql.spi.connector.Connector) IsolationLevel(io.prestosql.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle)

Example 2 with ConnectorTransactionHandle

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

the class IndexedTpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    TpchIndexedData indexedData = new TpchIndexedData(indexSpec);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
            return new TpchIndexMetadata(indexedData);
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpchRecordSetProvider();
        }

        @Override
        public ConnectorIndexProvider getIndexProvider() {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables() {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(io.prestosql.spi.connector.Connector) IsolationLevel(io.prestosql.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) TpchSplitManager(io.prestosql.plugin.tpch.TpchSplitManager) NodeManager(io.prestosql.spi.NodeManager) TpchNodePartitioningProvider(io.prestosql.plugin.tpch.TpchNodePartitioningProvider) SystemTable(io.prestosql.spi.connector.SystemTable) TpchRecordSetProvider(io.prestosql.plugin.tpch.TpchRecordSetProvider)

Example 3 with ConnectorTransactionHandle

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

the class CarbondataPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<ColumnHandle> columns) {
    HiveSplit carbonSplit = Types.checkType(((HiveSplitWrapper) (split)).getSplits().get(0), HiveSplit.class, "split is not class HiveSplit");
    this.queryId = carbonSplit.getSchema().getProperty("queryId");
    if (this.queryId == null) {
        // Fall back to hive pagesource.
        return super.createPageSource(transactionHandle, session, split, table, columns);
    }
    try {
        hdfsEnvironment.getFileSystem(new HdfsEnvironment.HdfsContext(session, carbonSplit.getDatabase()), new Path(carbonSplit.getSchema().getProperty("tablePath")));
    } catch (IOException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, "Failed to get file system: " + e.getMessage());
    }
    return hdfsEnvironment.doAs(session.getUser(), () -> {
        Configuration configuration = this.hdfsEnvironment.getConfiguration(new HdfsEnvironment.HdfsContext(session, carbonSplit.getDatabase(), carbonSplit.getTable()), new Path(carbonSplit.getSchema().getProperty("tablePath")));
        CarbonTable carbonTable = getCarbonTable(carbonSplit, configuration);
        /* So that CarbonTLS can access it */
        ThreadLocalSessionInfo.setConfigurationToCurrentThread(configuration);
        boolean isFullACID = isFullAcidTable(Maps.fromProperties(carbonSplit.getSchema()));
        boolean isDirectVectorFill = (carbonTableReader.config.getPushRowFilter() == null) || carbonTableReader.config.getPushRowFilter().equalsIgnoreCase("false") || columns.stream().anyMatch(c -> c.getColumnName().equalsIgnoreCase(CarbonCommonConstants.CARBON_IMPLICIT_COLUMN_TUPLEID));
        return new CarbondataPageSource(carbonTable, queryId, carbonSplit, columns, table, configuration, isDirectVectorFill, isFullACID, session.getUser(), hdfsEnvironment);
    });
}
Also used : Path(org.apache.hadoop.fs.Path) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) HiveSplitWrapper(io.prestosql.plugin.hive.HiveSplitWrapper) ConnectorSplit(io.prestosql.spi.connector.ConnectorSplit) Inject(com.google.inject.Inject) CarbondataTableReader(io.hetu.core.plugin.carbondata.impl.CarbondataTableReader) CarbonCommonConstants(org.apache.carbondata.core.constants.CarbonCommonConstants) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ThreadLocalSessionInfo(org.apache.carbondata.core.util.ThreadLocalSessionInfo) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) HiveConfig(io.prestosql.plugin.hive.HiveConfig) Configuration(org.apache.hadoop.conf.Configuration) Objects.requireNonNull(java.util.Objects.requireNonNull) DynamicFilterSupplier(io.prestosql.spi.dynamicfilter.DynamicFilterSupplier) Path(org.apache.hadoop.fs.Path) HivePageSourceFactory(io.prestosql.plugin.hive.HivePageSourceFactory) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) PrestoException(io.prestosql.spi.PrestoException) AcidUtils.isFullAcidTable(org.apache.hadoop.hive.ql.io.AcidUtils.isFullAcidTable) HivePageSourceProvider(io.prestosql.plugin.hive.HivePageSourceProvider) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TypeManager(io.prestosql.spi.type.TypeManager) Set(java.util.Set) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) CarbondataTableCacheModel(io.hetu.core.plugin.carbondata.impl.CarbondataTableCacheModel) HiveSplit(io.prestosql.plugin.hive.HiveSplit) List(java.util.List) ConnectorPageSource(io.prestosql.spi.connector.ConnectorPageSource) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) HiveRecordCursorProvider(io.prestosql.plugin.hive.HiveRecordCursorProvider) HiveSplit(io.prestosql.plugin.hive.HiveSplit) Configuration(org.apache.hadoop.conf.Configuration) HiveSplitWrapper(io.prestosql.plugin.hive.HiveSplitWrapper) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment)

Example 4 with ConnectorTransactionHandle

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

the class TableCommentSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Session session = toSession(transactionHandle, connectorSession);
    Builder table = InMemoryRecordSet.builder(COMMENT_TABLE);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
        Set<SchemaTableName> names = ImmutableSet.of();
        try {
            names = listTables(session, metadata, accessControl, prefix);
        } catch (PrestoException e) {
            // listTables throws an exception if cannot connect the database
            LOG.debug(e, "Failed to get tables for catalog: %s", catalog);
        }
        for (SchemaTableName name : names) {
            QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), name.getSchemaName(), name.getTableName());
            Optional<String> comment = Optional.empty();
            try {
                comment = metadata.getTableHandle(session, tableName).map(handle -> metadata.getTableMetadata(session, handle)).map(metadata -> metadata.getMetadata().getComment()).get();
            } catch (PrestoException e) {
                // getTableHandle may throw an exception (e.g. Cassandra connector doesn't allow case insensitive column names)
                LOG.debug(e, "Failed to get metadata for table: %s", name);
            }
            table.addRow(prefix.getCatalogName(), name.getSchemaName(), name.getTableName(), comment.orElse(null));
        }
    }
    return table.build().cursor();
}
Also used : FilterUtil.tablePrefix(io.prestosql.connector.system.jdbc.FilterUtil.tablePrefix) MetadataListing.listTables(io.prestosql.metadata.MetadataListing.listTables) Logger(io.airlift.log.Logger) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) SINGLE_COORDINATOR(io.prestosql.spi.connector.SystemTable.Distribution.SINGLE_COORDINATOR) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) Inject(javax.inject.Inject) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) MetadataListing.listCatalogs(io.prestosql.metadata.MetadataListing.listCatalogs) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) FilterUtil.stringFilter(io.prestosql.connector.system.jdbc.FilterUtil.stringFilter) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RecordCursor(io.prestosql.spi.connector.RecordCursor) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) AccessControl(io.prestosql.security.AccessControl) SystemTable(io.prestosql.spi.connector.SystemTable) TupleDomain(io.prestosql.spi.predicate.TupleDomain) SystemConnectorSessionUtil.toSession(io.prestosql.connector.system.SystemConnectorSessionUtil.toSession) Set(java.util.Set) Metadata(io.prestosql.metadata.Metadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) FilterUtil.filter(io.prestosql.connector.system.jdbc.FilterUtil.filter) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) Builder(io.prestosql.spi.connector.InMemoryRecordSet.Builder) TableMetadataBuilder.tableMetadataBuilder(io.prestosql.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) SystemConnectorSessionUtil.toSession(io.prestosql.connector.system.SystemConnectorSessionUtil.toSession)

Example 5 with ConnectorTransactionHandle

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

the class TestHBase method testRollbackTransaction.

/**
 * testRollbackTransaction
 */
@Test
public void testRollbackTransaction() {
    ConnectorTransactionHandle transactionHandle = hConnector.beginTransaction(IsolationLevel.READ_COMMITTED, true);
    hConnector.getMetadata(transactionHandle);
    hConnector.rollback(transactionHandle);
}
Also used : ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTransactionHandle (io.prestosql.spi.connector.ConnectorTransactionHandle)30 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)12 CatalogName (io.prestosql.spi.connector.CatalogName)11 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)10 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)9 Optional (java.util.Optional)9 Objects.requireNonNull (java.util.Objects.requireNonNull)8 List (java.util.List)7 ImmutableList (com.google.common.collect.ImmutableList)6 PrestoException (io.prestosql.spi.PrestoException)6 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)6 TupleDomain (io.prestosql.spi.predicate.TupleDomain)6 Inject (javax.inject.Inject)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Connector (io.prestosql.spi.connector.Connector)5 NodeManager (io.prestosql.spi.NodeManager)4 GENERIC_INTERNAL_ERROR (io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR)4 ConnectorDeleteAsInsertTableHandle (io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle)4 ConnectorSplitSource (io.prestosql.spi.connector.ConnectorSplitSource)4 RecordSet (io.prestosql.spi.connector.RecordSet)4