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


##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/util/TestDataTypeUtils.java:
##########
@@ -81,4 +95,126 @@ public void testToHoodieSchema() {
     assertEquals(HoodieSchemaType.STRING,
         
requiredSchema.getField("missing").get().schema().getNonNullType().getType());
   }
+
+  @Test
+  void testTypePredicatesAndPrecision() {
+    assertTrue(DataTypeUtils.isTimestampType(DataTypes.TIMESTAMP(3)));
+    assertFalse(DataTypeUtils.isTimestampType(DataTypes.TIMESTAMP_LTZ(3)));
+    assertTrue(DataTypeUtils.isDateType(DataTypes.DATE()));
+    assertTrue(DataTypeUtils.isDatetimeType(DataTypes.DATE()));
+    assertTrue(DataTypeUtils.isDatetimeType(DataTypes.TIMESTAMP(3)));
+    assertFalse(DataTypeUtils.isDatetimeType(DataTypes.STRING()));
+    assertEquals(3, 
DataTypeUtils.precision(DataTypes.TIMESTAMP(3).getLogicalType()));
+    assertEquals(6, 
DataTypeUtils.precision(DataTypes.TIMESTAMP_LTZ(6).getLogicalType()));
+    assertThrows(AssertionError.class,
+        () -> DataTypeUtils.precision(DataTypes.STRING().getLogicalType()));
+    assertTrue(DataTypeUtils.isFamily(
+        DataTypes.INT().getLogicalType(), LogicalTypeFamily.NUMERIC));
+  }
+
+  @Test
+  void testRowTypeProjectionUtilities() {
+    Schema schema = Schema.newBuilder()
+        .column("id", DataTypes.INT())
+        .column("name", DataTypes.STRING())
+        .columnByExpression("computed", "id + 1")
+        .build();
+    RowType rowType = DataTypeUtils.toRowType(schema);
+
+    assertEquals(Arrays.asList("id", "name"), rowType.getFieldNames());
+    RowType projected = (RowType) DataTypes.ROW(
+        DataTypes.FIELD("name", DataTypes.STRING()),
+        DataTypes.FIELD("id", DataTypes.INT()))
+        .getLogicalType();
+    assertArrayEquals(new int[] {1, 0}, DataTypeUtils.projectOrdinals(rowType, 
projected));
+    assertEquals(Arrays.asList("name", "id"), Arrays.asList(
+        DataTypeUtils.projectRowFields(rowType, new String[] {"name", 
"id"})[0].getName(),
+        DataTypeUtils.projectRowFields(rowType, new String[] {"name", 
"id"})[1].getName()));
+  }

Review Comment:
   🤖 nit: `projectRowFields(rowType, new String[]{"name", "id"})` is invoked 
twice here just to read two elements — could you assign it to a local 
`HoodieSchemaField[]` (or similar) once and index into it? Reads cleaner and 
avoids the double call.
   
   <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