Search in sources :

Example 1 with HiveBasicStatistics

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

the class CarbondataMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    SchemaTableName localSchemaTableName = tableMetadata.getTable();
    String localSchemaName = localSchemaTableName.getSchemaName();
    String tableName = localSchemaTableName.getTableName();
    this.user = session.getUser();
    this.schemaName = localSchemaName;
    currentState = State.CREATE_TABLE;
    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(localSchemaName).orElseThrow(() -> new SchemaNotFoundException(localSchemaName));
    BaseStorageFormat hiveStorageFormat = CarbondataTableProperties.getCarbondataStorageFormat(tableMetadata.getProperties());
    // it will get final path to create carbon table
    LocationHandle locationHandle = getCarbonDataTableCreationPath(session, tableMetadata, HiveWriteUtils.OpertionType.CREATE_TABLE);
    Path targetPath = locationService.getQueryWriteInfo(locationHandle).getTargetPath();
    AbsoluteTableIdentifier finalAbsoluteTableIdentifier = AbsoluteTableIdentifier.from(targetPath.toString(), new CarbonTableIdentifier(localSchemaName, tableName, UUID.randomUUID().toString()));
    hdfsEnvironment.doAs(session.getUser(), () -> {
        initialConfiguration = ConfigurationUtils.toJobConf(this.hdfsEnvironment.getConfiguration(new HdfsEnvironment.HdfsContext(session, localSchemaName, tableName), new Path(locationHandle.getJsonSerializableTargetPath())));
        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());
        try {
            Map<String, String> serdeParameters = initSerDeProperties(tableName);
            Table localTable = buildTableObject(session.getQueryId(), localSchemaName, tableName, session.getUser(), columnHandles, hiveStorageFormat, partitionedBy, Optional.empty(), tableProperties, targetPath, // carbon table is set as external table
            true, prestoVersion, serdeParameters);
            PrincipalPrivileges principalPrivileges = MetastoreUtil.buildInitialPrivilegeSet(localTable.getOwner());
            HiveBasicStatistics basicStatistics = localTable.getPartitionColumns().isEmpty() ? HiveBasicStatistics.createZeroStatistics() : HiveBasicStatistics.createEmptyStatistics();
            metastore.createTable(session, localTable, principalPrivileges, Optional.empty(), ignoreExisting, new PartitionStatistics(basicStatistics, ImmutableMap.of()));
        } catch (RuntimeException ex) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Error: creating table: %s ", ex.getMessage()), ex);
        }
    });
}
Also used : CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) Path(org.apache.hadoop.fs.Path) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Table(io.prestosql.plugin.hive.metastore.Table) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrestoException(io.prestosql.spi.PrestoException) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocationHandle(io.prestosql.plugin.hive.LocationHandle) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) BaseStorageFormat(io.prestosql.plugin.hive.BaseStorageFormat) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle)

Example 2 with HiveBasicStatistics

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

the class ThriftMetastoreUtil method getHiveBasicStatistics.

public static HiveBasicStatistics getHiveBasicStatistics(Map<String, String> parameters) {
    OptionalLong numFiles = parse(parameters.get(NUM_FILES));
    OptionalLong numRows = parse(parameters.get(NUM_ROWS));
    OptionalLong inMemoryDataSizeInBytes = parse(parameters.get(RAW_DATA_SIZE));
    OptionalLong onDiskDataSizeInBytes = parse(parameters.get(TOTAL_SIZE));
    return new HiveBasicStatistics(numFiles, numRows, inMemoryDataSizeInBytes, onDiskDataSizeInBytes);
}
Also used : OptionalLong(java.util.OptionalLong) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics)

Example 3 with HiveBasicStatistics

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

the class ThriftHiveMetastore method getTableStatistics.

