Search in sources :

Example 6 with Database

use of io.prestosql.plugin.hive.metastore.Database in project boostkit-bigdata by kunpengcompute.

the class HiveMetadata method createSchema.

@Override
public void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties) {
    Optional<String> location = HiveSchemaProperties.getLocation(properties).map(locationUri -> {
        try {
            hdfsEnvironment.getFileSystem(new HdfsContext(session, schemaName), new Path(locationUri));
        } catch (IOException e) {
            throw new PrestoException(INVALID_SCHEMA_PROPERTY, "Invalid location URI: " + locationUri, e);
        }
        return locationUri;
    });
    Database database = Database.builder().setDatabaseName(schemaName).setLocation(location).setOwnerType(USER).setOwnerName(session.getUser()).build();
    metastore.createDatabase(new HiveIdentity(session), database);
}
Also used : Path(org.apache.hadoop.fs.Path) Database(io.prestosql.plugin.hive.metastore.Database) PrestoException(io.prestosql.spi.PrestoException) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) IOException(java.io.IOException) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity)

Example 7 with Database

use of io.prestosql.plugin.hive.metastore.Database in project hetu-core by openlookeng.

the class CarbondataMetadata method beginCreateTable.

@Override
public CarbondataOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) {
    // get the root directory for the database
    SchemaTableName finalSchemaTableName = tableMetadata.getTable();
    String finalSchemaName = finalSchemaTableName.getSchemaName();
    String finalTableName = finalSchemaTableName.getTableName();
    this.user = session.getUser();
    this.schemaName = finalSchemaName;
    currentState = State.CREATE_TABLE_AS;
    List<String> partitionedBy = new ArrayList<String>();
    List<SortingColumn> sortBy = new ArrayList<SortingColumn>();
    List<HiveColumnHandle> columnHandles = new ArrayList<HiveColumnHandle>();
    Map<String, String> tableProperties = new HashMap<String, String>();
    getParametersForCreateTable(session, tableMetadata, partitionedBy, sortBy, columnHandles, tableProperties);
    metastore.getDatabase(finalSchemaName).orElseThrow(() -> new SchemaNotFoundException(finalSchemaName));
    // to avoid type mismatch between HiveStorageFormat & Carbondata StorageFormat this hack no option
    HiveStorageFormat tableStorageFormat = HiveStorageFormat.valueOf("CARBON");
    HiveStorageFormat partitionStorageFormat = tableStorageFormat;
    Map<String, HiveColumnHandle> columnHandlesByName = Maps.uniqueIndex(columnHandles, HiveColumnHandle::getName);
    List<Column> partitionColumns = partitionedBy.stream().map(columnHandlesByName::get).map(column -> new Column(column.getName(), column.getHiveType(), column.getComment())).collect(toList());
    checkPartitionTypesSupported(partitionColumns);
    // it will get final path to create carbon table
    LocationHandle locationHandle = getCarbonDataTableCreationPath(session, tableMetadata, HiveWriteUtils.OpertionType.CREATE_TABLE_AS);
    Path targetPath = locationService.getTableWriteInfo(locationHandle, false).getTargetPath();
    AbsoluteTableIdentifier finalAbsoluteTableIdentifier = AbsoluteTableIdentifier.from(targetPath.toString(), new CarbonTableIdentifier(finalSchemaName, finalTableName, UUID.randomUUID().toString()));
    hdfsEnvironment.doAs(session.getUser(), () -> {
        initialConfiguration = ConfigurationUtils.toJobConf(this.hdfsEnvironment.getConfiguration(new HdfsEnvironment.HdfsContext(session, finalSchemaName, finalTableName), new Path(locationHandle.getJsonSerializableTargetPath())));
        // Create Carbondata metadata folder and Schema file
        CarbondataMetadataUtils.createMetaDataFolderSchemaFile(hdfsEnvironment, session, columnHandles, finalAbsoluteTableIdentifier, partitionedBy, sortBy.stream().map(s -> s.getColumnName().toLowerCase(Locale.ENGLISH)).collect(toList()), targetPath.toString(), initialConfiguration);
        this.tableStorageLocation = Optional.of(targetPath.toString());
        Path outputPath = new Path(locationHandle.getJsonSerializableTargetPath());
        Properties schema = readSchemaForCarbon(finalSchemaName, finalTableName, targetPath, columnHandles, partitionColumns);
        // Create committer object
        setupCommitWriter(schema, outputPath, initialConfiguration, false);
    });
    try {
        CarbondataOutputTableHandle result = new CarbondataOutputTableHandle(finalSchemaName, finalTableName, columnHandles, metastore.generatePageSinkMetadata(new HiveIdentity(session), finalSchemaTableName), locationHandle, tableStorageFormat, partitionStorageFormat, partitionedBy, Optional.empty(), session.getUser(), tableProperties, ImmutableMap.<String, String>of(EncodedLoadModel, jobContext.getConfiguration().get(LOAD_MODEL)));
        LocationService.WriteInfo writeInfo = locationService.getQueryWriteInfo(locationHandle);
        metastore.declareIntentionToWrite(session, writeInfo.getWriteMode(), writeInfo.getWritePath(), finalSchemaTableName);
        return result;
    } catch (RuntimeException ex) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Error: creating table: %s ", ex.getMessage()), ex);
    }
}
Also used : Arrays(java.util.Arrays) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) BaseStorageFormat(io.prestosql.plugin.hive.BaseStorageFormat) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) FileSystem(org.apache.hadoop.fs.FileSystem) HiveWriteUtils(io.prestosql.plugin.hive.HiveWriteUtils) HiveUtil.hiveColumnHandles(io.prestosql.plugin.hive.HiveUtil.hiveColumnHandles) MetastoreUtil(io.prestosql.plugin.hive.metastore.MetastoreUtil) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) StringUtils(org.apache.commons.lang3.StringUtils) CarbonLockFactory(org.apache.carbondata.core.locks.CarbonLockFactory) HiveUtil.getPartitionKeyColumnHandles(io.prestosql.plugin.hive.HiveUtil.getPartitionKeyColumnHandles) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) CarbonCommonConstants(org.apache.carbondata.core.constants.CarbonCommonConstants) Future(java.util.concurrent.Future) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) HIVE_STRING(io.prestosql.plugin.hive.HiveType.HIVE_STRING) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) HiveErrorCode(io.prestosql.plugin.hive.HiveErrorCode) ThriftWrapperSchemaConverterImpl(org.apache.carbondata.core.metadata.converter.ThriftWrapperSchemaConverterImpl) TaskAttemptID(org.apache.hadoop.mapreduce.TaskAttemptID) Set(java.util.Set) LOCATION_PROPERTY(io.prestosql.plugin.hive.HiveTableProperties.LOCATION_PROPERTY) HiveTableProperties.getTransactionalValue(io.prestosql.plugin.hive.HiveTableProperties.getTransactionalValue) HiveOutputTableHandle(io.prestosql.plugin.hive.HiveOutputTableHandle) Collectors.joining(java.util.stream.Collectors.joining) BlockMappingVO(org.apache.carbondata.core.mutate.data.BlockMappingVO) CarbonLoadModel(org.apache.carbondata.processing.loading.model.CarbonLoadModel) META_TABLE_NAME(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_NAME) Table(io.prestosql.plugin.hive.metastore.Table) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) AccessControlMetadata(io.prestosql.plugin.hive.security.AccessControlMetadata) TableOptionConstant(org.apache.carbondata.processing.util.TableOptionConstant) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) PartitionInfo(org.apache.carbondata.core.metadata.schema.PartitionInfo) TypeTranslator(io.prestosql.plugin.hive.TypeTranslator) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) MapredCarbonOutputFormat(org.apache.carbondata.hive.MapredCarbonOutputFormat) StructField(org.apache.carbondata.core.metadata.datatype.StructField) CarbonUtil(org.apache.carbondata.core.util.CarbonUtil) CarbondataTableProperties.getCarbondataLocation(io.hetu.core.plugin.carbondata.CarbondataTableProperties.getCarbondataLocation) HiveWriterFactory(io.prestosql.plugin.hive.HiveWriterFactory) Database(io.prestosql.plugin.hive.metastore.Database) SchemaEvolutionEntry(org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry) Slice(io.airlift.slice.Slice) Partition(io.prestosql.plugin.hive.metastore.Partition) TRANSACTIONAL(io.prestosql.plugin.hive.HiveTableProperties.TRANSACTIONAL) DataTypes(org.apache.carbondata.core.metadata.datatype.DataTypes) CarbonDataMergerUtil(org.apache.carbondata.processing.merger.CarbonDataMergerUtil) SimpleDateFormat(java.text.SimpleDateFormat) ComputedStatistics(io.prestosql.spi.statistics.ComputedStatistics) CarbondataTableReader(io.hetu.core.plugin.carbondata.impl.CarbondataTableReader) ArrayList(java.util.ArrayList) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment) ThreadLocalSessionInfo(org.apache.carbondata.core.util.ThreadLocalSessionInfo) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LocationService(io.prestosql.plugin.hive.LocationService) LockUsage(org.apache.carbondata.core.locks.LockUsage) CarbonUpdateUtil(org.apache.carbondata.core.mutate.CarbonUpdateUtil) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) SegmentStatusManager(org.apache.carbondata.core.statusmanager.SegmentStatusManager) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) Properties(java.util.Properties) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) CarbonFile(org.apache.carbondata.core.datastore.filesystem.CarbonFile) CarbonOutputCommitter(org.apache.carbondata.hadoop.api.CarbonOutputCommitter) HiveStorageFormat(io.prestosql.plugin.hive.HiveStorageFormat) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) HiveInsertTableHandle(io.prestosql.plugin.hive.HiveInsertTableHandle) HiveTableProperties(io.prestosql.plugin.hive.HiveTableProperties) TypeManager(io.prestosql.spi.type.TypeManager) ICarbonLock(org.apache.carbondata.core.locks.ICarbonLock) IOException(java.io.IOException) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) File(java.io.File) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) ExecutionException(java.util.concurrent.ExecutionException) OutputCommitter(org.apache.hadoop.mapreduce.OutputCommitter) TreeMap(java.util.TreeMap) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) HiveWrittenPartitions(io.prestosql.plugin.hive.HiveWrittenPartitions) TableType(org.apache.hadoop.hive.metastore.TableType) META_TABLE_LOCATION(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_LOCATION) ConfigurationUtils(io.prestosql.plugin.hive.util.ConfigurationUtils) LocationHandle(io.prestosql.plugin.hive.LocationHandle) CarbonTableOutputFormat(org.apache.carbondata.hadoop.api.CarbonTableOutputFormat) CarbonMetadata(org.apache.carbondata.core.metadata.CarbonMetadata) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) HivePartitionManager(io.prestosql.plugin.hive.HivePartitionManager) ThriftWriter(org.apache.carbondata.core.writer.ThriftWriter) HiveTypeName(io.prestosql.plugin.hive.HiveTypeName) Date(java.util.Date) SYNTHESIZED(io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.SYNTHESIZED) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) Duration(io.airlift.units.Duration) SegmentFileStore(org.apache.carbondata.core.metadata.SegmentFileStore) TaskType(org.apache.hadoop.mapreduce.TaskType) Logger(org.apache.log4j.Logger) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Gson(com.google.gson.Gson) Locale(java.util.Locale) HiveCarbonUtil(org.apache.carbondata.hive.util.HiveCarbonUtil) Path(org.apache.hadoop.fs.Path) SegmentUpdateStatusManager(org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager) Type(io.prestosql.spi.type.Type) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) EncodedLoadModel(io.hetu.core.plugin.carbondata.CarbondataConstants.EncodedLoadModel) HiveBucketing(io.prestosql.plugin.hive.HiveBucketing) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) FileInputFormat(org.apache.hadoop.mapred.FileInputFormat) Collection(java.util.Collection) UUID(java.util.UUID) TableSchema(org.apache.carbondata.core.metadata.schema.table.TableSchema) HiveType(io.prestosql.plugin.hive.HiveType) CarbonLockUtil(org.apache.carbondata.core.locks.CarbonLockUtil) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) CarbonTableInputFormat(org.apache.carbondata.hadoop.api.CarbonTableInputFormat) List(java.util.List) TaskAttemptContextImpl(org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl) Job(org.apache.hadoop.mapreduce.Job) TableSchemaBuilder(org.apache.carbondata.core.metadata.schema.table.TableSchemaBuilder) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) HiveStatisticsProvider(io.prestosql.plugin.hive.statistics.HiveStatisticsProvider) JsonCodec(io.airlift.json.JsonCodec) HiveBucketProperty(io.prestosql.plugin.hive.HiveBucketProperty) ConnectorOutputMetadata(io.prestosql.spi.connector.ConnectorOutputMetadata) Segment(org.apache.carbondata.core.index.Segment) HiveSessionProperties(io.prestosql.plugin.hive.HiveSessionProperties) ConnectorNewTableLayout(io.prestosql.spi.connector.ConnectorNewTableLayout) TableInfo(org.apache.carbondata.core.metadata.schema.table.TableInfo) HashMap(java.util.HashMap) TableOperation(org.apache.carbondata.core.features.TableOperation) CompactionType(org.apache.carbondata.processing.merger.CompactionType) IOConstants(org.apache.hadoop.hive.ql.io.IOConstants) HiveUtil.toPartitionValues(io.prestosql.plugin.hive.HiveUtil.toPartitionValues) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory) SegmentStatus(org.apache.carbondata.core.statusmanager.SegmentStatus) LoadMetadataDetails(org.apache.carbondata.core.statusmanager.LoadMetadataDetails) Function(java.util.function.Function) ObjectSerializationUtil(org.apache.carbondata.core.util.ObjectSerializationUtil) JobContextImpl(org.apache.hadoop.mapreduce.task.JobContextImpl) HashSet(java.util.HashSet) JobStatus(org.apache.hadoop.mapred.JobStatus) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) FileWriteOperation(org.apache.carbondata.core.fileoperations.FileWriteOperation) Objects.requireNonNull(java.util.Objects.requireNonNull) CarbonLoaderUtil(org.apache.carbondata.processing.util.CarbonLoaderUtil) HiveACIDWriteType(io.prestosql.plugin.hive.HiveACIDWriteType) HiveMetadata(io.prestosql.plugin.hive.HiveMetadata) LogServiceFactory(org.apache.carbondata.common.logging.LogServiceFactory) JobID(org.apache.hadoop.mapreduce.JobID) NoSuchElementException(java.util.NoSuchElementException) SegmentUpdateDetails(org.apache.carbondata.core.mutate.SegmentUpdateDetails) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) HiveUpdateTableHandle(io.prestosql.plugin.hive.HiveUpdateTableHandle) TableProcessingOperations(org.apache.carbondata.processing.loading.TableProcessingOperations) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) NON_INHERITABLE_PROPERTIES(io.prestosql.plugin.hive.HiveTableProperties.NON_INHERITABLE_PROPERTIES) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) NoSuchMVException(org.apache.carbondata.common.exceptions.sql.NoSuchMVException) Maps(com.google.common.collect.Maps) HiveDeleteAsInsertTableHandle(io.prestosql.plugin.hive.HiveDeleteAsInsertTableHandle) RowCountDetailsVO(org.apache.carbondata.core.mutate.data.RowCountDetailsVO) CarbondataTableCacheModel(io.hetu.core.plugin.carbondata.impl.CarbondataTableCacheModel) PartitionUpdate(io.prestosql.plugin.hive.PartitionUpdate) JobConf(org.apache.hadoop.mapred.JobConf) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Column(io.prestosql.plugin.hive.metastore.Column) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) SchemaConverter(org.apache.carbondata.core.metadata.converter.SchemaConverter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrestoException(io.prestosql.spi.PrestoException) Properties(java.util.Properties) HiveTableProperties(io.prestosql.plugin.hive.HiveTableProperties) HiveSessionProperties(io.prestosql.plugin.hive.HiveSessionProperties) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) LocationHandle(io.prestosql.plugin.hive.LocationHandle) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment) LocationService(io.prestosql.plugin.hive.LocationService) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) HiveStorageFormat(io.prestosql.plugin.hive.HiveStorageFormat) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Column(io.prestosql.plugin.hive.metastore.Column) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) Path(org.apache.hadoop.fs.Path) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException)

