the-other-tim-brown commented on code in PR #14265:
URL: https://github.com/apache/hudi/pull/14265#discussion_r2548094067


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaField.java:
##########
@@ -0,0 +1,393 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.schema;
+
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+
+import org.apache.avro.Schema;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Wrapper class for Avro Schema.Field that provides Hudi-specific field 
functionality
+ * while maintaining binary compatibility with Avro.
+ *
+ * <p>This class encapsulates an Avro Schema.Field and provides a consistent 
interface
+ * for field operations across the Hudi codebase. It maintains full 
compatibility with
+ * Avro by delegating all operations to the underlying Avro field.</p>
+ *
+ * <p>Usage example:
+ * <pre>{@code
+ * // Create from Avro field
+ * Schema.Field avroField = new Schema.Field("name", 
Schema.create(Schema.Type.STRING));
+ * HoodieSchemaField hoodieField = HoodieSchemaField.fromAvroField(avroField);
+ *
+ * // Access field properties
+ * String name = hoodieField.name();
+ * HoodieSchema schema = hoodieField.schema();
+ * Option<Object> defaultValue = hoodieField.defaultVal();
+ * }</pre></p>
+ *
+ * @since 1.2.0
+ */
+public class HoodieSchemaField implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+
+  private final Schema.Field avroField;
+  private final HoodieSchema hoodieSchema;
+
+  /**
+   * Creates a new HoodieSchemaField wrapping the given Avro field.
+   *
+   * @param avroField the Avro field to wrap, cannot be null
+   */
+  public HoodieSchemaField(Schema.Field avroField) {
+    ValidationUtils.checkArgument(avroField != null, "Avro field cannot be 
null");
+    this.avroField = avroField;
+    this.hoodieSchema = HoodieSchema.fromAvroSchema(avroField.schema());
+  }
+
+  /**
+   * Factory method to create HoodieSchemaField from an Avro field.
+   *
+   * @param avroField the Avro field to wrap
+   * @return new HoodieSchemaField instance
+   * @throws IllegalArgumentException if avroField is null
+   */
+  public static HoodieSchemaField fromAvroField(Schema.Field avroField) {
+    return new HoodieSchemaField(avroField);
+  }
+
+  /**
+   * Creates a new HoodieSchemaField with the specified properties.
+   *
+   * @param name       the name of the field
+   * @param schema     the schema of the field
+   * @param doc        the documentation string, can be null
+   * @param defaultVal the default value, can be null
+   * @return new HoodieSchemaField instance
+   */
+  public static HoodieSchemaField of(String name, HoodieSchema schema, String 
doc, Object defaultVal) {
+    return of(name, schema, doc, defaultVal, HoodieFieldOrder.ASCENDING);
+  }
+
+  /**
+   * Creates a new HoodieSchemaField with the specified properties, including 
field order.
+   *
+   * @param name       the name of the field
+   * @param schema     the schema of the field
+   * @param doc        the documentation string, can be null
+   * @param defaultVal the default value, can be null
+   * @param order      the field order for sorting
+   * @return new HoodieSchemaField instance
+   */
+  public static HoodieSchemaField of(String name, HoodieSchema schema, String 
doc, Object defaultVal, HoodieFieldOrder order) {
+    ValidationUtils.checkArgument(name != null && !name.isEmpty(), "Field name 
cannot be null or empty");
+    ValidationUtils.checkArgument(schema != null, "Field schema cannot be 
null");
+    ValidationUtils.checkArgument(order != null, "Field order cannot be null");
+
+    Schema avroSchema = schema.getAvroSchema();
+    ValidationUtils.checkState(avroSchema != null, "Schema's Avro schema 
cannot be null");
+
+    Schema.Field avroField = new Schema.Field(name, avroSchema, doc, 
defaultVal, order.toAvroOrder());

Review Comment:
   Thanks for pointing this out, I have updated all the callers in this class



-- 
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