@Override
public PartitionStatistics getTableStatistics(HiveIdentity identity, Table table) {
    List<String> dataColumns = table.getSd().getCols().stream().map(FieldSchema::getName).collect(toImmutableList());
    HiveBasicStatistics basicStatistics = ThriftMetastoreUtil.getHiveBasicStatistics(table.getParameters());
    Map<String, HiveColumnStatistics> columnStatistics = getTableColumnStatistics(identity, table.getDbName(), table.getTableName(), dataColumns, basicStatistics.getRowCount());
    return new PartitionStatistics(basicStatistics, columnStatistics);
}
Also used : PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics)

Example 4 with HiveBasicStatistics

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

the class ThriftHiveMetastore method getPartitionStatistics.

@Override
public Map<String, PartitionStatistics> getPartitionStatistics(HiveIdentity identity, Table table, List<Partition> partitions) {
    List<String> dataColumns = table.getSd().getCols().stream().map(FieldSchema::getName).collect(toImmutableList());
    List<String> partitionColumns = table.getPartitionKeys().stream().map(FieldSchema::getName).collect(toImmutableList());
    Map<String, HiveBasicStatistics> partitionBasicStatistics = partitions.stream().collect(toImmutableMap(partition -> makePartName(partitionColumns, partition.getValues()), partition -> ThriftMetastoreUtil.getHiveBasicStatistics(partition.getParameters())));
    Map<String, OptionalLong> partitionRowCounts = partitionBasicStatistics.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().getRowCount()));
    Map<String, Map<String, HiveColumnStatistics>> partitionColumnStatistics = getPartitionColumnStatistics(identity, table.getDbName(), table.getTableName(), partitionBasicStatistics.keySet(), dataColumns, partitionRowCounts);
    ImmutableMap.Builder<String, PartitionStatistics> result = ImmutableMap.builder();
    for (String partitionName : partitionBasicStatistics.keySet()) {
        HiveBasicStatistics basicStatistics = partitionBasicStatistics.get(partitionName);
        Map<String, HiveColumnStatistics> columnStatistics = partitionColumnStatistics.getOrDefault(partitionName, ImmutableMap.of());
        result.put(partitionName, new PartitionStatistics(basicStatistics, columnStatistics));
    }
    return result.build();
}
Also used : LockComponentBuilder(org.apache.hadoop.hive.metastore.LockComponentBuilder) HiveViewNotSupportedException(io.prestosql.plugin.hive.HiveViewNotSupportedException) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) TableAlreadyExistsException(io.prestosql.spi.connector.TableAlreadyExistsException) RoleGrant(io.prestosql.spi.security.RoleGrant) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) SchemaAlreadyExistsException(io.prestosql.spi.connector.SchemaAlreadyExistsException) Sets.difference(com.google.common.collect.Sets.difference) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) Map(java.util.Map) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) HiveErrorCode(io.prestosql.plugin.hive.HiveErrorCode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) TxnAbortedException(org.apache.hadoop.hive.metastore.api.TxnAbortedException) Verify.verifyNotNull(com.google.common.base.Verify.verifyNotNull) ALREADY_EXISTS(io.prestosql.spi.StandardErrorCode.ALREADY_EXISTS) Iterables(com.google.common.collect.Iterables) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) Flatten(org.weakref.jmx.Flatten) HIVE_FILTER_FIELD_PARAMS(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) DataOperationType(org.apache.hadoop.hive.metastore.api.DataOperationType) OptionalLong(java.util.OptionalLong) Managed(org.weakref.jmx.Managed) LockState(org.apache.hadoop.hive.metastore.api.LockState) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) FileUtils.makePartName(org.apache.hadoop.hive.common.FileUtils.makePartName) TException(org.apache.thrift.TException) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) USER(io.prestosql.spi.security.PrincipalType.USER) Table(org.apache.hadoop.hive.metastore.api.Table) System.nanoTime(java.lang.System.nanoTime) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) PartitionNotFoundException(io.prestosql.plugin.hive.PartitionNotFoundException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Duration(io.airlift.units.Duration) RetryDriver(io.prestosql.plugin.hive.util.RetryDriver) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Throwables.propagateIfPossible(com.google.common.base.Throwables.propagateIfPossible) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) Type(io.prestosql.spi.type.Type) Collectors.toSet(java.util.stream.Collectors.toSet) PrivilegeBag(org.apache.hadoop.hive.metastore.api.PrivilegeBag) PrestoException(io.prestosql.spi.PrestoException) NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) LockRequestBuilder(org.apache.hadoop.hive.metastore.LockRequestBuilder) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) HiveType(io.prestosql.plugin.hive.HiveType) ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) HivePartition(io.prestosql.plugin.hive.HivePartition) List(java.util.List) PRESTO_VIEW_FLAG(io.prestosql.plugin.hive.HiveUtil.PRESTO_VIEW_FLAG) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Logger(io.airlift.log.Logger) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) Partition(org.apache.hadoop.hive.metastore.api.Partition) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) Inject(javax.inject.Inject) HashSet(java.util.HashSet) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) TABLE(org.apache.hadoop.hive.metastore.api.HiveObjectType.TABLE) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) Iterator(java.util.Iterator) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) PartitionWithStatistics(io.prestosql.plugin.hive.metastore.PartitionWithStatistics) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Column(io.prestosql.plugin.hive.metastore.Column) Closeable(java.io.Closeable) Database(org.apache.hadoop.hive.metastore.api.Database) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) OptionalLong(java.util.OptionalLong) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with HiveBasicStatistics

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

