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

feat(query): Add jq set returning function for processing Variant data with jq filters #16288

Merged
merged 6 commits into from
Aug 23, 2024

Conversation

maxjustus
Copy link
Contributor

@maxjustus maxjustus commented Aug 20, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

This adds a jq set returning function for working with Variant data. Jq is described as "regexp for json" and is a wonderful addition for processing data in Variant columns. This work was inspired by pgjq which adds jq to postgres and litejq which adds jq to sqlite.

the jq function being set returning means that you can write jq filters that unnest json data as a part of their evaluation. For example:

SELECT * FROM jq('.[] as $a | {upcased: ($a | ascii_upcase), original: $a}', json_array('hello', 'world'))
row 1: {"upcased": "HELLO", "original": "hello"}
row 2: {"upcased": "WORLD", "original": "world"}

It uses the lightweight jaq crate which provides a high performance pure rust implementation of jq.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@maxjustus maxjustus changed the title Add jq set returning function for processing Variant data with jq filters feat(query): Add jq set returning function for processing Variant data with jq filters Aug 20, 2024
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Aug 20, 2024
@maxjustus maxjustus force-pushed the add-jq branch 3 times, most recently from 3721e11 to 3a7a46e Compare August 20, 2024 05:29
@b41sh b41sh self-requested a review August 20, 2024 10:25
@maxjustus maxjustus force-pushed the add-jq branch 3 times, most recently from 51350b9 to 93ee6b5 Compare August 20, 2024 22:21
@maxjustus
Copy link
Contributor Author

Rebased against most recent main, fixed clippy and cargo machete errors.

@xudong963
Copy link
Member

Rebased against most recent main, fixed clippy and cargo machete errors.

Thanks for your contribution. You can run REGENERATE_GOLDENFILES=1 cargo test to update the failed unit test.

src/query/functions/src/srfs/variant.rs Outdated Show resolved Hide resolved
src/query/functions/src/srfs/variant.rs Outdated Show resolved Hide resolved
Copy link
Member

@b41sh b41sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @maxjustus
Thanks for your contribution, this feature is very useful.

@b41sh b41sh enabled auto-merge August 23, 2024 15:44
@b41sh b41sh added this pull request to the merge queue Aug 23, 2024
Merged via the queue into databendlabs:main with commit 9c7828a Aug 23, 2024
69 checks passed
@BohuTANG
Copy link
Member

Thanks @maxjustus, for your contribution!

We should add this new function to the docs. @soyeric128 @b41sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants