Search in sources :

Example 21 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class ParquetTester method assertNonHiveWriterRoundTrip.

void assertNonHiveWriterRoundTrip(List<ObjectInspector> objectInspectors, Iterable<?>[] writeValues, Iterable<?>[] readValues, List<String> columnNames, List<Type> columnTypes, org.apache.parquet.schema.MessageType parquetSchema) throws Exception {
    for (WriterVersion version : versions) {
        for (CompressionCodecName compression : compressions) {
            org.apache.parquet.hadoop.metadata.CompressionCodecName compressionCodecName = org.apache.parquet.hadoop.metadata.CompressionCodecName.valueOf(compression.name());
            for (ConnectorSession session : sessions) {
                try (TempFile tempFile = new TempFile("test", "parquet")) {
                    JobConf jobConf = new JobConf();
                    jobConf.setEnum(COMPRESSION, compressionCodecName);
                    jobConf.setBoolean(ENABLE_DICTIONARY, true);
                    jobConf.setEnum(WRITER_VERSION, version);
                    nonHiveParquetWriter(jobConf, tempFile.getFile(), compressionCodecName, getStandardStructObjectInspector(columnNames, objectInspectors), getIterators(writeValues), parquetSchema);
                    assertFileContents(session, tempFile.getFile(), getIterators(readValues), columnNames, columnTypes);
                }
            }
        }
    }
}
Also used : CompressionCodecName(org.apache.parquet.hadoop.metadata.CompressionCodecName) CompressionCodecName(org.apache.parquet.hadoop.metadata.CompressionCodecName) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) JobConf(org.apache.hadoop.mapred.JobConf) WriterVersion(org.apache.parquet.column.ParquetProperties.WriterVersion)

Example 22 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class ParquetTester method assertMaxReadBytes.

void assertMaxReadBytes(List<ObjectInspector> objectInspectors, Iterable<?>[] writeValues, Iterable<?>[] readValues, List<String> columnNames, List<Type> columnTypes, Optional<MessageType> parquetSchema, DataSize maxReadBlockSize) throws Exception {
    WriterVersion version = PARQUET_1_0;
    CompressionCodecName compressionCodecName = UNCOMPRESSED;
    HiveClientConfig config = new HiveClientConfig().setHiveStorageFormat(HiveStorageFormat.PARQUET).setUseParquetColumnNames(false).setParquetMaxReadBlockSize(maxReadBlockSize);
    ConnectorSession session = new TestingConnectorSession(new HiveSessionProperties(config, new OrcFileWriterConfig(), new ParquetFileWriterConfig(), new CacheConfig()).getSessionProperties());
    try (TempFile tempFile = new TempFile("test", "parquet")) {
        JobConf jobConf = new JobConf();
        jobConf.setEnum(COMPRESSION, compressionCodecName);
        jobConf.setBoolean(ENABLE_DICTIONARY, true);
        jobConf.setEnum(WRITER_VERSION, version);
        writeParquetColumn(jobConf, tempFile.getFile(), compressionCodecName, createTableProperties(columnNames, objectInspectors), getStandardStructObjectInspector(columnNames, objectInspectors), getIterators(writeValues), parquetSchema, false);
        Iterator<?>[] expectedValues = getIterators(readValues);
        try (ConnectorPageSource pageSource = getFileFormat().createFileFormatReader(session, HDFS_ENVIRONMENT, tempFile.getFile(), columnNames, columnTypes)) {
            assertPageSource(columnTypes, expectedValues, pageSource, Optional.of(getParquetMaxReadBlockSize(session).toBytes()));
            assertFalse(stream(expectedValues).allMatch(Iterator::hasNext));
        }
    }
}
Also used : TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) OrcFileWriterConfig(com.facebook.presto.hive.OrcFileWriterConfig) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) HiveSessionProperties(com.facebook.presto.hive.HiveSessionProperties) WriterVersion(org.apache.parquet.column.ParquetProperties.WriterVersion) CompressionCodecName(org.apache.parquet.hadoop.metadata.CompressionCodecName) AbstractIterator(com.google.common.collect.AbstractIterator) Iterator(java.util.Iterator) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) CacheConfig(com.facebook.presto.cache.CacheConfig) JobConf(org.apache.hadoop.mapred.JobConf) ParquetFileWriterConfig(com.facebook.presto.hive.ParquetFileWriterConfig) HiveClientConfig(com.facebook.presto.hive.HiveClientConfig)

Example 23 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method listRoleGrants.

@Override
public Set<RoleGrant> listRoleGrants(Session session, String catalog, PrestoPrincipal principal) {
    Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog);
    if (!catalogMetadata.isPresent()) {
        return ImmutableSet.of();
    }
    ConnectorId connectorId = catalogMetadata.get().getConnectorId();
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(connectorId);
    return metadata.listRoleGrants(connectorSession, principal);
}
Also used : ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 24 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method getNewTableLayout.

@Override
public Optional<NewTableLayout> getNewTableLayout(Session session, String catalogName, ConnectorTableMetadata tableMetadata) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    return metadata.getNewTableLayout(connectorSession, tableMetadata).map(layout -> new NewTableLayout(connectorId, transactionHandle, layout));
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 25 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method listSchemaNames.

