Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Add a pivot_longer node #34266

Closed
Tracked by #34265
westonpace opened this issue Feb 20, 2023 · 1 comment · Fixed by #34267
Closed
Tracked by #34265

[C++] Add a pivot_longer node #34266

westonpace opened this issue Feb 20, 2023 · 1 comment · Fixed by #34267

Comments

@westonpace
Copy link
Member

Describe the enhancement requested

Pivoting longer is an operation that is useful when a single row contains multiple observations or measurements. For example:

time left_temp right_temp
1 10 20
2 15 18

The columns left_temp and right_temp are really the combination of a "feature" (location) and a "measurement" (temp). We can pivot longer to extract these into their own columns:

time location temp
1 left 10
1 right 20
2 left 15
2 right 18

The addition of this capability should make it possible to fully bind tidyr's pivot_longer and pivot_wider (the latter can be expressed using a combination of project and aggregate). However, there is a considerable amount of convenience that could still be added and much of this is captured in the parent issue #34265

Component(s)

C++

@westonpace
Copy link
Member Author

It appears that DuckDb has tackled the pivot feature at the same time (and their implementation is much more complete). They use unnest for pivot longer but it's not clear to me that we could do the same thing here. It relies on the ability to create a sort of list comprehension out of field references to convert field references to elements into a field reference to a list element (I'm not sure exactly what this syntax is called). It's quite impressive :)

@westonpace westonpace added this to the 12.0.0 milestone Mar 4, 2023
westonpace added a commit that referenced this issue Mar 4, 2023
* Closes: #34266

Authored-by: Weston Pace <weston.pace@gmail.com>
Signed-off-by: Weston Pace <weston.pace@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant