Search in sources :

Example 6 with PartitionTransformSpec

use of org.apache.hadoop.hive.ql.parse.PartitionTransformSpec 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

PartitionTransformSpec (org.apache.hadoop.hive.ql.parse.PartitionTransformSpec)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Configuration (org.apache.hadoop.conf.Configuration)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 HiveStorageHandler (org.apache.hadoop.hive.ql.metadata.HiveStorageHandler)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 SessionStateUtil (org.apache.hadoop.hive.ql.session.SessionStateUtil)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 ListIterator (java.util.ListIterator)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1