You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "thisisnic (via GitHub)" <gi...@apache.org> on 2023/03/08 13:56:03 UTC
[GitHub] [arrow] thisisnic opened a new issue, #34501: [C++] Substrait plan with multiple aggregate fields returns incorrect results
thisisnic opened a new issue, #34501:
URL: https://github.com/apache/arrow/issues/34501
### Describe the bug, including details regarding any error messages, version, and platform.
When I specify a plan containing more than 1 aggregate, the results I get back are incorrect - the values representing the grouping variable are returned in the wrong column, and the values for the first aggregate is returned in the other columns.
I *think* the plan is correct as I'm getting the right results back from DuckDB - the only difference is that I've had to supply the `phase` and `invocation` for compatibility with Acero, but unsure if this is relevant?
``` r
library(substrait, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
data <- tibble::tibble(
x = 1:10,
y = rep(c("A", "B"), each = 5)
)
data
#> # A tibble: 10 × 2
#> x y
#> <int> <chr>
#> 1 1 A
#> 2 2 A
#> 3 3 A
#> 4 4 A
#> 5 5 A
#> 6 6 B
#> 7 7 B
#> 8 8 B
#> 9 9 B
#> 10 10 B
# In R directly
data %>%
group_by(y) %>%
summarise(min_x = min(x, na.rm =TRUE), max_x = max(x, na.rm =TRUE)) %>%
collect()
#> # A tibble: 2 × 3
#> y min_x max_x
#> <chr> <int> <int>
#> 1 A 1 5
#> 2 B 6 10
# DuckDB via Substrait
ddb <- data %>%
duckdb_substrait_compiler() %>%
group_by(y) %>%
summarise(min_x = min(x, na.rm =TRUE), max_x = max(x, na.rm =TRUE))
collect(ddb)
#> # A tibble: 2 × 3
#> y min_x max_x
#> <chr> <int> <int>
#> 1 A 1 5
#> 2 B 6 10
# Arrow via Substrait
arr <- data %>%
arrow_substrait_compiler() %>%
group_by(y) %>%
summarise(min_x = min(x, na.rm =TRUE), max_x = max(x, na.rm =TRUE))
collect(arr)
#> # A tibble: 2 × 3
#> y min_x max_x
#> <int> <int> <chr>
#> 1 1 1 A
#> 2 6 6 B
arr$plan() |>
as.raw() |>
arrow::buffer() |>
arrow:::substrait__internal__SubstraitToJSON() |>
jsonlite::prettify(indent = 2)
#> {
#> "extensionUris": [
#> {
#> "extensionUriAnchor": 1,
#> "uri": "https://github.com/substrait-io/substrait/blob/main/extensions/functions_arithmetic.yaml"
#> },
#> {
#> "extensionUriAnchor": 2,
#> "uri": "https://github.com/substrait-io/substrait/blob/main/extensions/functions_comparison.yaml"
#> }
#> ],
#> "extensions": [
#> {
#> "extensionFunction": {
#> "extensionUriReference": 1,
#> "functionAnchor": 2,
#> "name": "min"
#> }
#> },
#> {
#> "extensionFunction": {
#> "extensionUriReference": 1,
#> "functionAnchor": 3,
#> "name": "max"
#> }
#> }
#> ],
#> "relations": [
#> {
#> "root": {
#> "input": {
#> "aggregate": {
#> "input": {
#> "project": {
#> "common": {
#> "emit": {
#> "outputMapping": [
#> 2,
#> 3
#> ]
#> }
#> },
#> "input": {
#> "read": {
#> "baseSchema": {
#> "names": [
#> "x",
#> "y"
#> ],
#> "struct": {
#> "types": [
#> {
#> "i32": {
#> "nullability": "NULLABILITY_NULLABLE"
#> }
#> },
#> {
#> "string": {
#> "nullability": "NULLABILITY_NULLABLE"
#> }
#> }
#> ]
#> }
#> },
#> "namedTable": {
#> "names": [
#> "named_table_1"
#> ]
#> }
#> }
#> },
#> "expressions": [
#> {
#> "selection": {
#> "directReference": {
#> "structField": {
#>
#> }
#> },
#> "rootReference": {
#>
#> }
#> }
#> },
#> {
#> "selection": {
#> "directReference": {
#> "structField": {
#> "field": 1
#> }
#> },
#> "rootReference": {
#>
#> }
#> }
#> }
#> ]
#> }
#> },
#> "groupings": [
#> {
#> "groupingExpressions": [
#> {
#> "selection": {
#> "directReference": {
#> "structField": {
#> "field": 1
#> }
#> },
#> "rootReference": {
#>
#> }
#> }
#> }
#> ]
#> }
#> ],
#> "measures": [
#> {
#> "measure": {
#> "functionReference": 2,
#> "phase": "AGGREGATION_PHASE_INITIAL_TO_RESULT",
#> "outputType": {
#> "fp64": {
#> "nullability": "NULLABILITY_NULLABLE"
#> }
#> },
#> "invocation": "AGGREGATION_INVOCATION_ALL",
#> "arguments": [
#> {
#> "value": {
#> "selection": {
#> "directReference": {
#> "structField": {
#>
#> }
#> },
#> "rootReference": {
#>
#> }
#> }
#> }
#> }
#> ]
#> }
#> },
#> {
#> "measure": {
#> "functionReference": 3,
#> "phase": "AGGREGATION_PHASE_INITIAL_TO_RESULT",
#> "outputType": {
#> "i64": {
#> "nullability": "NULLABILITY_NULLABLE"
#> }
#> },
#> "invocation": "AGGREGATION_INVOCATION_ALL",
#> "arguments": [
#> {
#> "value": {
#> "selection": {
#> "directReference": {
#> "structField": {
#>
#> }
#> },
#> "rootReference": {
#>
#> }
#> }
#> }
#> }
#> ]
#> }
#> }
#> ]
#> }
#> },
#> "names": [
#> "y",
#> "min_x",
#> "max_x"
#> ]
#> }
#> }
#> ]
#> }
#>
```
### Component(s)
C++
--
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@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on issue #34501: [C++] Substrait plan with multiple aggregate fields returns incorrect results
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on issue #34501:
URL: https://github.com/apache/arrow/issues/34501#issuecomment-1466504420
Yes, I believe that is the problem. #33616 is the issue. It would be good I think to fix this soon so that people don't start to rely on the current behavior.
--
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
[GitHub] [arrow] jorisvandenbossche commented on issue #34501: [C++] Substrait plan with multiple aggregate fields returns incorrect results
Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on issue #34501:
URL: https://github.com/apache/arrow/issues/34501#issuecomment-1460374432
I can't directly find the issue or PR, but I remember we recently discussed with @westonpace about having the group key column first vs last. Acero puts it last, but we probably want to change that to first (matching what R, pandas, .. and others do).
It might be that substrait is also expecting that? (the output field names in the plan are in that order)
--
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: [I] [C++] Substrait plan with multiple aggregate fields returns incorrect results [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic closed issue #34501: [C++] Substrait plan with multiple aggregate fields returns incorrect results
URL: https://github.com/apache/arrow/issues/34501
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org