Example 8 with Database

use of io.prestosql.plugin.hive.metastore.Database in project hetu-core by openlookeng.

the class FileHiveMetastore method getAllTables.

@Override
public synchronized Optional<List<String>> getAllTables(String databaseName) {
    requireNonNull(databaseName, "databaseName is null");
    Optional<Database> database = getDatabase(databaseName);
    if (!database.isPresent()) {
        return Optional.empty();
    }
    Path databaseMetadataDirectory = getDatabaseMetadataDirectory(databaseName);
    List<String> tables = getChildSchemaDirectories(databaseMetadataDirectory).stream().map(Path::getName).collect(toList());
    return Optional.of(ImmutableList.copyOf(tables));
}
Also used : Path(org.apache.hadoop.fs.Path) Database(io.prestosql.plugin.hive.metastore.Database)

Example 9 with Database

use of io.prestosql.plugin.hive.metastore.Database in project hetu-core by openlookeng.

the class HiveMetadata method beginCreateTable.

@Override
public HiveOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) {
    if (getExternalLocation(tableMetadata.getProperties()) != null || isExternalTable(tableMetadata.getProperties())) {
        throw new PrestoException(NOT_SUPPORTED, "External tables cannot be created using CREATE TABLE AS");
    }
    if (HiveTableProperties.getAvroSchemaUrl(tableMetadata.getProperties()) != null) {
        throw new PrestoException(NOT_SUPPORTED, "CREATE TABLE AS not supported when Avro schema url is set");
    }
    HiveStorageFormat tableStorageFormat = HiveTableProperties.getHiveStorageFormat(tableMetadata.getProperties());
    List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties());
    Optional<HiveBucketProperty> bucketProperty = HiveTableProperties.getBucketProperty(tableMetadata.getProperties());
    // get the root directory for the database
    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    Map<String, String> tableProperties = getEmptyTableProperties(tableMetadata, bucketProperty, new HdfsContext(session, schemaName, tableName));
    List<HiveColumnHandle> columnHandles = getColumnHandles(tableMetadata, ImmutableSet.copyOf(partitionedBy), typeTranslator);
    HiveStorageFormat partitionStorageFormat = HiveSessionProperties.isRespectTableFormat(session) ? tableStorageFormat : HiveSessionProperties.getHiveStorageFormat(session);
    // unpartitioned tables ignore the partition storage format
    HiveStorageFormat actualStorageFormat = partitionedBy.isEmpty() ? tableStorageFormat : partitionStorageFormat;
    actualStorageFormat.validateColumns(columnHandles);
    Map<String, HiveColumnHandle> columnHandlesByName = Maps.uniqueIndex(columnHandles, HiveColumnHandle::getName);
    List<Column> partitionColumns = partitionedBy.stream().map(columnHandlesByName::get).map(column -> new Column(column.getName(), column.getHiveType(), column.getComment())).collect(toList());
    checkPartitionTypesSupported(partitionColumns);
    Optional<String> location = getLocation(tableMetadata.getProperties());
    if (location.isPresent() && !tableCreatesWithLocationAllowed) {
        throw new PrestoException(NOT_SUPPORTED, format("Setting %s property is not allowed", LOCATION_PROPERTY));
    }
    Optional<WriteIdInfo> writeIdInfo = Optional.empty();
    if (AcidUtils.isTransactionalTable(tableProperties)) {
        // Create the HiveTableHandle for just to obtain writeIds.
        List<HiveColumnHandle> partitionColumnHandles = partitionedBy.stream().map(columnHandlesByName::get).collect(toList());
        HiveTableHandle tableHandle = new HiveTableHandle(schemaName, tableName, tableProperties, partitionColumnHandles, Optional.empty());
        Optional<Long> writeId = metastore.getTableWriteId(session, tableHandle, HiveACIDWriteType.INSERT);
        if (!writeId.isPresent()) {
            throw new IllegalStateException("No validWriteIds present");
        }
        writeIdInfo = Optional.of(new WriteIdInfo(writeId.get(), writeId.get(), 0));
    }
    LocationHandle locationHandle;
    if (location.isPresent()) {
        Path path = getPath(new HdfsContext(session, schemaName, tableName), location.get(), false);
        locationHandle = locationService.forNewTable(metastore, session, schemaName, tableName, writeIdInfo, Optional.of(path), HiveWriteUtils.OpertionType.CREATE_TABLE_AS);
    } else {
        locationHandle = locationService.forNewTable(metastore, session, schemaName, tableName, writeIdInfo, Optional.empty(), HiveWriteUtils.OpertionType.CREATE_TABLE_AS);
    }
    HiveOutputTableHandle result = new HiveOutputTableHandle(schemaName, tableName, columnHandles, metastore.generatePageSinkMetadata(new HiveIdentity(session), schemaTableName), locationHandle, tableStorageFormat, partitionStorageFormat, partitionedBy, bucketProperty, session.getUser(), tableProperties);
    LocationService.WriteInfo writeInfo = locationService.getQueryWriteInfo(locationHandle);
    metastore.declareIntentionToWrite(session, writeInfo.getWriteMode(), writeInfo.getWritePath(), schemaTableName);
    return result;
}
Also used : TableStatistics(io.prestosql.spi.statistics.TableStatistics) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) PartialAndFinalAggregationType(io.prestosql.spi.PartialAndFinalAggregationType) FIELD_DELIM(org.apache.hadoop.hive.serde.serdeConstants.FIELD_DELIM) HiveUtil.verifyPartitionTypeSupported(io.prestosql.plugin.hive.HiveUtil.verifyPartitionTypeSupported) FileSystem(org.apache.hadoop.fs.FileSystem) HIVE_FILESYSTEM_ERROR(io.prestosql.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) HiveUtil.hiveColumnHandles(io.prestosql.plugin.hive.HiveUtil.hiveColumnHandles) MetastoreUtil(io.prestosql.plugin.hive.metastore.MetastoreUtil) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) NullableValue(io.prestosql.spi.predicate.NullableValue) RoleGrant(io.prestosql.spi.security.RoleGrant) ConnectorVacuumTableHandle(io.prestosql.spi.connector.ConnectorVacuumTableHandle) FileStatus(org.apache.hadoop.fs.FileStatus) SCHEMA_NOT_EMPTY(io.prestosql.spi.StandardErrorCode.SCHEMA_NOT_EMPTY) HiveUtil.getPartitionKeyColumnHandles(io.prestosql.plugin.hive.HiveUtil.getPartitionKeyColumnHandles) ConnectorDeleteAsInsertTableHandle(io.prestosql.spi.connector.ConnectorDeleteAsInsertTableHandle) Future(java.util.concurrent.Future) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) BucketingVersion(io.prestosql.plugin.hive.HiveBucketing.BucketingVersion) ConnectorUpdateTableHandle(io.prestosql.spi.connector.ConnectorUpdateTableHandle) Map(java.util.Map) HiveTableProperties.getPartitionedBy(io.prestosql.plugin.hive.HiveTableProperties.getPartitionedBy) ENGLISH(java.util.Locale.ENGLISH) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) SystemTable(io.prestosql.spi.connector.SystemTable) GrantInfo(io.prestosql.spi.security.GrantInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) org.apache.hadoop.hive.serde.serdeConstants(org.apache.hadoop.hive.serde.serdeConstants) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) Set(java.util.Set) LOCATION_PROPERTY(io.prestosql.plugin.hive.HiveTableProperties.LOCATION_PROPERTY) HiveTableProperties.getTransactionalValue(io.prestosql.plugin.hive.HiveTableProperties.getTransactionalValue) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) Collectors.joining(java.util.stream.Collectors.joining) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Privilege(io.prestosql.spi.security.Privilege) INVALID_TABLE_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) HiveTableProperties.isExternalTable(io.prestosql.plugin.hive.HiveTableProperties.isExternalTable) Domain(io.prestosql.spi.predicate.Domain) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) AccessControlMetadata(io.prestosql.plugin.hive.security.AccessControlMetadata) ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) ORC(io.prestosql.plugin.hive.HiveStorageFormat.ORC) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) Database(io.prestosql.plugin.hive.metastore.Database) Slice(io.airlift.slice.Slice) Partition(io.prestosql.plugin.hive.metastore.Partition) TRANSACTIONAL(io.prestosql.plugin.hive.HiveTableProperties.TRANSACTIONAL) HiveWriterFactory.getSnapshotSubFileIndex(io.prestosql.plugin.hive.HiveWriterFactory.getSnapshotSubFileIndex) Supplier(java.util.function.Supplier) ComputedStatistics(io.prestosql.spi.statistics.ComputedStatistics) ArrayList(java.util.ArrayList) HiveUtil.decodeViewData(io.prestosql.plugin.hive.HiveUtil.decodeViewData) OptionalLong(java.util.OptionalLong) TupleDomain.withColumnDomains(io.prestosql.spi.predicate.TupleDomain.withColumnDomains) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectorPartitioningHandle(io.prestosql.spi.connector.ConnectorPartitioningHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) RecordCursor(io.prestosql.spi.connector.RecordCursor) DiscretePredicates(io.prestosql.spi.connector.DiscretePredicates) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) HiveWriterFactory.removeSnapshotFileName(io.prestosql.plugin.hive.HiveWriterFactory.removeSnapshotFileName) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) Properties(java.util.Properties) HiveUtil.isPrestoView(io.prestosql.plugin.hive.HiveUtil.isPrestoView) TypeManager(io.prestosql.spi.type.TypeManager) IOException(java.io.IOException) USER(io.prestosql.spi.security.PrincipalType.USER) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Streams.stream(com.google.common.collect.Streams.stream) IS_EXTERNAL_TABLE(io.prestosql.plugin.hive.HiveTableProperties.IS_EXTERNAL_TABLE) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ConnectorTablePartitioning(io.prestosql.spi.connector.ConnectorTablePartitioning) TableType(org.apache.hadoop.hive.metastore.TableType) ConfigurationUtils(io.prestosql.plugin.hive.util.ConfigurationUtils) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) HiveWriterFactory.isSnapshotFile(io.prestosql.plugin.hive.HiveWriterFactory.isSnapshotFile) VarcharType(io.prestosql.spi.type.VarcharType) HiveTableProperties.getLocation(io.prestosql.plugin.hive.HiveTableProperties.getLocation) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) Statistics(io.prestosql.plugin.hive.util.Statistics) URL(java.net.URL) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) EXTERNAL_TABLE(org.apache.hadoop.hive.metastore.TableType.EXTERNAL_TABLE) ViewNotFoundException(io.prestosql.spi.connector.ViewNotFoundException) HiveTableProperties.getHiveStorageFormat(io.prestosql.plugin.hive.HiveTableProperties.getHiveStorageFormat) Duration(io.airlift.units.Duration) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) FileSinkOperator(org.apache.hadoop.hive.ql.exec.FileSinkOperator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) INVALID_ANALYZE_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_ANALYZE_PROPERTY) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Collectors.toMap(java.util.stream.Collectors.toMap) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Iterables.concat(com.google.common.collect.Iterables.concat) Path(org.apache.hadoop.fs.Path) Type(io.prestosql.spi.type.Type) Splitter(com.google.common.base.Splitter) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Collectors.toSet(java.util.stream.Collectors.toSet) Constraint(io.prestosql.spi.connector.Constraint) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) HiveWriteUtils.isS3FileSystem(io.prestosql.plugin.hive.HiveWriteUtils.isS3FileSystem) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) HiveUtil.columnExtraInfo(io.prestosql.plugin.hive.HiveUtil.columnExtraInfo) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) HiveUtil.encodeViewData(io.prestosql.plugin.hive.HiveUtil.encodeViewData) HiveWriterFactory.isSnapshotSubFile(io.prestosql.plugin.hive.HiveWriterFactory.isSnapshotSubFile) ROW_COUNT(io.prestosql.spi.statistics.TableStatisticType.ROW_COUNT) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) List(java.util.List) PRESTO_VIEW_FLAG(io.prestosql.plugin.hive.HiveUtil.PRESTO_VIEW_FLAG) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Function.identity(java.util.function.Function.identity) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils) HiveStatisticsProvider(io.prestosql.plugin.hive.statistics.HiveStatisticsProvider) JsonCodec(io.airlift.json.JsonCodec) IntStream(java.util.stream.IntStream) ConnectorOutputMetadata(io.prestosql.spi.connector.ConnectorOutputMetadata) Logger(io.airlift.log.Logger) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) ConnectorNewTableLayout(io.prestosql.spi.connector.ConnectorNewTableLayout) HashMap(java.util.HashMap) HiveUtil.toPartitionValues(io.prestosql.plugin.hive.HiveUtil.toPartitionValues) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) HashSet(java.util.HashSet) HiveTableProperties.getExternalLocation(io.prestosql.plugin.hive.HiveTableProperties.getExternalLocation) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) OpenCSVSerde(org.apache.hadoop.hive.serde2.OpenCSVSerde) INVALID_SCHEMA_PROPERTY(io.prestosql.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) Suppliers(com.google.common.base.Suppliers) NoSuchElementException(java.util.NoSuchElementException) Block(io.prestosql.spi.block.Block) VerifyException(com.google.common.base.VerifyException) Collections.emptyMap(java.util.Collections.emptyMap) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) MalformedURLException(java.net.MalformedURLException) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) NON_INHERITABLE_PROPERTIES(io.prestosql.plugin.hive.HiveTableProperties.NON_INHERITABLE_PROPERTIES) Maps(com.google.common.collect.Maps) PRIMITIVE(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE) JobConf(org.apache.hadoop.mapred.JobConf) Collectors.toList(java.util.stream.Collectors.toList) Column(io.prestosql.plugin.hive.metastore.Column) GENERIC_USER_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_USER_ERROR) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) ConnectorInsertTableHandle(io.prestosql.spi.connector.ConnectorInsertTableHandle) HiveBucketing.bucketedOnTimestamp(io.prestosql.plugin.hive.HiveBucketing.bucketedOnTimestamp) PrestoException(io.prestosql.spi.PrestoException) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) HiveTableProperties.getHiveStorageFormat(io.prestosql.plugin.hive.HiveTableProperties.getHiveStorageFormat) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Column(io.prestosql.plugin.hive.metastore.Column) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) Path(org.apache.hadoop.fs.Path) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) OptionalLong(java.util.OptionalLong)

