@Override
  public void preTruncateTable(org.apache.hadoop.hive.metastore.api.Table table, EnvironmentContext context,
      List<String> partNames)
      throws MetaException {
    this.catalogProperties = getCatalogProperties(table);
    this.icebergTable = Catalogs.loadTable(conf, catalogProperties);
    Map<String, PartitionField> partitionFieldMap = icebergTable.spec().fields().stream()
        .collect(Collectors.toMap(PartitionField::name, Function.identity()));
    Expression finalExp = CollectionUtils.isEmpty(partNames) ? Expressions.alwaysTrue() : Expressions.alwaysFalse();
    if (partNames != null) {
      for (String partName : partNames) {
        Map<String, String> specMap = Warehouse.makeSpecFromName(partName);
        Expression subExp = Expressions.alwaysTrue();
        for (Map.Entry<String, String> entry : specMap.entrySet()) {
          String partColValue;
          // Since Iceberg encodes the values in UTF-8, we need to decode it.
          try {
            partColValue = URLDecoder.decode(entry.getValue(), "UTF-8");
          } catch (UnsupportedEncodingException e) {
            throw new MetaException(String.format("Unable to decode partition path values due to: %s", e));
          }
          if (partitionFieldMap.containsKey(entry.getKey())) {
            PartitionField partitionField = partitionFieldMap.get(entry.getKey());
            Type resultType = partitionField.transform().getResultType(icebergTable.schema()
                    .findField(partitionField.sourceId()).type());
            TransformSpec.TransformType transformType = TransformSpec.fromString(partitionField.transform().toString());
            Object value = Conversions.fromPartitionString(resultType, partColValue);
            Iterable iterable = () -> Collections.singletonList(value).iterator();
            if (TransformSpec.TransformType.IDENTITY.equals(transformType)) {
              Expression boundPredicate = Expressions.in(partitionField.name(), iterable);
              subExp = Expressions.and(subExp, boundPredicate);
            } else {
              throw new MetaException(
                  String.format("Partition transforms are not supported via truncate operation: %s", entry.getKey()));
            }
          } else {
            throw new MetaException(String.format("No partition column/transform name by the name: %s",
                entry.getKey()));
          }
        }
        finalExp = Expressions.or(finalExp, subExp);
      }
    }

    DeleteFiles delete = icebergTable.newDelete();
    String branchName = context.getProperties().get(Catalogs.SNAPSHOT_REF);
    if (branchName != null) {
      delete.toBranch(HiveUtils.getTableSnapshotRef(branchName));
    }
    delete.deleteFromRowFilter(finalExp);
    delete.commit();
    context.putToProperties("truncateSkipDataDeletion", "true");
  }
Checks if the table can be migrated to iceberg format. An eligible table is:
- external
- not temporary
- not acid
- uses one of supported file formats
@param hmsTable the table which should be migrated to iceberg, if eligible
@throws MetaException if the table is not eligible for migration due to violating one of the conditions above
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java