Search in sources :

Example 21 with Table

use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.

the class HiveMetadata method getNewTableLayout.

@Override
public Optional<ConnectorNewTableLayout> getNewTableLayout(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
    Optional<HiveBucketProperty> bucketProperty = getBucketProperty(tableMetadata.getProperties());
    if (!bucketProperty.isPresent()) {
        return Optional.empty();
    }
    if (!bucketWritingEnabled) {
        throw new PrestoException(NOT_SUPPORTED, "Writing to bucketed Hive table has been temporarily disabled");
    }
    List<String> bucketedBy = bucketProperty.get().getBucketedBy();
    Map<String, HiveType> hiveTypeMap = tableMetadata.getColumns().stream().collect(toMap(ColumnMetadata::getName, column -> toHiveType(typeTranslator, column.getType())));
    return Optional.of(new ConnectorNewTableLayout(new HivePartitioningHandle(connectorId, bucketProperty.get().getBucketCount(), bucketedBy.stream().map(hiveTypeMap::get).collect(toList())), bucketedBy));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) TypeManager(com.facebook.presto.spi.type.TypeManager) HiveTableProperties.getPartitionedBy(com.facebook.presto.hive.HiveTableProperties.getPartitionedBy) Map(java.util.Map) INVALID_TABLE_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) HivePartitionManager.extractPartitionKeyValues(com.facebook.presto.hive.HivePartitionManager.extractPartitionKeyValues) WriteMode(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode) Verify(com.google.common.base.Verify) StorageFormat(com.facebook.presto.hive.metastore.StorageFormat) HIVE_INVALID_METADATA(com.facebook.presto.hive.HiveErrorCode.HIVE_INVALID_METADATA) PrincipalPrivileges(com.facebook.presto.hive.metastore.PrincipalPrivileges) PATH_COLUMN_NAME(com.facebook.presto.hive.HiveColumnHandle.PATH_COLUMN_NAME) Set(java.util.Set) HivePrivilegeInfo.toHivePrivilege(com.facebook.presto.hive.metastore.HivePrivilegeInfo.toHivePrivilege) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Domain(com.facebook.presto.spi.predicate.Domain) HiveColumnHandle.updateRowIdHandle(com.facebook.presto.hive.HiveColumnHandle.updateRowIdHandle) HivePrivilegeInfo(com.facebook.presto.hive.metastore.HivePrivilegeInfo) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Iterables(com.google.common.collect.Iterables) Table(com.facebook.presto.hive.metastore.Table) Slice(io.airlift.slice.Slice) Database(com.facebook.presto.hive.metastore.Database) REGULAR(com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR) BUCKET_COLUMN_NAME(com.facebook.presto.hive.HiveColumnHandle.BUCKET_COLUMN_NAME) HiveUtil.columnExtraInfo(com.facebook.presto.hive.HiveUtil.columnExtraInfo) HiveTableProperties.getBucketProperty(com.facebook.presto.hive.HiveTableProperties.getBucketProperty) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) DIRECT_TO_TARGET_EXISTING_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.DIRECT_TO_TARGET_EXISTING_DIRECTORY) Type(com.facebook.presto.spi.type.Type) HiveUtil.encodeViewData(com.facebook.presto.hive.HiveUtil.encodeViewData) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) HiveTableProperties.getHiveStorageFormat(com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat) HiveWriteUtils.checkTableIsWritable(com.facebook.presto.hive.HiveWriteUtils.checkTableIsWritable) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) PRESTO_VIEW_FLAG(com.facebook.presto.hive.HiveUtil.PRESTO_VIEW_FLAG) Properties(java.util.Properties) HiveWriteUtils.initializeSerializer(com.facebook.presto.hive.HiveWriteUtils.initializeSerializer) HIVE_CONCURRENT_MODIFICATION_DETECTED(com.facebook.presto.hive.HiveErrorCode.HIVE_CONCURRENT_MODIFICATION_DETECTED) Constraint(com.facebook.presto.spi.Constraint) IOException(java.io.IOException) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) HivePrivilege(com.facebook.presto.hive.metastore.HivePrivilegeInfo.HivePrivilege) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) TableType(org.apache.hadoop.hive.metastore.TableType) HiveUtil.hiveColumnHandles(com.facebook.presto.hive.HiveUtil.hiveColumnHandles) DIRECT_TO_TARGET_NEW_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.DIRECT_TO_TARGET_NEW_DIRECTORY) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ViewNotFoundException(com.facebook.presto.spi.ViewNotFoundException) HiveTableProperties.getExternalLocation(com.facebook.presto.hive.HiveTableProperties.getExternalLocation) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) HiveType.toHiveType(com.facebook.presto.hive.HiveType.toHiveType) STAGE_AND_MOVE_TO_TARGET_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.STAGE_AND_MOVE_TO_TARGET_DIRECTORY) Privilege(com.facebook.presto.spi.security.Privilege) FileSinkOperator(org.apache.hadoop.hive.ql.exec.FileSinkOperator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HiveSessionProperties.isBucketExecutionEnabled(com.facebook.presto.hive.HiveSessionProperties.isBucketExecutionEnabled) Collectors.toMap(java.util.stream.Collectors.toMap) Iterables.concat(com.google.common.collect.Iterables.concat) HIVE_COLUMN_ORDER_MISMATCH(com.facebook.presto.hive.HiveErrorCode.HIVE_COLUMN_ORDER_MISMATCH) BUCKETED_BY_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKETED_BY_PROPERTY) Path(org.apache.hadoop.fs.Path) DiscretePredicates(com.facebook.presto.spi.DiscretePredicates) NullableValue(com.facebook.presto.spi.predicate.NullableValue) Collectors.toSet(java.util.stream.Collectors.toSet) HIVE_UNSUPPORTED_FORMAT(com.facebook.presto.hive.HiveErrorCode.HIVE_UNSUPPORTED_FORMAT) ImmutableSet(com.google.common.collect.ImmutableSet) HIVE_UNKNOWN_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_UNKNOWN_ERROR) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) INVALID_SCHEMA_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) SCHEMA_NOT_EMPTY(com.facebook.presto.spi.StandardErrorCode.SCHEMA_NOT_EMPTY) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) STORAGE_FORMAT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.STORAGE_FORMAT_PROPERTY) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) HIVE_STRING(com.facebook.presto.hive.HiveType.HIVE_STRING) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) USER(com.facebook.presto.hive.metastore.PrincipalType.USER) Optional(java.util.Optional) HIVE_TIMEZONE_MISMATCH(com.facebook.presto.hive.HiveErrorCode.HIVE_TIMEZONE_MISMATCH) PARTITION_KEY(com.facebook.presto.hive.HiveColumnHandle.ColumnType.PARTITION_KEY) HiveUtil.schemaTableName(com.facebook.presto.hive.HiveUtil.schemaTableName) HIDDEN(com.facebook.presto.hive.HiveColumnHandle.ColumnType.HIDDEN) JsonCodec(io.airlift.json.JsonCodec) TupleDomain.withColumnDomains(com.facebook.presto.spi.predicate.TupleDomain.withColumnDomains) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Column(com.facebook.presto.hive.metastore.Column) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) HIVE_WRITER_CLOSE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_CLOSE_ERROR) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) Partition(com.facebook.presto.hive.metastore.Partition) ImmutableList(com.google.common.collect.ImmutableList) PARTITIONED_BY_PROPERTY(com.facebook.presto.hive.HiveTableProperties.PARTITIONED_BY_PROPERTY) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) HiveUtil.toPartitionValues(com.facebook.presto.hive.HiveUtil.toPartitionValues) HiveWriteUtils.isWritableType(com.facebook.presto.hive.HiveWriteUtils.isWritableType) ConnectorNodePartitioning(com.facebook.presto.spi.ConnectorNodePartitioning) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) EXTERNAL_LOCATION_PROPERTY(com.facebook.presto.hive.HiveTableProperties.EXTERNAL_LOCATION_PROPERTY) VIEW_STORAGE_FORMAT(com.facebook.presto.hive.metastore.StorageFormat.VIEW_STORAGE_FORMAT) Maps(com.google.common.collect.Maps) JobConf(org.apache.hadoop.mapred.JobConf) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) BUCKET_COUNT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKET_COUNT_PROPERTY) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) HiveUtil.decodeViewData(com.facebook.presto.hive.HiveUtil.decodeViewData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MetastoreUtil.getHiveSchema(com.facebook.presto.hive.metastore.MetastoreUtil.getHiveSchema) PrestoException(com.facebook.presto.spi.PrestoException) HiveType.toHiveType(com.facebook.presto.hive.HiveType.toHiveType) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout)

