You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/11/15 02:45:20 UTC

[GitHub] [iceberg] singhpk234 commented on a diff in pull request #6190: Spark: Backport #5860 to spark 3.x

singhpk234 commented on code in PR #6190:
URL: https://github.com/apache/iceberg/pull/6190#discussion_r1022261543


##########
spark/v3.1/spark/src/main/java/org/apache/iceberg/spark/SparkValueConverter.java:
##########
@@ -70,9 +72,25 @@ public static Object convert(Type type, Object object) {
         return convertedMap;
 
       case DATE:
-        return DateTimeUtils.fromJavaDate((Date) object);
+        // if spark.sql.datetime.java8API.enabled is set to true, java.time.LocalDate
+        // for Spark SQL DATE type otherwise java.sql.Date is returned.
+        if (object instanceof Date) {
+          return DateTimeUtils.fromJavaDate((Date) object);
+        } else if (object instanceof LocalDate) {
+          return DateTimeUtils.localDateToDays((LocalDate) object);
+        } else {
+          throw new UnsupportedOperationException("Not a supported date class: " + object);
+        }

Review Comment:
   DateTimeUtils#anyToDays & DateTimeUtils#anyToMicros utils were introduced at part of this [commit](anyToMicros) of 3.3.0 hence not present here.
   
   Since the above two utils do a scala `match` without fallback if none of the scenarios matched, added UnsupportedOperationException here.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org