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

JSONExtract String or Raw #25452

Merged
merged 2 commits into from
Jul 9, 2021

Conversation

amosbird
Copy link
Collaborator

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Allow extract non-string element as string using JSONExtract. This is for #25414

Detailed description / Documentation draft:

.

@robot-clickhouse robot-clickhouse added the pr-improvement Pull request with some product improvements label Jun 18, 2021
@Avogar Avogar self-assigned this Jun 21, 2021
@Avogar
Copy link
Member

Avogar commented Jun 21, 2021

The changes also affect JSONExtractKeysAndValues function:

SELECT JSONExtractKeysAndValues('{"a": "string", "b": [1, 2]}', 'String') = [('a','string'),('b','[1,2]')]

Do we really want such behaviour?

@amosbird
Copy link
Collaborator Author

Do we really want such behaviour?

Looks ok to me)

@Avogar
Copy link
Member

Avogar commented Jun 21, 2021

Ok, let's fix tests and merge it

@filimonov
Copy link
Contributor

filimonov commented Jun 21, 2021

The main problem in that implementation is ambiguity of

{"a": "{}", "b": {} }

And lack of possibility to extract string field with surrounding quotes (to have always valid sub-json, which can be parsed)

It is rather minor issue, but it potentially is not 100% sane, and once it will be merged we will not be able to fix it anymore in any other way. String will always extract raw-json.

@alexey-milovidov
Copy link
Member

@filimonov This is what JSONExtractRaw for.

@filimonov
Copy link
Contributor

@filimonov This is what JSONExtractRaw for.

Check #25414

@Avogar
Copy link
Member

Avogar commented Jun 22, 2021

@filimonov maybe you have an idea how to solve this ambiguity? One of the possible solution is to add new data type RawString, but this is overkill I think.

@amosbird
Copy link
Collaborator Author

amosbird commented Jun 22, 2021

@filimonov maybe you have an idea how to solve this ambiguity? One of the possible solution is to add new data type RawString, but this is overkill I think.

It's also possible to give a different name like JSONExtractWithRawString. However, I don't understand the impact of this ambiguity. What would break?

@filimonov
Copy link
Contributor

filimonov commented Jun 23, 2021

@filimonov maybe you have an idea how to solve this ambiguity?

Nothing much smarter than:

to add new data type RawString
but this is overkill I think.

Sounds like overkill, agree.

It's also possible to give a different name like JSONExtractWithRawString.

Theoretically it's bit safer (no regressions like in example below). But i also don't feel 100% happy about that (more functions / switches again)

However, I don't understand the impact of this ambiguity. What would break?

For ex. things like

with '{a:{b:1}}' as json
Select if(JSONExtract(json, 'a'), JSONExtract(json, 'a'), JSONExtract(json, 'a.b'))

@alexey-milovidov
Copy link
Member

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Jul 2, 2021

Command update: success

Branch has been successfully updated

@alexey-milovidov alexey-milovidov self-assigned this Jul 9, 2021
@alexey-milovidov alexey-milovidov merged commit eafce77 into ClickHouse:master Jul 9, 2021
@filimonov
Copy link
Contributor

That needs a clear documentation. Also a note in changelog.

@wangqinghuan
Copy link
Contributor

This change does not affect JSONExtractString(). Could we keep same behavior in all JSONExtract String function? @amosbird

@amosbird
Copy link
Collaborator Author

@wangqinghuan Yes. It's reasonable. #30426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants