felixYyu commented on a change in pull request #3862:
URL: https://github.com/apache/iceberg/pull/3862#discussion_r780742434



##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java
##########
@@ -850,4 +865,47 @@ public String unknown(String sourceName, int sourceId, 
String transform,
       return String.format("%s(%s) %s %s", transform, sourceName, direction, 
nullOrder);
     }
   }
+
+  public static Object convertPartitionType(Object value, DataType dataType) {
+    if (value == null && dataType instanceof NullType) {
+      return null;
+    }
+    String old = String.valueOf(value);
+    if (dataType instanceof BooleanType) {
+      return DatatypeConverter.parseBoolean(old);
+    }
+    else if (dataType instanceof ByteType) {
+      return DatatypeConverter.parseByte(old);
+    }
+    else if (dataType instanceof ShortType) {
+      return DatatypeConverter.parseShort(old);
+    }
+    else if (dataType instanceof IntegerType) {
+      return DatatypeConverter.parseInt(old);
+    }
+    else if (dataType instanceof DateType) {
+      // days(ts) or date(ts) partition schema DataType
+      return DateTimeUtil.daysFromDate(LocalDate.parse(old));
+    }
+    else if (dataType instanceof FloatType) {
+      return DatatypeConverter.parseFloat(old);
+    }
+    else if (dataType instanceof DoubleType) {
+      return DatatypeConverter.parseDouble(old);
+    }
+    else if (dataType instanceof LongType) {
+      return DatatypeConverter.parseLong(old);
+    }
+    else if (dataType instanceof DecimalType) {
+      return DatatypeConverter.parseDecimal(old);
+    }
+    if (dataType instanceof BinaryType) {
+      return DatatypeConverter.parseHexBinary(old);
+    }
+    else if (dataType instanceof StringType) {
+      return UTF8String.fromString(old);
+    } else {
+      return value;
+    }

Review comment:
       fix




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to