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();
}
Aggregations