[GitHub] [spark] HyukjinKwon commented on a change in pull request #28993: [SPARK-32168][SQL] Fix hidden partitioning correctness bug in SQL overwrite

2020-07-08 Thread GitBox


HyukjinKwon commented on a change in pull request #28993:
URL: https://github.com/apache/spark/pull/28993#discussion_r451898804



##
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/InMemoryTable.scala
##
@@ -78,10 +92,44 @@ class InMemoryTable(
 throw new IllegalArgumentException(s"Unsupported type, 
${dataType.simpleString}")
 }
   } else {
-value
+(value, schema(index).dataType)
   }
 }
-partCols.map(fieldNames => extractor(fieldNames, schema, row))
+
+partitioning.map {
+  case IdentityTransform(ref) =>
+extractor(ref.fieldNames, schema, row)._1
+  case YearsTransform(ref) =>
+extractor(ref.fieldNames, schema, row) match {
+  case (days: Int, DateType) =>
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, 
DateTimeUtils.daysToLocalDate(days))
+  case (micros: Long, TimestampType) =>
+val localDate = 
DateTimeUtils.microsToInstant(micros).atZone(UTC).toLocalDate
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, localDate)

Review comment:
   Sure, sorry it was clearly my misunderstanding. LGTM.





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.

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



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



[GitHub] [spark] HyukjinKwon commented on a change in pull request #28993: [SPARK-32168][SQL] Fix hidden partitioning correctness bug in SQL overwrite

2020-07-07 Thread GitBox


HyukjinKwon commented on a change in pull request #28993:
URL: https://github.com/apache/spark/pull/28993#discussion_r451292098



##
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/InMemoryTable.scala
##
@@ -78,10 +92,44 @@ class InMemoryTable(
 throw new IllegalArgumentException(s"Unsupported type, 
${dataType.simpleString}")
 }
   } else {
-value
+(value, schema(index).dataType)
   }
 }
-partCols.map(fieldNames => extractor(fieldNames, schema, row))
+
+partitioning.map {
+  case IdentityTransform(ref) =>
+extractor(ref.fieldNames, schema, row)._1
+  case YearsTransform(ref) =>
+extractor(ref.fieldNames, schema, row) match {
+  case (days: Int, DateType) =>
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, 
DateTimeUtils.daysToLocalDate(days))
+  case (micros: Long, TimestampType) =>
+val localDate = 
DateTimeUtils.microsToInstant(micros).atZone(UTC).toLocalDate
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, localDate)

Review comment:
   Oh! It was in the test!





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.

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



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



[GitHub] [spark] HyukjinKwon commented on a change in pull request #28993: [SPARK-32168][SQL] Fix hidden partitioning correctness bug in SQL overwrite

2020-07-07 Thread GitBox


HyukjinKwon commented on a change in pull request #28993:
URL: https://github.com/apache/spark/pull/28993#discussion_r451234819



##
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/InMemoryTable.scala
##
@@ -78,10 +92,44 @@ class InMemoryTable(
 throw new IllegalArgumentException(s"Unsupported type, 
${dataType.simpleString}")
 }
   } else {
-value
+(value, schema(index).dataType)
   }
 }
-partCols.map(fieldNames => extractor(fieldNames, schema, row))
+
+partitioning.map {
+  case IdentityTransform(ref) =>
+extractor(ref.fieldNames, schema, row)._1
+  case YearsTransform(ref) =>
+extractor(ref.fieldNames, schema, row) match {
+  case (days: Int, DateType) =>
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, 
DateTimeUtils.daysToLocalDate(days))
+  case (micros: Long, TimestampType) =>
+val localDate = 
DateTimeUtils.microsToInstant(micros).atZone(UTC).toLocalDate
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, localDate)

Review comment:
   Hm .. @rdblue, will this be the default behaviour for these partitioning 
expressions? I wonder what happens if other datasources implement these in a 
different way, for example, some expressions might respect Spark session 
timezone.





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.

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



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



[GitHub] [spark] HyukjinKwon commented on a change in pull request #28993: [SPARK-32168][SQL] Fix hidden partitioning correctness bug in SQL overwrite

2020-07-07 Thread GitBox


HyukjinKwon commented on a change in pull request #28993:
URL: https://github.com/apache/spark/pull/28993#discussion_r451234819



##
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/InMemoryTable.scala
##
@@ -78,10 +92,44 @@ class InMemoryTable(
 throw new IllegalArgumentException(s"Unsupported type, 
${dataType.simpleString}")
 }
   } else {
-value
+(value, schema(index).dataType)
   }
 }
-partCols.map(fieldNames => extractor(fieldNames, schema, row))
+
+partitioning.map {
+  case IdentityTransform(ref) =>
+extractor(ref.fieldNames, schema, row)._1
+  case YearsTransform(ref) =>
+extractor(ref.fieldNames, schema, row) match {
+  case (days: Int, DateType) =>
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, 
DateTimeUtils.daysToLocalDate(days))
+  case (micros: Long, TimestampType) =>
+val localDate = 
DateTimeUtils.microsToInstant(micros).atZone(UTC).toLocalDate
+ChronoUnit.YEARS.between(EPOCH_LOCAL_DATE, localDate)

Review comment:
   Hm .. @rdblue, will this be the default behaviour for these partitioning 
expressions? I wonder what happens if other datasources implement these in a 
different implementation. For example, some expressions might respect Spark 
session timezone.





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.

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



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