You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "barrkel (via GitHub)" <gi...@apache.org> on 2024/02/16 19:43:52 UTC

[PR] Support JSON_OBJECT('foo', 'bar') syntax [calcite]

barrkel opened a new pull request, #3694:
URL: https://github.com/apache/calcite/pull/3694

   Currently, Calcite has two styles for invoking `JSON_OBJECT`:
   
   ```
       JSON_OBJECT(KEY 'foo' VALUE 'bar', KEY 'foo2' VALUE 'bar2')
   ```
   
   and:
   
   ```
       JSON_OBJECT('foo' : 'bar', 'foo2' : 'bar')
   ```
   
   However, [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions#json_object) uses a lighter-weight syntax resembling the MAP<> constructor, with an even numbered argument list where every odd item is a key and the following even item is a value:
   
   ```
       JSON_OBJECT('foo', 'bar', 'foo2', 'bar2')
   ```
   
   This PR updates the grammar to allow `,` as well as `:` for separating key/value pairs in the invocation.
   
   It does not prevent mixing `,` and `:`, but retains the prohibition from mixing with `KEY`/`VALUE` syntax.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CALCITE-6255 Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #3694:
URL: https://github.com/apache/calcite/pull/3694#discussion_r1492924458


##########
core/src/main/java/org/apache/calcite/runtime/CalciteResource.java:
##########
@@ -112,6 +112,9 @@ public interface CalciteResource {
   @BaseMessage("Illegal identifier '':''. Was expecting ''VALUE''")
   ExInst<CalciteException> illegalColon();
 
+  @BaseMessage("Illegal identifier '',''. Was expecting ''VALUE''")

Review Comment:
   delimiter is also fine



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CALCITE-6255 Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "barrkel (via GitHub)" <gi...@apache.org>.
barrkel commented on code in PR #3694:
URL: https://github.com/apache/calcite/pull/3694#discussion_r1495655052


##########
core/src/main/java/org/apache/calcite/runtime/CalciteResource.java:
##########
@@ -112,6 +112,9 @@ public interface CalciteResource {
   @BaseMessage("Illegal identifier '':''. Was expecting ''VALUE''")
   ExInst<CalciteException> illegalColon();
 
+  @BaseMessage("Illegal identifier '',''. Was expecting ''VALUE''")

Review Comment:
   Well `,` isn't a legal identifier - the message is not wrong. It's kind of a two-prong message; we were expecting an identifier, and for the identifier to be `VALUE`. We fell at the first hurdle because `,` isn't an identifier.
   
   (AFAICT `VALUE` is usually a keyword not an identifier but it's a bit squishy because it could easily be a non-reserved word.)
   
   A better message might be "Unexpected symbol" rather than "Illegal identifier", which has better symmetry with the expected clause following. I'll change both to that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CALCITE-6255 Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "barrkel (via GitHub)" <gi...@apache.org>.
barrkel commented on code in PR #3694:
URL: https://github.com/apache/calcite/pull/3694#discussion_r1495637782


##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -6767,7 +6773,8 @@ SqlCall JsonObjectFunctionCall() :
 }
 {
     <JSON_OBJECT> { span = span(); }
-    <LPAREN> [
+    <LPAREN>

Review Comment:
   Stray edit from an earlier version of the code. I'll revert.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CALCITE-6255 Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #3694:
URL: https://github.com/apache/calcite/pull/3694#discussion_r1492920787


##########
testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java:
##########
@@ -8815,6 +8815,10 @@ private static Consumer<List<? extends Throwable>> checkWarnings(
         .ok("JSON_OBJECT(KEY 'foo' VALUE "
             + "JSON_OBJECT(KEY 'foo' VALUE 'bar' NULL ON NULL) "
             + "FORMAT JSON NULL ON NULL)");
+    expr("json_object('foo', 'bar')")

Review Comment:
   how about some other tests, e.g., with an odd number of elements?



##########
core/src/main/java/org/apache/calcite/runtime/CalciteResource.java:
##########
@@ -112,6 +112,9 @@ public interface CalciteResource {
   @BaseMessage("Illegal identifier '':''. Was expecting ''VALUE''")
   ExInst<CalciteException> illegalColon();
 
+  @BaseMessage("Illegal identifier '',''. Was expecting ''VALUE''")

Review Comment:
   Comma is not really an identifier.  Maybe "symbol".
   Yes, the previous message is probably wrong too.
   



##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -6767,7 +6773,8 @@ SqlCall JsonObjectFunctionCall() :
 }
 {
     <JSON_OBJECT> { span = span(); }
-    <LPAREN> [
+    <LPAREN>

Review Comment:
   why this change?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6255] Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "macroguo-ghy (via GitHub)" <gi...@apache.org>.
macroguo-ghy commented on PR #3694:
URL: https://github.com/apache/calcite/pull/3694#issuecomment-1955969341

   I think you should make the Jira ticket title, GitHub PR title, and commit message title consistent.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6255] Support BigQuery-style JSON_OBJECT invocation syntax [calcite]

Posted by "barrkel (via GitHub)" <gi...@apache.org>.
barrkel commented on PR #3694:
URL: https://github.com/apache/calcite/pull/3694#issuecomment-1956413163

   > I think you should make the Jira ticket title, GitHub PR title, and commit message title consistent.
   
   Done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-6255] Support BigQuery-style JSON_OBJECT invocation syntax [calcite]

Posted by "tanclary (via GitHub)" <gi...@apache.org>.
tanclary merged PR #3694:
URL: https://github.com/apache/calcite/pull/3694


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CALCITE-6255 Support JSON_OBJECT('foo', 'bar') syntax [calcite]

Posted by "tanclary (via GitHub)" <gi...@apache.org>.
tanclary commented on code in PR #3694:
URL: https://github.com/apache/calcite/pull/3694#discussion_r1492923794


##########
core/src/main/java/org/apache/calcite/runtime/CalciteResource.java:
##########
@@ -112,6 +112,9 @@ public interface CalciteResource {
   @BaseMessage("Illegal identifier '':''. Was expecting ''VALUE''")
   ExInst<CalciteException> illegalColon();
 
+  @BaseMessage("Illegal identifier '',''. Was expecting ''VALUE''")

Review Comment:
   It's kind of a delimiter too? Wdyt



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org