zhztheplayer commented on a change in pull request #1070: [CALCITE-2808]Add the
JSON_LENGTH function
URL: https://github.com/apache/calcite/pull/1070#discussion_r264211919
##########
File path: core/src/main/codegen/templates/Parser.jj
##########
@@ -5300,6 +5302,30 @@ SqlCall JsonDepthFunctionCall() :
}
}
+SqlCall JsonLengthFunctionCall() :
+{
+ final SqlNode[] args = new SqlNode[1];
+ SqlNode e;
+ final Span span;
+ List<SqlNode> behavior;
+}
+{
+ <JSON_LENGTH> { span = span(); }
+ <LPAREN> [
Review comment:
Currently `JsonApiCommonSyntax()` only accepts parameters like `json_doc,
path`, which means, the `path` expression must be specified explicitly.
I suggest to make some changes to code of `JsonApiCommonSyntax()` to make it
support `json_doc[, path]`, for instance, change the current syntax code to
something like:
```
SqlNode JsonApiCommonSyntax() :
{
SqlNode e;
List<SqlNode> args = new ArrayList<SqlNode>();
Span span;
SqlOperator op;
}
{
e = JsonValueExpression(true) {
args.add(e);
span = Span.of(e);
}
(
<COMMA>
e = Expression(ExprContext.ACCEPT_NON_QUERY) {
op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX;
args.add(e);
}
|
{
op = SqlStdOperatorTable.JSON_API_COMMON_SYNTAX_WITHOUT_PATH;
}
)
[
<PASSING> e = JsonValueExpression(false) {
args.add(e);
}
<AS> e = SimpleIdentifier() {
args.add(e);
}
(
<COMMA>
e = JsonValueExpression(false) {
args.add(e);
}
<AS> e = SimpleIdentifier() {
args.add(e);
}
)*
]
{
return op.createCall(span.end(this), args);
}
}
```
Then we should add a new operator `JSON_API_COMMON_SYNTAX_WITHOUT_PATH` and
implement it at enumerable level.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services