You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2023/09/07 06:25:42 UTC

[GitHub] [spark] zhengruifeng opened a new pull request, #42847: [WIP] ArrowUtils support CalendarIntervalType

zhengruifeng opened a new pull request, #42847:
URL: https://github.com/apache/spark/pull/42847

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] hvanhovell commented on a diff in pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1323190219


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowWriter.scala:
##########
@@ -464,3 +466,15 @@ private[arrow] class DurationWriter(val valueVector: DurationVector)
     valueVector.set(count, input.getLong(ordinal))
   }
 }
+
+private[arrow] class IntervalMonthDayNanoWriter(val valueVector: IntervalMonthDayNanoVector)
+  extends ArrowFieldWriter {
+  override def setNull(): Unit = {
+    valueVector.setNull(count)
+  }
+
+  override def setValue(input: SpecializedGetters, ordinal: Int): Unit = {
+    val ci = input.getInterval(ordinal)
+    valueVector.setSafe(count, ci.months, ci.days, ci.microseconds * 1000)

Review Comment:
   Should add an overflow check 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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] HyukjinKwon closed pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow
URL: https://github.com/apache/spark/pull/42847


-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] HyukjinKwon commented on pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #42847:
URL: https://github.com/apache/spark/pull/42847#issuecomment-1720788409

   Merged to master.


-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1323871670


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowWriter.scala:
##########
@@ -464,3 +466,15 @@ private[arrow] class DurationWriter(val valueVector: DurationVector)
     valueVector.set(count, input.getLong(ordinal))
   }
 }
+
+private[arrow] class IntervalMonthDayNanoWriter(val valueVector: IntervalMonthDayNanoVector)
+  extends ArrowFieldWriter {
+  override def setNull(): Unit = {
+    valueVector.setNull(count)
+  }
+
+  override def setValue(input: SpecializedGetters, ordinal: Int): Unit = {
+    val ci = input.getInterval(ordinal)
+    valueVector.setSafe(count, ci.months, ci.days, ci.microseconds * 1000)

Review Comment:
   done, switch to `Math.multiplyExact` which is widely used in DateTimes and Intervals.



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1320901889


##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   I think no need to follow how we're doing with Spark internal format .. - we can just provide the input and output consistently .. how to handle shouldn't matter



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1322582952


##########
sql/catalyst/src/main/java/org/apache/spark/sql/vectorized/ColumnVector.java:
##########
@@ -289,7 +289,7 @@ public final ColumnarRow getStruct(int rowId) {
    * is a long type vector, containing all the microsecond values of all the interval values in this
    * vector.
    */
-  public final CalendarInterval getInterval(int rowId) {
+  public CalendarInterval getInterval(int rowId) {

Review Comment:
   if this approach is fine, I will need to update the comments above:
   
   >  To support interval type, implementations must implement {@link #getChild(int)} and define 3
   >    * child vectors: the first child vector is an int type vector, containing all the month values of
   >    * all the interval values in this vector. The second child vector is an int type vector,
   >    * containing all the day values of all the interval values in this vector. The third child vector
   >    * is a long type vector, containing all the microsecond values of all the interval values in this
   >    * vector.



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1320899339


##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   But I found the `getInterval` in `ColumnVector.scala`, not sure whether we should follow it?



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1320899115


##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   yes, `org.apache.arrow.vector.IntervalMonthDayNanoVector` and `org.apache.arrow.vector.PeriodDuration`



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1323808019


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowWriter.scala:
##########
@@ -464,3 +466,15 @@ private[arrow] class DurationWriter(val valueVector: DurationVector)
     valueVector.set(count, input.getLong(ordinal))
   }
 }
+
+private[arrow] class IntervalMonthDayNanoWriter(val valueVector: IntervalMonthDayNanoVector)
+  extends ArrowFieldWriter {
+  override def setNull(): Unit = {
+    valueVector.setNull(count)
+  }
+
+  override def setValue(input: SpecializedGetters, ordinal: Int): Unit = {
+    val ci = input.getInterval(ordinal)
+    valueVector.setSafe(count, ci.months, ci.days, ci.microseconds * 1000)

Review Comment:
   ok, let me add it



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #42847:
URL: https://github.com/apache/spark/pull/42847#issuecomment-1709549020

   I found there was
   
   https://github.com/apache/spark/blob/c74506cc33bc0a41a869b4184eaf7c7bfa1dcc91/sql/catalyst/src/main/java/org/apache/spark/sql/vectorized/ColumnVector.java#L275-L298
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1320902565


##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   I mean, external ser/de with Arrow should use that corresponding types ideally. Internal ser/de we can use our existing `getInterval` approach from Arrow batch.



##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   I mean, external ser/de with Arrow and Arrow schema should use that corresponding types ideally. Internal ser/de we can use our existing `getInterval` approach from Arrow batch.



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] HyukjinKwon commented on a diff in pull request #42847: [WIP] ArrowUtils support CalendarIntervalType

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1320898412


##########
sql/api/src/main/scala/org/apache/spark/sql/util/ArrowUtils.scala:
##########
@@ -118,6 +118,18 @@ private[sql] object ArrowUtils {
             nullable = false,
             timeZoneId,
             largeVarTypes)).asJava)
+      case CalendarIntervalType =>
+        val fields = Seq(

Review Comment:
   Hm, can we try to find the equivalent type in Arrow? e.g., https://arrow.apache.org/docs/cpp/api/datatype.html#_CPPv4N5arrow4Type4type23INTERVAL_MONTH_DAY_NANOE



-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on pull request #42847: [SPARK-45128][SQL] Support `CalendarIntervalType` in Arrow

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #42847:
URL: https://github.com/apache/spark/pull/42847#issuecomment-1715165201

   also cc @hvanhovell @cloud-fan @ueshin 


-- 
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: reviews-unsubscribe@spark.apache.org

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


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


[GitHub] [spark] zhengruifeng commented on a diff in pull request #42847: [WIP] Support `CalendarIntervalType` in Arrow

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #42847:
URL: https://github.com/apache/spark/pull/42847#discussion_r1321464833


##########
sql/catalyst/src/main/java/org/apache/spark/sql/vectorized/ArrowColumnVector.java:
##########
@@ -112,6 +114,12 @@ public UTF8String getUTF8String(int rowId) {
     return accessor.getUTF8String(rowId);
   }
 
+  @Override
+  public CalendarInterval getInterval(int rowId) {

Review Comment:
   need to override `ColumnVector#getInterval` to add the tests



-- 
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: reviews-unsubscribe@spark.apache.org

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


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