Skip to content

feat: UDF json_get with user specified return type#7554

Merged
sunng87 merged 7 commits into
GreptimeTeam:mainfrom
sunng87:feature/json-get-with-type
Jan 26, 2026
Merged

feat: UDF json_get with user specified return type#7554
sunng87 merged 7 commits into
GreptimeTeam:mainfrom
sunng87:feature/json-get-with-type

Conversation

@sunng87
Copy link
Copy Markdown
Member

@sunng87 sunng87 commented Jan 9, 2026

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

Fixes #7500

What's changed and what's your intention?

  1. add json_get function that accept a return type, like string, int, 'float' and 'bool'
  2. add datafusion return_field_from_args to our Function trait
  3. port json_get_bool and json_get_float to new data type

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

@github-actions github-actions Bot added size/S docs-not-required This change does not impact docs. labels Jan 9, 2026
json_get with third argument accepting a scalar value for type.
@github-actions github-actions Bot added size/M and removed size/S labels Jan 12, 2026
@sunng87 sunng87 marked this pull request as ready for review January 12, 2026 08:32
@sunng87 sunng87 requested a review from a team as a code owner January 12, 2026 08:32
@waynexia
Copy link
Copy Markdown
Member

How about use datatype itself as a parameter instead of parsing a string? like this https://github.com/waynexia/jsonfusion/blob/645f8eccf8eccf9d6139b848d1fffe9f70d95cdf/src/get_field_typed.rs#L79-L85

This can express a more complicated type, and reduce maintaince burden of the string to type mapping

@sunng87
Copy link
Copy Markdown
Member Author

sunng87 commented Jan 14, 2026

@waynexia I'm afraid this will make the function difficult to understand, for example json_get(a, 'a', true) has exact same meaning of json_get(a, 'a', false).

@waynexia
Copy link
Copy Markdown
Member

why use it like this, rather than json_get(a, 'a')::boolean. The third parameter should be for internal usage.

@sunng87
Copy link
Copy Markdown
Member Author

sunng87 commented Jan 16, 2026

Even if we will be rewriting json_get(a, 'a')::boolean to the three-argument form, I still think using type name is more direct than using type instance for the hidden argument.

For example, if we want to support int array as return type, we can rewrite json_get(a, 'a')::int4[] to json_get(a, 'a', 'int4[]'), rather than generating a real int4[] literal value just to represent the type like json_get(a, 'a', '{1}'::int4[])

@waynexia waynexia added this pull request to the merge queue Jan 26, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 26, 2026
@sunng87 sunng87 added this pull request to the merge queue Jan 26, 2026
Merged via the queue into GreptimeTeam:main with commit 079ee86 Jan 26, 2026
43 checks passed
@sunng87 sunng87 deleted the feature/json-get-with-type branch January 26, 2026 10:29
linyihai pushed a commit to linyihai/greptimedb that referenced this pull request Jan 28, 2026
* feat: add return_field_from_args

* feat: add JsonGetWithType

* port json_get_float and json_get_bool to new implementation, add
json_get with third argument accepting a scalar value for type.

* fix: lint fix

* chore: add sqlness tests

* chore: update tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new function: json_get(column, path, datatype)

3 participants