Search in sources :

Example 1 with UpdatePartitionSpec

use of org.apache.iceberg.UpdatePartitionSpec in project hive by apache.

the class IcebergTableUtil method updateSpec.

public static void updateSpec(Configuration configuration, Table table) {
    // get the new partition transform spec
    PartitionSpec newPartitionSpec = spec(configuration, table.schema());
    if (newPartitionSpec == null) {
        LOG.debug("Iceberg Partition spec is not updated due to empty partition spec definition.");
        return;
    }
    // delete every field from the old partition spec
    UpdatePartitionSpec updatePartitionSpec = table.updateSpec().caseSensitive(false);
    table.spec().fields().forEach(field -> updatePartitionSpec.removeField(field.name()));
    List<PartitionTransformSpec> partitionTransformSpecList = SessionStateUtil.getResource(configuration, hive_metastoreConstants.PARTITION_TRANSFORM_SPEC).map(o -> (List<PartitionTransformSpec>) o).orElseGet(() -> null);
    partitionTransformSpecList.forEach(spec -> {
        switch(spec.getTransformType()) {
            case IDENTITY:
                updatePartitionSpec.addField(spec.getColumnName());
                break;
            case YEAR:
                updatePartitionSpec.addField(Expressions.year(spec.getColumnName()));
                break;
            case MONTH:
                updatePartitionSpec.addField(Expressions.month(spec.getColumnName()));
                break;
            case DAY:
                updatePartitionSpec.addField(Expressions.day(spec.getColumnName()));
                break;
            case HOUR:
                updatePartitionSpec.addField(Expressions.hour(spec.getColumnName()));
                break;
            case TRUNCATE:
                updatePartitionSpec.addField(Expressions.truncate(spec.getColumnName(), spec.getTransformParam().get()));
                break;
            case BUCKET:
                updatePartitionSpec.addField(Expressions.bucket(spec.getColumnName(), spec.getTransformParam().get()));
                break;
        }
    });
    updatePartitionSpec.commit();
}
Also used : PartitionTransformSpec(org.apache.hadoop.hive.ql.parse.PartitionTransformSpec) Properties(java.util.Properties) Logger(org.slf4j.Logger) Table(org.apache.iceberg.Table) Catalogs(org.apache.iceberg.mr.Catalogs) LoggerFactory(org.slf4j.LoggerFactory) Schema(org.apache.iceberg.Schema) List(java.util.List) UpdatePartitionSpec(org.apache.iceberg.UpdatePartitionSpec) Configuration(org.apache.hadoop.conf.Configuration) PartitionSpec(org.apache.iceberg.PartitionSpec) SessionStateUtil(org.apache.hadoop.hive.ql.session.SessionStateUtil) QueryState(org.apache.hadoop.hive.ql.QueryState) Expressions(org.apache.iceberg.expressions.Expressions) org.apache.hadoop.hive.metastore.api.hive_metastoreConstants(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants) UpdatePartitionSpec(org.apache.iceberg.UpdatePartitionSpec) List(java.util.List) UpdatePartitionSpec(org.apache.iceberg.UpdatePartitionSpec) PartitionSpec(org.apache.iceberg.PartitionSpec) PartitionTransformSpec(org.apache.hadoop.hive.ql.parse.PartitionTransformSpec)

Aggregations

List (java.util.List)1 Properties (java.util.Properties)1 Configuration (org.apache.hadoop.conf.Configuration)1 org.apache.hadoop.hive.metastore.api.hive_metastoreConstants (org.apache.hadoop.hive.metastore.api.hive_metastoreConstants)1 QueryState (org.apache.hadoop.hive.ql.QueryState)1 PartitionTransformSpec (org.apache.hadoop.hive.ql.parse.PartitionTransformSpec)1 SessionStateUtil (org.apache.hadoop.hive.ql.session.SessionStateUtil)1 PartitionSpec (org.apache.iceberg.PartitionSpec)1 Schema (org.apache.iceberg.Schema)1 Table (org.apache.iceberg.Table)1 UpdatePartitionSpec (org.apache.iceberg.UpdatePartitionSpec)1 Expressions (org.apache.iceberg.expressions.Expressions)1 Catalogs (org.apache.iceberg.mr.Catalogs)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1