Example 10 with Database

use of io.prestosql.plugin.hive.metastore.Database in project hetu-core by openlookeng.

the class HiveMetadata method createSchema.

@Override
public void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties) {
    Optional<String> location = HiveSchemaProperties.getLocation(properties).map(locationUri -> {
        try {
            hdfsEnvironment.getFileSystem(new HdfsContext(session, schemaName), new Path(locationUri));
        } catch (IOException e) {
            throw new PrestoException(INVALID_SCHEMA_PROPERTY, "Invalid location URI: " + locationUri, e);
        }
        return locationUri;
    });
    Database database = Database.builder().setDatabaseName(schemaName).setLocation(location).setOwnerType(USER).setOwnerName(session.getUser()).build();
    metastore.createDatabase(new HiveIdentity(session), database);
}
Also used : Path(org.apache.hadoop.fs.Path) Database(io.prestosql.plugin.hive.metastore.Database) PrestoException(io.prestosql.spi.PrestoException) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) IOException(java.io.IOException) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity)

Aggregations

Database (io.prestosql.plugin.hive.metastore.Database)18 Path (org.apache.hadoop.fs.Path)14 PrestoException (io.prestosql.spi.PrestoException)11 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)9 HdfsContext (io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)8 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 IOException (java.io.IOException)7 PrincipalPrivileges (io.prestosql.plugin.hive.metastore.PrincipalPrivileges)6 Table (io.prestosql.plugin.hive.metastore.Table)6 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)6 TableAlreadyExistsException (io.prestosql.spi.connector.TableAlreadyExistsException)6 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 JsonCodec (io.airlift.json.JsonCodec)5 Slice (io.airlift.slice.Slice)5 HiveUtil.toPartitionValues (io.prestosql.plugin.hive.HiveUtil.toPartitionValues)5