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: Add Spark json_array_length function #11946

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

WangGuangxin
Copy link

@WangGuangxin WangGuangxin commented Dec 24, 2024

The 'json_array_length' functions of Presto and Spark are similar, however
Presto returns int64_t, while Spark returns int32_t. In this PR, the
'JsonArrayLengthFunction' implementation is extracted to 'velox/functions/lib'
and registered with differenct return types for Presto and Spark.

Spark doc: https://spark.apache.org/docs/latest/api/sql/#json_array_length

@WangGuangxin WangGuangxin force-pushed the feat_json_array_length branch from a971121 to a5c0d3b Compare December 24, 2024 01:52
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 24, 2024
Copy link

netlify bot commented Dec 24, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit a971121
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/676a13f34f6f9b00089907c6

Copy link

netlify bot commented Dec 24, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit dbd4e2f
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/6788d8048a39080008ce7c5f

@WangGuangxin
Copy link
Author

@rui-mo @JkSelf @PHILO-HE Can you please help review this?

struct JsonArrayLengthFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(int32_t& len, const arg_type<Json>& json) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:
Change const arg_type<Json>& to const arg_type<Varchar>& and remove the above corresponding header.

I think JsonType is just for presto.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, fixed

Copy link
Contributor

@PHILO-HE PHILO-HE left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

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

Thanks. Added some comments.

velox/functions/lib/JsonArrayLength.h Show resolved Hide resolved
velox/functions/lib/JsonArrayLength.h Outdated Show resolved Hide resolved
velox/functions/lib/JsonArrayLength.h Show resolved Hide resolved
@rui-mo rui-mo changed the title feat: Add json_array_length Spark function feat: Add Spark json_array_length function Jan 6, 2025
Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

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

Thanks for updating. Added some comments.

velox/functions/lib/JsonArrayLength.h Outdated Show resolved Hide resolved
velox/functions/lib/JsonArrayLength.h Outdated Show resolved Hide resolved
velox/functions/sparksql/tests/JsonArrayLengthTest.cpp Outdated Show resolved Hide resolved
velox/functions/sparksql/tests/JsonArrayLengthTest.cpp Outdated Show resolved Hide resolved
@WangGuangxin WangGuangxin requested a review from rui-mo January 9, 2025 13:46
Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

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

Thanks. Added several nits on the doc.

velox/docs/functions/spark/json.rst Outdated Show resolved Hide resolved
velox/docs/functions/spark/json.rst Outdated Show resolved Hide resolved
velox/docs/functions/spark/json.rst Outdated Show resolved Hide resolved
velox/docs/functions/spark/json.rst Outdated Show resolved Hide resolved
velox/functions/lib/JsonArrayLength.h Outdated Show resolved Hide resolved
@WangGuangxin WangGuangxin requested a review from rui-mo January 13, 2025 01:50
@WangGuangxin WangGuangxin force-pushed the feat_json_array_length branch from 75dc918 to dbd4e2f Compare January 16, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants