@Override
  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
      throw new UDFArgumentLengthException(
        "ICEBERG_HOUR requires 1 arguments (value), but got " + arguments.length);
    }

    if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
      throw new UDFArgumentException(
        "ICEBERG_HOUR first argument takes primitive types, got " + argumentOI.getTypeName());
    }
    argumentOI = (PrimitiveObjectInspector) arguments[0];

    PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory();
    ObjectInspector outputOI;
    switch (inputType) {
      case TIMESTAMP:
        converter = new PrimitiveObjectInspectorConverter.TimestampConverter(argumentOI,
          PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
        Function<Object, Integer> timestampTransform = Transforms.hour().bind(Types.TimestampType.withoutZone());
        evaluator = arg -> {
          TimestampWritableV2 val = (TimestampWritableV2) converter.convert(arg.get());
          result.set(timestampTransform.apply(Double.valueOf(val.getMicros()).longValue()));
        };
        break;

      case TIMESTAMPLOCALTZ:
        converter = new PrimitiveObjectInspectorConverter.TimestampLocalTZConverter(argumentOI,
          PrimitiveObjectInspectorFactory.writableTimestampTZObjectInspector);
        Function<Object, Integer> timestampLocalTzTransform = Transforms.hour().bind(Types.TimestampType.withZone());
        evaluator = arg -> {
          TimestampLocalTZWritable val = (TimestampLocalTZWritable) converter.convert(arg.get());
          result.set(timestampLocalTzTransform.apply(Double.valueOf(val.getMicros()).longValue()));
        };
        break;

      default:
        throw new UDFArgumentException(
          " ICEBERG_HOUR() only takes TIMESTAMP/TIMESTAMPLOCALTZ" +
          " types as first argument, got " + inputType);
    }
    outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    return outputOI;
  }
GenericUDFIcebergHour - UDF that wraps around Iceberg's hour transform function
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/udf/GenericUDFIcebergHour.java