Example 22 with Table

use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.

the class HiveMetadata method getViews.

@Override
public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, ConnectorViewDefinition> views = ImmutableMap.builder();
    List<SchemaTableName> tableNames;
    if (prefix.getTableName() != null) {
        tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
    } else {
        tableNames = listViews(session, prefix.getSchemaName());
    }
    for (SchemaTableName schemaTableName : tableNames) {
        Optional<Table> table = metastore.getTable(schemaTableName.getSchemaName(), schemaTableName.getTableName());
        if (table.isPresent() && HiveUtil.isPrestoView(table.get())) {
            views.put(schemaTableName, new ConnectorViewDefinition(schemaTableName, Optional.ofNullable(table.get().getOwner()), decodeViewData(table.get().getViewOriginalText().get())));
        }
    }
    return views.build();
}
Also used : Table(com.facebook.presto.hive.metastore.Table) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition)

Example 23 with Table

use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.

the class HiveMetadata method columnMetadataGetter.

private static Function<HiveColumnHandle, ColumnMetadata> columnMetadataGetter(Table table, TypeManager typeManager) {
    ImmutableList.Builder<String> columnNames = ImmutableList.builder();
    table.getPartitionColumns().stream().map(Column::getName).forEach(columnNames::add);
    table.getDataColumns().stream().map(Column::getName).forEach(columnNames::add);
    List<String> allColumnNames = columnNames.build();
    if (allColumnNames.size() > Sets.newHashSet(allColumnNames).size()) {
        throw new PrestoException(HIVE_INVALID_METADATA, format("Hive metadata for table %s is invalid: Table descriptor contains duplicate columns", table.getTableName()));
    }
    List<Column> tableColumns = table.getDataColumns();
    ImmutableMap.Builder<String, Optional<String>> builder = ImmutableMap.builder();
    for (Column field : concat(tableColumns, table.getPartitionColumns())) {
        if ((field.getComment() != null) && !Optional.of("from deserializer").equals(field.getComment())) {
            builder.put(field.getName(), field.getComment());
        } else {
            builder.put(field.getName(), Optional.empty());
        }
    }
    // add hidden columns
    builder.put(PATH_COLUMN_NAME, Optional.empty());
    if (table.getStorage().getBucketProperty().isPresent()) {
        builder.put(BUCKET_COLUMN_NAME, Optional.empty());
    }
    Map<String, Optional<String>> columnComment = builder.build();
    return handle -> new ColumnMetadata(handle.getName(), typeManager.getType(handle.getTypeSignature()), columnComment.get(handle.getName()).orElse(null), columnExtraInfo(handle.isPartitionKey()), handle.isHidden());
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) TypeManager(com.facebook.presto.spi.type.TypeManager) HiveTableProperties.getPartitionedBy(com.facebook.presto.hive.HiveTableProperties.getPartitionedBy) Map(java.util.Map) INVALID_TABLE_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) HivePartitionManager.extractPartitionKeyValues(com.facebook.presto.hive.HivePartitionManager.extractPartitionKeyValues) WriteMode(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode) Verify(com.google.common.base.Verify) StorageFormat(com.facebook.presto.hive.metastore.StorageFormat) HIVE_INVALID_METADATA(com.facebook.presto.hive.HiveErrorCode.HIVE_INVALID_METADATA) PrincipalPrivileges(com.facebook.presto.hive.metastore.PrincipalPrivileges) PATH_COLUMN_NAME(com.facebook.presto.hive.HiveColumnHandle.PATH_COLUMN_NAME) Set(java.util.Set) HivePrivilegeInfo.toHivePrivilege(com.facebook.presto.hive.metastore.HivePrivilegeInfo.toHivePrivilege) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Domain(com.facebook.presto.spi.predicate.Domain) HiveColumnHandle.updateRowIdHandle(com.facebook.presto.hive.HiveColumnHandle.updateRowIdHandle) HivePrivilegeInfo(com.facebook.presto.hive.metastore.HivePrivilegeInfo) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Iterables(com.google.common.collect.Iterables) Table(com.facebook.presto.hive.metastore.Table) Slice(io.airlift.slice.Slice) Database(com.facebook.presto.hive.metastore.Database) REGULAR(com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR) BUCKET_COLUMN_NAME(com.facebook.presto.hive.HiveColumnHandle.BUCKET_COLUMN_NAME) HiveUtil.columnExtraInfo(com.facebook.presto.hive.HiveUtil.columnExtraInfo) HiveTableProperties.getBucketProperty(com.facebook.presto.hive.HiveTableProperties.getBucketProperty) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) DIRECT_TO_TARGET_EXISTING_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.DIRECT_TO_TARGET_EXISTING_DIRECTORY) Type(com.facebook.presto.spi.type.Type) HiveUtil.encodeViewData(com.facebook.presto.hive.HiveUtil.encodeViewData) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) HiveTableProperties.getHiveStorageFormat(com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat) HiveWriteUtils.checkTableIsWritable(com.facebook.presto.hive.HiveWriteUtils.checkTableIsWritable) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) PRESTO_VIEW_FLAG(com.facebook.presto.hive.HiveUtil.PRESTO_VIEW_FLAG) Properties(java.util.Properties) HiveWriteUtils.initializeSerializer(com.facebook.presto.hive.HiveWriteUtils.initializeSerializer) HIVE_CONCURRENT_MODIFICATION_DETECTED(com.facebook.presto.hive.HiveErrorCode.HIVE_CONCURRENT_MODIFICATION_DETECTED) Constraint(com.facebook.presto.spi.Constraint) IOException(java.io.IOException) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) HivePrivilege(com.facebook.presto.hive.metastore.HivePrivilegeInfo.HivePrivilege) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) TableType(org.apache.hadoop.hive.metastore.TableType) HiveUtil.hiveColumnHandles(com.facebook.presto.hive.HiveUtil.hiveColumnHandles) DIRECT_TO_TARGET_NEW_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.DIRECT_TO_TARGET_NEW_DIRECTORY) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ViewNotFoundException(com.facebook.presto.spi.ViewNotFoundException) HiveTableProperties.getExternalLocation(com.facebook.presto.hive.HiveTableProperties.getExternalLocation) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) HiveType.toHiveType(com.facebook.presto.hive.HiveType.toHiveType) STAGE_AND_MOVE_TO_TARGET_DIRECTORY(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore.WriteMode.STAGE_AND_MOVE_TO_TARGET_DIRECTORY) Privilege(com.facebook.presto.spi.security.Privilege) FileSinkOperator(org.apache.hadoop.hive.ql.exec.FileSinkOperator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HiveSessionProperties.isBucketExecutionEnabled(com.facebook.presto.hive.HiveSessionProperties.isBucketExecutionEnabled) Collectors.toMap(java.util.stream.Collectors.toMap) Iterables.concat(com.google.common.collect.Iterables.concat) HIVE_COLUMN_ORDER_MISMATCH(com.facebook.presto.hive.HiveErrorCode.HIVE_COLUMN_ORDER_MISMATCH) BUCKETED_BY_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKETED_BY_PROPERTY) Path(org.apache.hadoop.fs.Path) DiscretePredicates(com.facebook.presto.spi.DiscretePredicates) NullableValue(com.facebook.presto.spi.predicate.NullableValue) Collectors.toSet(java.util.stream.Collectors.toSet) HIVE_UNSUPPORTED_FORMAT(com.facebook.presto.hive.HiveErrorCode.HIVE_UNSUPPORTED_FORMAT) ImmutableSet(com.google.common.collect.ImmutableSet) HIVE_UNKNOWN_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_UNKNOWN_ERROR) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) INVALID_SCHEMA_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) SCHEMA_NOT_EMPTY(com.facebook.presto.spi.StandardErrorCode.SCHEMA_NOT_EMPTY) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) STORAGE_FORMAT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.STORAGE_FORMAT_PROPERTY) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) HIVE_STRING(com.facebook.presto.hive.HiveType.HIVE_STRING) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) USER(com.facebook.presto.hive.metastore.PrincipalType.USER) Optional(java.util.Optional) HIVE_TIMEZONE_MISMATCH(com.facebook.presto.hive.HiveErrorCode.HIVE_TIMEZONE_MISMATCH) PARTITION_KEY(com.facebook.presto.hive.HiveColumnHandle.ColumnType.PARTITION_KEY) HiveUtil.schemaTableName(com.facebook.presto.hive.HiveUtil.schemaTableName) HIDDEN(com.facebook.presto.hive.HiveColumnHandle.ColumnType.HIDDEN) JsonCodec(io.airlift.json.JsonCodec) TupleDomain.withColumnDomains(com.facebook.presto.spi.predicate.TupleDomain.withColumnDomains) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Column(com.facebook.presto.hive.metastore.Column) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) HIVE_WRITER_CLOSE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_CLOSE_ERROR) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) Partition(com.facebook.presto.hive.metastore.Partition) ImmutableList(com.google.common.collect.ImmutableList) PARTITIONED_BY_PROPERTY(com.facebook.presto.hive.HiveTableProperties.PARTITIONED_BY_PROPERTY) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) HiveUtil.toPartitionValues(com.facebook.presto.hive.HiveUtil.toPartitionValues) HiveWriteUtils.isWritableType(com.facebook.presto.hive.HiveWriteUtils.isWritableType) ConnectorNodePartitioning(com.facebook.presto.spi.ConnectorNodePartitioning) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) EXTERNAL_LOCATION_PROPERTY(com.facebook.presto.hive.HiveTableProperties.EXTERNAL_LOCATION_PROPERTY) VIEW_STORAGE_FORMAT(com.facebook.presto.hive.metastore.StorageFormat.VIEW_STORAGE_FORMAT) Maps(com.google.common.collect.Maps) JobConf(org.apache.hadoop.mapred.JobConf) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) BUCKET_COUNT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKET_COUNT_PROPERTY) StorageFormat.fromHiveStorageFormat(com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat) HiveUtil.decodeViewData(com.facebook.presto.hive.HiveUtil.decodeViewData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MetastoreUtil.getHiveSchema(com.facebook.presto.hive.metastore.MetastoreUtil.getHiveSchema) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) ImmutableMap(com.google.common.collect.ImmutableMap) Column(com.facebook.presto.hive.metastore.Column)

