Skip to content

[CALCITE-2870] Support for JSON query quotes behavior#1107

Closed
ritesh-kapoor wants to merge 3 commits intoapache:masterfrom
ritesh-kapoor:CALCITE-2870
Closed

[CALCITE-2870] Support for JSON query quotes behavior#1107
ritesh-kapoor wants to merge 3 commits intoapache:masterfrom
ritesh-kapoor:CALCITE-2870

Conversation

@ritesh-kapoor
Copy link
Contributor

No description provided.

"[100]", "VARCHAR(2000)");

//omit quotes test
tester.checkString("json_query('{\"foo\":\"100\"}', 'strict $.foo' "
Copy link
Member

@zhztheplayer zhztheplayer Apr 3, 2019

Choose a reason for hiding this comment

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

For comparing the behaviors, could you please add a case for the flag KEEP QUOTES?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unless RETURNING text is defined KEEP QUOTES doesn't functionally changes anything. Please help me understand if it is incorrect or should we implement RETURNING functionality as well.

Copy link
Member

@zhztheplayer zhztheplayer Apr 13, 2019

Choose a reason for hiding this comment

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

@ritesh-kapoor Thanks for your clarification, and sorry for the late reply.

if it is incorrect or should we implement RETURNING functionality as well

Here is the SQL:2016 standard's JSON part:
https://standards.iso.org/ittf/PubliclyAvailableStandards/c067367_ISO_IEC_TR_19075-6_2017.zip

In the std, JSON_QUERY does include a optional output clause:

<JSON output clause> ::= RETURNING [ FORMAT <JSON representation> ]

So yes I think the functionality should be implemented as well, maybe by a separated PR/JIRA.

Besides, I recall that currently JSON_QUERY is not designed for returning scalar values (see examples in page 34 in std). It only returns JSON array or object, otherwise an error is thrown. But the highlighted case your wrote shows that a JSON_QUERY call produces an scalar string in the PR.

So in the PR the behavior on querying a scalar string is:

  1. If OMIT QUOTES is specified, return a string value;
  2. If KEEP QUOTES is specified, report an error;
  3. If quote behavior is not specified, report an error.

Did I summarize them correctly? If yes, I think case 1 and case 2/3 are not consistent. Maybe we should make JSON_QUERY be able to return scalar values as well as JSON_VALUE by default (without abiding by the std). Have you checked how does the same part work in other SQL impelemtations such as DB2[1]? Does it ban scalar value for JSON_QUERY too?

[1] https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0070413.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can raise a separate PR for the optional clause for JSON_QUERY. Also

  1. If OMIT QUOTES is specified, return a string value;
  2. If KEEP QUOTES is specified, the function would behave as if it was unspecified.
  3. If quote behavior is not specified, the function would behave as if it was unspecified.

Got some references : https://marc.info/?l=postgresql-hackers&m=153024002012585&w=2

Sorry this PR is pending for long, I will also resolve all the conflicts once it is ready to be merged.

@hsyuan hsyuan changed the title CALCITE-2870: Support for JSON query quotes behavior [CALCITE-2870] Support for JSON query quotes behavior Apr 14, 2019
@danny0405 danny0405 force-pushed the master branch 2 times, most recently from 80f411d to ca27fe9 Compare November 30, 2019 07:52
@Humbedooh Humbedooh deleted the branch apache:master April 26, 2022 14:21
@Humbedooh Humbedooh closed this Apr 26, 2022
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

Successfully merging this pull request may close these issues.

3 participants