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

What is the syntax for json path? #3

Closed
hamlet-lee opened this issue Nov 9, 2017 · 2 comments
Closed

What is the syntax for json path? #3

hamlet-lee opened this issue Nov 9, 2017 · 2 comments

Comments

@hamlet-lee
Copy link

hamlet-lee commented Nov 9, 2017

create table temp.test_explode (userid string, log string) partitioned by (day string) stored as orc;
insert into table temp.test_explode partition (day = '2017-11-01') values ('u1', '[{  "action": "a" },  {  
"action": "b"} ]');
insert into table temp.test_explode partition (day = '2017-11-02') values ('u2', '[{  "action": "a" , "arg1": "1"},  {  "action": "b", "arg2": "2"} ]');


create temporary function udf_json_array_extract as 'cc.shanruifeng.functions.json.UDFJsonArrayExtract';

create temporary function udf_json_array_extract_scalar as 'cc.shanruifeng.functions.json.UDFJsonExtractScalar';


select userid, udf_json_array_extract ( log, '$.action' ) from  temp.test_explode  where day = '2017-11-01';

-- result
u1	["\"a\"","\"b\""]

select userid, udf_json_array_extract_scalar ( log, '$.action' ) from  temp.test_explode  where day = '2017-11-01';

-- result
u1	NULL

I want to get an array like ["a","b"], in the above second query, I got NULL.

Am I using wrong syntax for json path? What is the syntax for the path?

@aaronshan
Copy link
Owner

@hamlet-lee your udf function define error.
you should change UDFJsonExtractScalar to UDFJsonArrayExtractScalar . like this:

create temporary function udf_json_array_extract_scalar as 'cc.shanruifeng.functions.json.UDFJsonArrayExtractScalar';

@hamlet-lee
Copy link
Author

@aaronshan Thanks, I will try later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants