boneanxs commented on code in PR #8452:
URL: https://github.com/apache/hudi/pull/8452#discussion_r1222426029


##########
hudi-common/src/main/java/org/apache/hudi/internal/schema/utils/Conversions.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.internal.schema.utils;
+
+import org.apache.hudi.internal.schema.Type;
+import org.apache.hudi.internal.schema.Types;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.UUID;
+
+public class Conversions {
+
+  private static final OffsetDateTime EPOCH = 
Instant.ofEpochSecond(0).atOffset(ZoneOffset.UTC);
+  private static final LocalDate EPOCH_DAY = EPOCH.toLocalDate();
+
+  private static final HashSet<Type.TypeID> SUPPORTED_PARTITION_TYPES = new 
HashSet<>(
+      Arrays.asList(Type.TypeID.INT,
+          Type.TypeID.LONG,
+          Type.TypeID.BOOLEAN,
+          Type.TypeID.FLOAT,
+          Type.TypeID.DECIMAL,
+          Type.TypeID.DOUBLE,
+          Type.TypeID.UUID,
+          Type.TypeID.DATE,
+          Type.TypeID.STRING));
+
+  public static boolean isSchemaSupportedConversion(Types.RecordType schema) {
+    for (Types.Field field: schema.fields()) {
+      if (!SUPPORTED_PARTITION_TYPES.contains(field.type().typeId())) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  public static Object fromPartitionString(String partitionValue, Type type) {

Review Comment:
   This is specially for partition values(more like a util method), but TypeId 
looks more generic. Should we move it there?



##########
hudi-common/src/main/java/org/apache/hudi/internal/schema/Types.java:
##########
@@ -523,18 +524,31 @@ public List<Field> fields() {
       return Arrays.asList(fields);
     }
 
-    public Field field(String name) {
+    /**
+     * Case-sensitive get field by name
+     */
+    public synchronized Field fieldByName(String name) {
       if (nameToFields == null) {
         nameToFields = new HashMap<>();
         for (Field field : fields) {
-          nameToFields.put(field.name().toLowerCase(Locale.ROOT), field);
+          nameToFields.put(field.name(), field);
+        }
+      }
+      return nameToFields.get(name);
+    }
+
+    public synchronized Field fieldByNameCaseInsensitive(String name) {
+      if (lowercaseNameToFields == null) {
+        lowercaseNameToFields = new HashMap<>();
+        for (Field field : fields) {
+          lowercaseNameToFields.put(field.name().toLowerCase(Locale.ROOT), 
field);
         }
       }
-      return nameToFields.get(name.toLowerCase(Locale.ROOT));
+      return lowercaseNameToFields.get(name.toLowerCase(Locale.ROOT));
     }
 
     @Override
-    public Field field(int id) {
+    public synchronized Field field(int id) {

Review Comment:
   Since all spark tests share the same JVM, it's possible that many threads 
running concurrently 
here(`org.apache.hudi.metadata.AbstractHoodieTableMetadata#extractPartitionValues`),
 one thread trying to initialize `idToFields`, while another thread trying to 
fetch field.
   
   Let me try to avoid it.



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