hudi-agent commented on code in PR #18539:
URL: https://github.com/apache/hudi/pull/18539#discussion_r3243506412


##########
hudi-flink-datasource/hudi-flink2.1.x/src/main/java/org/apache/hudi/adapter/DataTypeAdapter.java:
##########
@@ -25,11 +25,39 @@
 import org.apache.flink.table.types.logical.LogicalTypeRoot;
 import org.apache.flink.types.variant.BinaryVariant;
 import org.apache.flink.types.variant.Variant;
+import org.apache.hudi.common.util.Option;
+import org.apache.parquet.schema.LogicalTypeAnnotation;
+
+import java.lang.reflect.Method;
 
 /**
  * Adapter utils to provide {@code DataType} utilities.
  */
 public class DataTypeAdapter {
+
+  /**
+   * Cached VARIANT annotation resolved via reflection. Empty if parquet-java
+   * on the classpath predates {@code LogicalTypeAnnotation.variantType()} (< 
1.16.0).
+   */
+  private static final Option<LogicalTypeAnnotation> VARIANT_ANNOTATION = 
resolveVariantAnnotation();
+
+  private static Option<LogicalTypeAnnotation> resolveVariantAnnotation() {
+    try {
+      Method factory = LogicalTypeAnnotation.class.getMethod("variantType", 
byte.class);
+      return Option.of((LogicalTypeAnnotation) factory.invoke(null, (byte) 1));

Review Comment:
   🤖 nit: the bare `(byte) 1` here is a magic value — could you pull it into a 
named constant (e.g. `VARIANT_SPEC_VERSION`) or add a brief comment noting what 
it represents? Otherwise a future reader has to dig into parquet-java to 
understand why we pass `1`.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to