Example 24 with Table

use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.

the class HivePartitionManager method getTable.

private Table getTable(SemiTransactionalHiveMetastore metastore, SchemaTableName tableName) {
    Optional<Table> target = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
    if (!target.isPresent()) {
        throw new TableNotFoundException(tableName);
    }
    Table table = target.get();
    String protectMode = table.getParameters().get(ProtectMode.PARAMETER_NAME);
    if (protectMode != null && getProtectModeFromString(protectMode).offline) {
        throw new TableOfflineException(tableName, false, null);
    }
    String prestoOffline = table.getParameters().get(PRESTO_OFFLINE);
    if (!isNullOrEmpty(prestoOffline)) {
        throw new TableOfflineException(tableName, true, prestoOffline);
    }
    return table;
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Table(com.facebook.presto.hive.metastore.Table) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString)

Example 25 with Table

use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.

the class FileHiveMetastore method setTablePrivileges.

private synchronized void setTablePrivileges(String principalName, PrincipalType principalType, String databaseName, String tableName, Collection<HivePrivilegeInfo> privileges) {
    requireNonNull(principalName, "principalName is null");
    requireNonNull(principalType, "principalType is null");
    requireNonNull(databaseName, "databaseName is null");
    requireNonNull(tableName, "tableName is null");
    requireNonNull(privileges, "privileges is null");
    try {
        Table table = getRequiredTable(databaseName, tableName);
        Path permissionsDirectory = getPermissionsDirectory(table);
        metadataFileSystem.mkdirs(permissionsDirectory);
        if (!metadataFileSystem.isDirectory(permissionsDirectory)) {
            throw new PrestoException(HIVE_METASTORE_ERROR, "Could not create permissions directory");
        }
        Path permissionFilePath = getPermissionsPath(permissionsDirectory, principalName, principalType);
        List<PermissionMetadata> permissions = privileges.stream().map(PermissionMetadata::new).collect(toList());
        writeFile("permissions", permissionFilePath, permissionsCodec, permissions, true);
    } catch (IOException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Table(com.facebook.presto.hive.metastore.Table) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Aggregations

Table (com.facebook.presto.hive.metastore.Table)33 Path (org.apache.hadoop.fs.Path)24 SchemaTableName (com.facebook.presto.spi.SchemaTableName)20 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)20 PrestoException (com.facebook.presto.spi.PrestoException)18 ImmutableMap (com.google.common.collect.ImmutableMap)17 PrincipalPrivileges (com.facebook.presto.hive.metastore.PrincipalPrivileges)16 Slice (io.airlift.slice.Slice)16 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ImmutableList (com.google.common.collect.ImmutableList)15 Partition (com.facebook.presto.hive.metastore.Partition)14 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)14 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)14 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)14 Collection (java.util.Collection)14 List (java.util.List)14 Map (java.util.Map)14 Optional (java.util.Optional)14 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)13 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)13