the class ThriftHiveMetastore method updatePartitionStatistics.

@Override
public void updatePartitionStatistics(HiveIdentity identity, String databaseName, String tableName, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
    List<Partition> partitions = getPartitionsByNames(identity, databaseName, tableName, ImmutableList.of(partitionName));
    if (partitions.size() != 1) {
        throw new PrestoException(HiveErrorCode.HIVE_METASTORE_ERROR, "Metastore returned multiple partitions for name: " + partitionName);
    }
    Table table = getTable(identity, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    PartitionStatistics currentStatistics = requireNonNull(getPartitionStatistics(identity, table, partitions).get(partitionName), "getPartitionStatistics() returned null");
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    Partition originalPartition = getOnlyElement(partitions);
    Partition modifiedPartition = originalPartition.deepCopy();
    HiveBasicStatistics basicStatistics = updatedStatistics.getBasicStatistics();
    modifiedPartition.setParameters(ThriftMetastoreUtil.updateStatisticsParameters(modifiedPartition.getParameters(), basicStatistics));
    alterPartitionWithoutStatistics(identity, databaseName, tableName, modifiedPartition);
    updatePartitionColumnStatistics(identity, modifiedPartition, databaseName, tableName, partitionName, basicStatistics, currentStatistics, updatedStatistics);
}
Also used : HivePartition(io.prestosql.plugin.hive.HivePartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) PrestoException(io.prestosql.spi.PrestoException) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Aggregations

HiveBasicStatistics (io.prestosql.plugin.hive.HiveBasicStatistics)17 PartitionStatistics (io.prestosql.plugin.hive.PartitionStatistics)12 PrestoException (io.prestosql.spi.PrestoException)6 HivePartition (io.prestosql.plugin.hive.HivePartition)5 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)5 Test (org.testng.annotations.Test)5 HiveColumnStatistics (io.prestosql.plugin.hive.metastore.HiveColumnStatistics)4 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)4 OptionalLong (java.util.OptionalLong)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 HiveColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle)3 HiveConfig (io.prestosql.plugin.hive.HiveConfig)3 HiveSessionProperties (io.prestosql.plugin.hive.HiveSessionProperties)3 OrcFileWriterConfig (io.prestosql.plugin.hive.OrcFileWriterConfig)3 ParquetFileWriterConfig (io.prestosql.plugin.hive.ParquetFileWriterConfig)3 ThriftMetastoreUtil.getHiveBasicStatistics (io.prestosql.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics)3 MetastoreHiveStatisticsProvider.validatePartitionStatistics (io.prestosql.plugin.hive.statistics.MetastoreHiveStatisticsProvider.validatePartitionStatistics)3