You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynr (via GitHub)" <gi...@apache.org> on 2024/03/29 15:13:05 UTC

[PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

waynr opened a new pull request, #40889:
URL: https://github.com/apache/arrow/pull/40889

   
   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   To enable the use of the flightsql driver's implementation of golang sql interfaces.
   
   ### What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   A new case statement branch for handling `array.Duration`.
   
   ### Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   I manually tested and didn't add new unit tests because none of the other types handled in the same case statement are unit tested.
   
   ### Are there any user-facing changes?
   
   Just a more complete set of types handled by the sql driver.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical 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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #40889:
URL: https://github.com/apache/arrow/pull/40889#discussion_r1546434319


##########
go/arrow/flight/flightsql/driver/utils_test.go:
##########
@@ -123,4 +125,10 @@ func Test_fromArrowType(t *testing.T) {
 	tf(t, 14, time.Date(1970, 1, 1, 12, 0, 0, 0, time.UTC))  // "f15-ts_us"
 	tf(t, 15, testTime.In(time.UTC).Truncate(24*time.Hour))  // "f16-d64"
 	tf(t, 16, time.Duration(24*time.Hour+time.Second))       // "f17-dti"
+	// according to
+	// https://github.com/apache/arrow/blob/50ca7a76d38e6ecf19589bc44f46bffd1db0d4c8/format/Schema.fbs#L420-L435
+	// the default "TimeUnit" for an arrow.Duration is in microseconds but golang
+	// Durations are int64 nanoseconds so we verify here that the
+	// array.Duration(1) we create above shows up as a 1000 nanoseconds
+	tf(t, 17, time.Duration(1000)) // "f18-duration_ms"

Review Comment:
   the comment should be `f18-duration_us`



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "waynr (via GitHub)" <gi...@apache.org>.
waynr commented on PR #40889:
URL: https://github.com/apache/arrow/pull/40889#issuecomment-2027388574

   > I manually tested and didn't add new unit tests because none of the other types handled in the same switch block are unit tested.
   
   Whoops, this actually isn't true. I'm working on adding test case(s) now.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #40889:
URL: https://github.com/apache/arrow/pull/40889#discussion_r1546429531


##########
go/arrow/flight/flightsql/driver/utils.go:
##########
@@ -104,6 +104,13 @@ func fromArrowType(arr arrow.Array, idx int) (interface{}, error) {
 		return v.ToTime(ts.TimeUnit()), nil
 	case *array.Date64:
 		return c.Value(idx).ToTime(), nil
+	case *array.Duration:
+    // according to
+    // https://github.com/apache/arrow/blob/50ca7a76d38e6ecf19589bc44f46bffd1db0d4c8/format/Schema.fbs#L420-L435
+    // the default "TimeUnit" for an arrow.Duration is in microseconds but
+    // golang Durations are int64 nanoseconds
+		duration := time.Duration(int64(c.Value(idx) * 1000))

Review Comment:
   this should probably be `time.Duration(int64(c.Value(idx))) * arr.DataType().(*arrow.Duration).TimeUnit.Multiplier()` in order to produce nanoseconds. Or something to that end. Like the other types, you need to use the `TimeUnit` to determine what unit the values are in for durations, you can't just blindly multiply by 1000.



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #40889:
URL: https://github.com/apache/arrow/pull/40889#discussion_r1546430093


##########
go/arrow/flight/flightsql/driver/utils_test.go:
##########
@@ -50,6 +50,7 @@ func Test_fromArrowType(t *testing.T) {
 		{Name: "f15-ts_us", Type: arrow.FixedWidthTypes.Timestamp_ns},
 		{Name: "f16-d64", Type: arrow.FixedWidthTypes.Date64},
 		{Name: "f17-dti", Type: arrow.FixedWidthTypes.DayTimeInterval},
+		{Name: "f17-duration", Type: arrow.FixedWidthTypes.Duration_us},

Review Comment:
   should this be `f18-duration_us` ?



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40889:
URL: https://github.com/apache/arrow/pull/40889#issuecomment-2027368874

   :warning: GitHub issue #40888 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #40889:
URL: https://github.com/apache/arrow/pull/40889#issuecomment-2030936333

   After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 68241d8a86e9923cda2b758d10176b8dfb1cfea7.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/23325134748) has more details. It also includes information about 3 possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade merged PR #40889:
URL: https://github.com/apache/arrow/pull/40889


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "waynr (via GitHub)" <gi...@apache.org>.
waynr commented on code in PR #40889:
URL: https://github.com/apache/arrow/pull/40889#discussion_r1546587603


##########
go/arrow/flight/flightsql/driver/utils.go:
##########
@@ -104,6 +104,13 @@ func fromArrowType(arr arrow.Array, idx int) (interface{}, error) {
 		return v.ToTime(ts.TimeUnit()), nil
 	case *array.Date64:
 		return c.Value(idx).ToTime(), nil
+	case *array.Duration:
+    // according to
+    // https://github.com/apache/arrow/blob/50ca7a76d38e6ecf19589bc44f46bffd1db0d4c8/format/Schema.fbs#L420-L435
+    // the default "TimeUnit" for an arrow.Duration is in microseconds but
+    // golang Durations are int64 nanoseconds
+		duration := time.Duration(int64(c.Value(idx) * 1000))

Review Comment:
   Ah, thanks for catching that! I was wondering how to determine what the multiplier should be since the `array.Duration` didn't seem to me to have any obvious (to me) way to get it. After taking a closer look at the embedded `array` struct in `array.Duration` I kind of see how it works now. I fixed this and added more unit test cases for different `TimeUnit` values.



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-40888: [Go][FlightRPC] support conversion from array.Duration in FlightSQL driver [arrow]

Posted by "waynr (via GitHub)" <gi...@apache.org>.
waynr commented on code in PR #40889:
URL: https://github.com/apache/arrow/pull/40889#discussion_r1546587603


##########
go/arrow/flight/flightsql/driver/utils.go:
##########
@@ -104,6 +104,13 @@ func fromArrowType(arr arrow.Array, idx int) (interface{}, error) {
 		return v.ToTime(ts.TimeUnit()), nil
 	case *array.Date64:
 		return c.Value(idx).ToTime(), nil
+	case *array.Duration:
+    // according to
+    // https://github.com/apache/arrow/blob/50ca7a76d38e6ecf19589bc44f46bffd1db0d4c8/format/Schema.fbs#L420-L435
+    // the default "TimeUnit" for an arrow.Duration is in microseconds but
+    // golang Durations are int64 nanoseconds
+		duration := time.Duration(int64(c.Value(idx) * 1000))

Review Comment:
   Ah, thanks for catching that! I was wondering how to determine what the multiplier should be since the `array.Duration` didn't seem to me to have any obvious way to determine it. After taking a closer look at the embedded `array` struct in `array.Duration` I kind of see how it works now. I fixed this and added more unit test cases for different `TimeUnit` values.



-- 
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: github-unsubscribe@arrow.apache.org

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