bvaradar commented on code in PR #14265:
URL: https://github.com/apache/hudi/pull/14265#discussion_r2539060254


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaType.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.avro.Schema;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enumeration of all schema types supported by Hudi schema system.
+ *
+ * <p>This enum wraps Avro's Schema.Type to provide a consistent interface
+ * for schema type handling while maintaining binary compatibility with Avro.
+ * Each Hudi schema type corresponds directly to an Avro schema type.</p>
+ *
+ * <p>Usage example:
+ * <pre>{@code
+ * HoodieSchemaType type = HoodieSchemaType.STRING;
+ * Schema.Type avroType = type.toAvroType();
+ * HoodieSchemaType backToHudi = HoodieSchemaType.fromAvroType(avroType);
+ * }</pre></p>
+ *
+ * @since 1.2.0
+ */
+public enum HoodieSchemaType {

Review Comment:
   Good point. Can we add this in the follow up PR. 



##########
hudi-common/src/test/java/org/apache/hudi/common/schema/TestHoodieSchema.java:
##########
@@ -0,0 +1,579 @@
+/*
+ * 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.exception.HoodieAvroSchemaException;
+
+import org.apache.avro.JsonProperties;
+import org.apache.avro.Schema;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test class for {@link HoodieSchema}.
+ */
+public class TestHoodieSchema {
+
+  private static final String SAMPLE_RECORD_SCHEMA =

Review Comment:
   Sure



##########
hudi-common/src/test/java/org/apache/hudi/common/schema/TestHoodieSchemaUtils.java:
##########
@@ -0,0 +1,350 @@
+/*
+ * 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.avro.AvroSchemaUtils;
+import org.apache.hudi.avro.HoodieAvroUtils;
+
+import org.apache.avro.Schema;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link HoodieSchemaUtils}.
+ */
+public class TestHoodieSchemaUtils {
+
+  private static final String SIMPLE_SCHEMA = "{"
+      + "\"type\":\"record\","
+      + "\"name\":\"TestRecord\","
+      + "\"fields\":["
+      + "{\"name\":\"id\",\"type\":\"string\"},"
+      + "{\"name\":\"name\",\"type\":\"string\"}"
+      + "]}";
+
+  private static final String EVOLVED_SCHEMA = "{"
+      + "\"type\":\"record\","
+      + "\"name\":\"TestRecord\","
+      + "\"fields\":["
+      + "{\"name\":\"id\",\"type\":\"string\"},"
+      + "{\"name\":\"name\",\"type\":\"string\"},"
+      + "{\"name\":\"age\",\"type\":[\"null\",\"int\"],\"default\":null}"
+      + "]}";
+
+  @Test
+  public void testCreateHoodieWriteSchema() {
+    // Test with operation field
+    HoodieSchema writeSchemaWithOp = 
HoodieSchemaUtils.createHoodieWriteSchema(SIMPLE_SCHEMA, true);
+
+    assertNotNull(writeSchemaWithOp);
+    assertEquals(HoodieSchemaType.RECORD, writeSchemaWithOp.getType());
+
+    // Should have original fields plus metadata fields
+    List<HoodieSchemaField> fields = writeSchemaWithOp.getFields();
+    assertTrue(fields.size() > 2); // Original 2 fields + metadata fields
+
+    // Test without operation field
+    HoodieSchema writeSchemaNoOp = 
HoodieSchemaUtils.createHoodieWriteSchema(SIMPLE_SCHEMA, false);
+
+    assertNotNull(writeSchemaNoOp);
+    assertEquals(HoodieSchemaType.RECORD, writeSchemaNoOp.getType());
+
+    // Should have different number of fields
+    assertNotNull(writeSchemaNoOp.getFields());

Review Comment:
   yes, I agree



##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieFieldOrder.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.avro.Schema;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enumeration of field sort orders supported by Hudi schema system.
+ *
+ * <p>This enum wraps Avro's Schema.Field.Order to provide a consistent 
interface
+ * for field ordering while maintaining binary compatibility with Avro.</p>
+ *
+ * @since 1.2.0
+ */
+public enum HoodieFieldOrder {

Review Comment:
   @the-other-tim-brown As we are using composition pattern (and not 
inheritance), the order would need to be supported. right ? Anyways, when you 
take over this PR, can you look into if this is needed and remove it if not 
needed.



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