the-other-tim-brown commented on code in PR #742:
URL: https://github.com/apache/incubator-xtable/pull/742#discussion_r2486686539


##########
xtable-core/src/test/java/org/apache/xtable/paimon/TestPaimonSchemaExtractor.java:
##########
@@ -0,0 +1,538 @@
+/*
+ * 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.xtable.paimon;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.paimon.schema.TableSchema;
+import org.apache.paimon.types.ArrayType;
+import org.apache.paimon.types.BigIntType;
+import org.apache.paimon.types.BooleanType;
+import org.apache.paimon.types.CharType;
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DateType;
+import org.apache.paimon.types.DecimalType;
+import org.apache.paimon.types.DoubleType;
+import org.apache.paimon.types.FloatType;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.MapType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.types.SmallIntType;
+import org.apache.paimon.types.TimestampType;
+import org.apache.paimon.types.TinyIntType;
+import org.apache.paimon.types.VarCharType;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.schema.InternalSchema;
+import org.apache.xtable.model.schema.InternalType;
+
+public class TestPaimonSchemaExtractor {
+  private static final PaimonSchemaExtractor schemaExtractor = 
PaimonSchemaExtractor.getInstance();
+
+  private void assertField(DataField paimonField, InternalField 
expectedInternalField) {
+    assertField(paimonField, expectedInternalField, Collections.emptyList());
+  }
+
+  private void assertField(
+      DataField paimonField, InternalField expectedInternalField, List<String> 
primaryKeys) {
+    TableSchema paimonSchema =
+        new TableSchema(
+            0,
+            Collections.singletonList(paimonField),
+            0,
+            Collections.emptyList(),
+            primaryKeys,
+            new HashMap<>(),
+            "");
+    InternalSchema internalSchema = 
schemaExtractor.toInternalSchema(paimonSchema);
+    List<InternalField> recordKeyFields =
+        primaryKeys.isEmpty()
+            ? Collections.emptyList()
+            : Collections.singletonList(expectedInternalField);
+    InternalSchema expectedSchema =
+        InternalSchema.builder()
+            .name("record")
+            .dataType(InternalType.RECORD)
+            .fields(Collections.singletonList(expectedInternalField))
+            .recordKeyFields(recordKeyFields)
+            .build();
+    assertEquals(expectedSchema, internalSchema);
+  }
+
+  @Test
+  void testCharField() {
+    DataField paimonField = new DataField(0, "char_field", new CharType(10));
+    InternalField expectedField =
+        InternalField.builder()
+            .name("char_field")
+            .fieldId(0)
+            .schema(
+                InternalSchema.builder()
+                    .name("CHAR(10)")
+                    .dataType(InternalType.STRING)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testVarcharField() {
+    DataField paimonField = new DataField(1, "varchar_field", new 
VarCharType(255));
+    InternalField expectedField =
+        InternalField.builder()
+            .name("varchar_field")
+            .fieldId(1)
+            .schema(
+                InternalSchema.builder()
+                    .name("VARCHAR(255)")
+                    .dataType(InternalType.STRING)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testBooleanField() {
+    DataField paimonField = new DataField(2, "boolean_field", new 
BooleanType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("boolean_field")
+            .fieldId(2)
+            .schema(
+                InternalSchema.builder()
+                    .name("BOOLEAN")
+                    .dataType(InternalType.BOOLEAN)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testTinyIntField() {
+    DataField paimonField = new DataField(3, "tinyint_field", new 
TinyIntType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("tinyint_field")
+            .fieldId(3)
+            .schema(
+                InternalSchema.builder()
+                    .name("TINYINT")
+                    .dataType(InternalType.INT)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testSmallIntField() {
+    DataField paimonField = new DataField(4, "smallint_field", new 
SmallIntType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("smallint_field")
+            .fieldId(4)
+            .schema(
+                InternalSchema.builder()
+                    .name("SMALLINT")
+                    .dataType(InternalType.INT)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testIntField() {
+    DataField paimonField = new DataField(5, "int_field", new IntType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("int_field")
+            .fieldId(5)
+            .schema(
+                InternalSchema.builder()
+                    .name("INT")
+                    .dataType(InternalType.INT)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testBigIntField() {
+    DataField paimonField = new DataField(6, "bigint_field", new BigIntType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("bigint_field")
+            .fieldId(6)
+            .schema(
+                InternalSchema.builder()
+                    .name("BIGINT")
+                    .dataType(InternalType.LONG)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testFloatField() {
+    DataField paimonField = new DataField(7, "float_field", new FloatType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("float_field")
+            .fieldId(7)
+            .schema(
+                InternalSchema.builder()
+                    .name("FLOAT")
+                    .dataType(InternalType.FLOAT)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testDoubleField() {
+    DataField paimonField = new DataField(8, "double_field", new DoubleType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("double_field")
+            .fieldId(8)
+            .schema(
+                InternalSchema.builder()
+                    .name("DOUBLE")
+                    .dataType(InternalType.DOUBLE)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @Test
+  void testDateField() {
+    DataField paimonField = new DataField(9, "date_field", new DateType());
+    InternalField expectedField =
+        InternalField.builder()
+            .name("date_field")
+            .fieldId(9)
+            .schema(
+                InternalSchema.builder()
+                    .name("DATE")
+                    .dataType(InternalType.DATE)
+                    .isNullable(true)
+                    .build())
+            .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE)
+            .build();
+    assertField(paimonField, expectedField);
+  }
+
+  @ParameterizedTest
+  @ValueSource(ints = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
+  void testTimestampField(int precision) {
+    DataField paimonField = new DataField(10, "timestamp_field", new 
TimestampType(precision));
+    Map<InternalSchema.MetadataKey, Object> timestampMetadata =
+        Collections.singletonMap(
+            InternalSchema.MetadataKey.TIMESTAMP_PRECISION, 
InternalSchema.MetadataValue.MICROS);

Review Comment:
   This looks like a bug based on my understanding of the docs. It should be 
not always be micros 



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