@Override
public List<String> listSchemaNames(Session session, String catalogName) {
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, catalogName);
    ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getConnectorId());
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            metadata.listSchemaNames(connectorSession).stream().map(schema -> schema.toLowerCase(Locale.ENGLISH)).forEach(schemaNames::add);
        }
    }
    return ImmutableList.copyOf(schemaNames.build());
}
Also used : NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) ComputedStatistics(com.facebook.presto.spi.statistics.ComputedStatistics) JsonCodecFactory(com.facebook.airlift.json.JsonCodecFactory) TypeSignature(com.facebook.presto.common.type.TypeSignature) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) SystemTable(com.facebook.presto.spi.SystemTable) ENGLISH(java.util.Locale.ENGLISH) HASH_CODE(com.facebook.presto.common.function.OperatorType.HASH_CODE) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TableStatisticsMetadata(com.facebook.presto.spi.statistics.TableStatisticsMetadata) Joiner(com.google.common.base.Joiner) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) Slice(io.airlift.slice.Slice) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OptionalLong(java.util.OptionalLong) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TableHandle(com.facebook.presto.spi.TableHandle) SqlFunction(com.facebook.presto.spi.function.SqlFunction) TransactionManager(com.facebook.presto.transaction.TransactionManager) LinkedHashSet(java.util.LinkedHashSet) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) SystemSessionProperties.isIgnoreStatsCalculatorFailures(com.facebook.presto.SystemSessionProperties.isIgnoreStatsCalculatorFailures) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) Session(com.facebook.presto.Session) Constraint(com.facebook.presto.spi.Constraint) OperatorType(com.facebook.presto.common.function.OperatorType) GREATER_THAN(com.facebook.presto.common.function.OperatorType.GREATER_THAN) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) BETWEEN(com.facebook.presto.common.function.OperatorType.BETWEEN) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) QueryId(com.facebook.presto.spi.QueryId) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) TableLayoutFilterCoverage(com.facebook.presto.spi.TableLayoutFilterCoverage) TableLayout.fromConnectorLayout(com.facebook.presto.metadata.TableLayout.fromConnectorLayout) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ConnectorCapabilities(com.facebook.presto.spi.connector.ConnectorCapabilities) JsonCodec(com.facebook.airlift.json.JsonCodec) TableStatistics(com.facebook.presto.spi.statistics.TableStatistics) Privilege(com.facebook.presto.spi.security.Privilege) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HashMultimap(com.google.common.collect.HashMultimap) Locale(java.util.Locale) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) LESS_THAN(com.facebook.presto.common.function.OperatorType.LESS_THAN) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) GET_LAYOUT_TIME_NANOS(com.facebook.presto.common.RuntimeMetricName.GET_LAYOUT_TIME_NANOS) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) String.format(java.lang.String.format) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) RoleGrant(com.facebook.presto.spi.security.RoleGrant) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Entry(java.util.Map.Entry) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) NOT_EQUAL(com.facebook.presto.common.function.OperatorType.NOT_EQUAL) Logger(com.facebook.airlift.log.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) HashMap(java.util.HashMap) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) LESS_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.LESS_THAN_OR_EQUAL) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Type(com.facebook.presto.common.type.Type) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) GrantInfo(com.facebook.presto.spi.security.GrantInfo) NOT_APPLICABLE(com.facebook.presto.spi.TableLayoutFilterCoverage.NOT_APPLICABLE) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) Constraint.alwaysTrue(com.facebook.presto.spi.Constraint.alwaysTrue) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) GREATER_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.GREATER_THAN_OR_EQUAL) MoreFutures.toListenableFuture(com.facebook.airlift.concurrent.MoreFutures.toListenableFuture) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) SYNTAX_ERROR(com.facebook.presto.spi.StandardErrorCode.SYNTAX_ERROR) ConnectorPartitioningMetadata(com.facebook.presto.spi.connector.ConnectorPartitioningMetadata) CatalogSchemaName(com.facebook.presto.common.CatalogSchemaName) MaterializedViewStatus(com.facebook.presto.spi.MaterializedViewStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorSession (com.facebook.presto.spi.ConnectorSession)189 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)94 ColumnHandle (com.facebook.presto.spi.ColumnHandle)91 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)80 List (java.util.List)79 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)78 SchemaTableName (com.facebook.presto.spi.SchemaTableName)74 Optional (java.util.Optional)73 ImmutableList (com.google.common.collect.ImmutableList)72 Objects.requireNonNull (java.util.Objects.requireNonNull)72 PrestoException (com.facebook.presto.spi.PrestoException)63 ImmutableMap (com.google.common.collect.ImmutableMap)63 Map (java.util.Map)63 Test (org.testng.annotations.Test)63 Path (org.apache.hadoop.fs.Path)61 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)53 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)53 Constraint (com.facebook.presto.spi.Constraint)51 Slice (io.airlift.slice.Slice)51 Type (com.facebook.presto.common.type.Type)50