Search in sources :

Example 11 with ConnectorSession

use of io.prestosql.spi.connector.ConnectorSession 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 12 with ConnectorSession

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

the class TestHiveWriterFactory method testSortingPath.

@Test
public void testSortingPath() {
    setUp();
    String targetPath = "/tmp";
    String writePath = "/tmp/table";
    Optional<WriteIdInfo> writeIdInfo = Optional.of(new WriteIdInfo(1, 1, 0));
    StorageFormat storageFormat = StorageFormat.fromHiveStorageFormat(ORC);
    Storage storage = new Storage(storageFormat, "", Optional.empty(), false, ImmutableMap.of());
    Table table = new Table("schema", "table", "user", "MANAGED_TABLE", storage, ImmutableList.of(new Column("col_1", HiveType.HIVE_INT, Optional.empty())), ImmutableList.of(), ImmutableMap.of("transactional", "true"), Optional.of("original"), Optional.of("expanded"));
    HiveConfig hiveConfig = getHiveConfig();
    HivePageSinkMetadata hivePageSinkMetadata = new HivePageSinkMetadata(new SchemaTableName("schema", "table"), Optional.of(table), ImmutableMap.of());
    PageSorter pageSorter = new PagesIndexPageSorter(new PagesIndex.TestingFactory(false));
    Metadata metadata = createTestMetadataManager();
    TypeManager typeManager = new InternalTypeManager(metadata.getFunctionAndTypeManager());
    HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationInitializer(hiveConfig), ImmutableSet.of());
    HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveConfig, new NoHdfsAuthentication());
    LocationService locationService = new HiveLocationService(hdfsEnvironment);
    ConnectorSession session = newSession();
    HiveWriterFactory hiveWriterFactory = new HiveWriterFactory(getDefaultHiveFileWriterFactories(hiveConfig), "schema", "table", false, HiveACIDWriteType.DELETE, ImmutableList.of(new HiveColumnHandle("col_1", HiveType.HIVE_INT, new TypeSignature("integer", ImmutableList.of()), 0, HiveColumnHandle.ColumnType.REGULAR, Optional.empty())), ORC, ORC, ImmutableMap.of(), OptionalInt.empty(), ImmutableList.of(), new LocationHandle(targetPath, writePath, false, LocationHandle.WriteMode.STAGE_AND_MOVE_TO_TARGET_DIRECTORY, writeIdInfo), locationService, session.getQueryId(), new HivePageSinkMetadataProvider(hivePageSinkMetadata, CachingHiveMetastore.memoizeMetastore(metastore, 1000), new HiveIdentity(session)), typeManager, hdfsEnvironment, pageSorter, hiveConfig.getWriterSortBufferSize(), hiveConfig.getMaxOpenSortFiles(), false, UTC, session, new TestingNodeManager("fake-environment"), new HiveEventClient(), new HiveSessionProperties(hiveConfig, new OrcFileWriterConfig(), new ParquetFileWriterConfig()), new HiveWriterStats(), getDefaultOrcFileWriterFactory(hiveConfig));
    HiveWriter hiveWriter = hiveWriterFactory.createWriter(ImmutableList.of(), OptionalInt.empty(), Optional.empty());
    assertEquals(((SortingFileWriter) hiveWriter.getFileWriter()).getTempFilePrefix().getName(), ".tmp-sort.bucket_00000");
}
Also used : HivePageSinkMetadataProvider(io.prestosql.plugin.hive.metastore.HivePageSinkMetadataProvider) HivePageSinkMetadata(io.prestosql.plugin.hive.metastore.HivePageSinkMetadata) Metadata(io.prestosql.metadata.Metadata) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) PagesIndex(io.prestosql.operator.PagesIndex) NoHdfsAuthentication(io.prestosql.plugin.hive.authentication.NoHdfsAuthentication) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) PagesIndexPageSorter(io.prestosql.PagesIndexPageSorter) TypeSignature(io.prestosql.spi.type.TypeSignature) Column(io.prestosql.plugin.hive.metastore.Column) TestingNodeManager(io.prestosql.testing.TestingNodeManager) PagesIndexPageSorter(io.prestosql.PagesIndexPageSorter) PageSorter(io.prestosql.spi.PageSorter) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) TestingConnectorSession(io.prestosql.testing.TestingConnectorSession) InternalTypeManager(io.prestosql.type.InternalTypeManager) Table(io.prestosql.plugin.hive.metastore.Table) HivePageSinkMetadata(io.prestosql.plugin.hive.metastore.HivePageSinkMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Storage(io.prestosql.plugin.hive.metastore.Storage) InternalTypeManager(io.prestosql.type.InternalTypeManager) TypeManager(io.prestosql.spi.type.TypeManager) Test(org.testng.annotations.Test)

Example 13 with ConnectorSession

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

the class TestSemiTransactionalHiveMetastore method testIsCollectColumnStatisticsOnWriteFalse.

@Test
public void testIsCollectColumnStatisticsOnWriteFalse() {
    ConnectorSession session = newSession(ImmutableMap.of("collect_column_statistics_on_write", false));
    assertEquals(STATISTICS_2, skipStats(STATISTICS_1, STATISTICS_2, HiveSessionProperties.isCollectColumnStatisticsOnWrite(session)));
}
Also used : ConnectorSession(io.prestosql.spi.connector.ConnectorSession) TestingConnectorSession(io.prestosql.testing.TestingConnectorSession) Test(org.testng.annotations.Test)

Example 14 with ConnectorSession

use of io.prestosql.spi.connector.ConnectorSession 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 15 with ConnectorSession

use of io.prestosql.spi.connector.ConnectorSession 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

ConnectorSession (io.prestosql.spi.connector.ConnectorSession)267 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)160 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)159 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)130 Test (org.testng.annotations.Test)115 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)107 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)98 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)90 PrestoException (io.prestosql.spi.PrestoException)83 TupleDomain (io.prestosql.spi.predicate.TupleDomain)83 List (java.util.List)82 ImmutableList (com.google.common.collect.ImmutableList)80 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)79 Optional (java.util.Optional)78 Objects.requireNonNull (java.util.Objects.requireNonNull)74 Path (org.apache.hadoop.fs.Path)74 Slice (io.airlift.slice.Slice)72 ImmutableMap (com.google.common.collect.ImmutableMap)67 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)65 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)65