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 in lower version 
so added the checks here.
   
   Since the above two utils do a direct scala `match` without matching when 
none of the scenarios matched, which would result in exception, added 
UnsupportedOperationException here as well.



-- 
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-unsubscr...@iceberg.apache.org

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


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

Reply via email to