jonvex commented on code in PR #13711:
URL: https://github.com/apache/hudi/pull/13711#discussion_r2355892453


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/utils/SparkValueMetadata.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.client.utils;
+
+import org.apache.hudi.SparkAdapterSupport$;
+import org.apache.hudi.avro.ValueMetadata;
+import org.apache.hudi.avro.ValueType;
+import org.apache.hudi.avro.model.HoodieValueTypeInfo;
+import org.apache.hudi.common.util.collection.ArrayComparable;
+import org.apache.hudi.metadata.HoodieIndexVersion;
+
+import org.apache.spark.sql.types.ArrayType;
+import org.apache.spark.sql.types.BinaryType;
+import org.apache.spark.sql.types.BooleanType;
+import org.apache.spark.sql.types.ByteType;
+import org.apache.spark.sql.types.CharType;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DateType;
+import org.apache.spark.sql.types.Decimal;
+import org.apache.spark.sql.types.DecimalType;
+import org.apache.spark.sql.types.DoubleType;
+import org.apache.spark.sql.types.FloatType;
+import org.apache.spark.sql.types.IntegerType;
+import org.apache.spark.sql.types.LongType;
+import org.apache.spark.sql.types.NullType;
+import org.apache.spark.sql.types.ShortType;
+import org.apache.spark.sql.types.StringType;
+import org.apache.spark.sql.types.TimestampType;
+import org.apache.spark.sql.types.VarcharType;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.util.Arrays;
+
+public class SparkValueMetadata extends ValueMetadata {
+
+  private final DataType dataType;
+
+  protected SparkValueMetadata(ValueType valueType, DataType dataType) {
+    super(valueType);
+    this.dataType = dataType;
+  }
+
+  public Comparable convertSparkToJava(Object value) {
+    return convertSparkToJava(value, true);
+  }
+
+  public static SparkValueMetadata getValueMetadata(DataType dataType, 
HoodieIndexVersion indexVersion) {
+    if (indexVersion.lowerThan(HoodieIndexVersion.V2)) {
+      return SparkV1EmptyMetadata.get();
+    }
+    if (dataType == null) {
+      return new SparkValueMetadata(ValueType.NULL, null);
+    }
+    ValueType valueType = fromDataType(dataType);
+    if (valueType == ValueType.DECIMAL) {
+      return new SparkDecimalMetadata((DecimalType) dataType);
+    } else {
+      return new SparkValueMetadata(valueType, dataType);
+    }
+  }
+
+  private static ValueType fromDataType(DataType dataType) {
+    return fromDataType(dataType, true);
+  }
+
+  private static ValueType fromDataType(DataType dataType, boolean root) {
+    if (dataType instanceof NullType) {
+      return ValueType.NULL;
+    } else if (dataType instanceof BooleanType) {
+      return ValueType.BOOLEAN;
+    } else if (dataType instanceof IntegerType || dataType instanceof 
ShortType || dataType instanceof ByteType) {
+      return ValueType.INT;
+    } else if (dataType instanceof LongType) {
+      return ValueType.LONG;
+    } else if (dataType instanceof FloatType) {
+      return ValueType.FLOAT;
+    } else if (dataType instanceof DoubleType) {
+      return ValueType.DOUBLE;
+    } else if (dataType instanceof StringType || dataType instanceof CharType 
|| dataType instanceof VarcharType) {
+      return ValueType.STRING;
+    }  else if (dataType instanceof TimestampType) {
+      return ValueType.TIMESTAMP_MICROS;
+    }  else if (dataType instanceof DecimalType) {
+      return ValueType.DECIMAL;
+    } else if (dataType instanceof DateType) {
+      return ValueType.DATE;
+    } else if (dataType instanceof BinaryType) {
+      return ValueType.BYTES;
+    } else if (dataType instanceof ArrayType) {
+      if (root) {
+        return fromDataType(((ArrayType) dataType).elementType(), false);
+      } else {
+        throw new IllegalArgumentException("Array of Array is not supported");
+      }
+    } else if 
(SparkAdapterSupport$.MODULE$.sparkAdapter().isTimestampNTZType(dataType)) {
+      return ValueType.LOCAL_TIMESTAMP_MICROS;
+    } else {
+      throw new IllegalArgumentException("Unsupported data type: " + dataType);
+    }
+  }
+
+  private static class SparkV1EmptyMetadata extends SparkValueMetadata {
+    private static final SparkV1EmptyMetadata V_1_EMPTY_METADATA = new 
SparkV1EmptyMetadata();

Review Comment:
   no more spark value metadata



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/utils/SparkValueMetadata.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * 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.client.utils;
+
+import org.apache.hudi.SparkAdapterSupport$;
+import org.apache.hudi.avro.ValueMetadata;
+import org.apache.hudi.avro.ValueType;
+import org.apache.hudi.avro.model.HoodieValueTypeInfo;
+import org.apache.hudi.common.util.collection.ArrayComparable;
+import org.apache.hudi.metadata.HoodieIndexVersion;
+
+import org.apache.spark.sql.types.ArrayType;
+import org.apache.spark.sql.types.BinaryType;
+import org.apache.spark.sql.types.BooleanType;
+import org.apache.spark.sql.types.ByteType;
+import org.apache.spark.sql.types.CharType;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DateType;
+import org.apache.spark.sql.types.Decimal;
+import org.apache.spark.sql.types.DecimalType;
+import org.apache.spark.sql.types.DoubleType;
+import org.apache.spark.sql.types.FloatType;
+import org.apache.spark.sql.types.IntegerType;
+import org.apache.spark.sql.types.LongType;
+import org.apache.spark.sql.types.NullType;
+import org.apache.spark.sql.types.ShortType;
+import org.apache.spark.sql.types.StringType;
+import org.apache.spark.sql.types.TimestampType;
+import org.apache.spark.sql.types.VarcharType;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.util.Arrays;
+
+public class SparkValueMetadata extends ValueMetadata {
+
+  private final DataType dataType;
+
+  protected SparkValueMetadata(ValueType valueType, DataType dataType) {
+    super(valueType);
+    this.dataType = dataType;
+  }
+
+  public Comparable convertSparkToJava(Object value) {
+    return convertSparkToJava(value, true);
+  }
+
+  public static SparkValueMetadata getValueMetadata(DataType dataType, 
HoodieIndexVersion indexVersion) {
+    if (indexVersion.lowerThan(HoodieIndexVersion.V2)) {
+      return SparkV1EmptyMetadata.get();
+    }
+    if (dataType == null) {
+      return new SparkValueMetadata(ValueType.NULL, null);
+    }
+    ValueType valueType = fromDataType(dataType);
+    if (valueType == ValueType.DECIMAL) {
+      return new SparkDecimalMetadata((DecimalType) dataType);
+    } else {
+      return new SparkValueMetadata(valueType, dataType);
+    }
+  }
+
+  private static ValueType fromDataType(DataType dataType) {
+    return fromDataType(dataType, true);
+  }
+
+  private static ValueType fromDataType(DataType dataType, boolean root) {
+    if (dataType instanceof NullType) {
+      return ValueType.NULL;
+    } else if (dataType instanceof BooleanType) {
+      return ValueType.BOOLEAN;
+    } else if (dataType instanceof IntegerType || dataType instanceof 
ShortType || dataType instanceof ByteType) {
+      return ValueType.INT;
+    } else if (dataType instanceof LongType) {
+      return ValueType.LONG;
+    } else if (dataType instanceof FloatType) {
+      return ValueType.FLOAT;
+    } else if (dataType instanceof DoubleType) {
+      return ValueType.DOUBLE;
+    } else if (dataType instanceof StringType || dataType instanceof CharType 
|| dataType instanceof VarcharType) {
+      return ValueType.STRING;
+    }  else if (dataType instanceof TimestampType) {
+      return ValueType.TIMESTAMP_MICROS;
+    }  else if (dataType instanceof DecimalType) {
+      return ValueType.DECIMAL;
+    } else if (dataType instanceof DateType) {
+      return ValueType.DATE;
+    } else if (dataType instanceof BinaryType) {
+      return ValueType.BYTES;
+    } else if (dataType instanceof ArrayType) {
+      if (root) {
+        return fromDataType(((ArrayType) dataType).elementType(), false);
+      } else {
+        throw new IllegalArgumentException("Array of Array is not supported");
+      }
+    } else if 
(SparkAdapterSupport$.MODULE$.sparkAdapter().isTimestampNTZType(dataType)) {
+      return ValueType.LOCAL_TIMESTAMP_MICROS;
+    } else {
+      throw new IllegalArgumentException("Unsupported data type: " + dataType);
+    }
+  }
+
+  private static class SparkV1EmptyMetadata extends SparkValueMetadata {

Review Comment:
   removed
   



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