snuyanzin commented on code in PR #3771:
URL: https://github.com/apache/calcite/pull/3771#discussion_r1592395238
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -2903,6 +2903,34 @@ private static class JsonValueImplementor extends
MethodImplementor {
}
}
+ /**
+ * Implementor for JSON_QUERY function. Passes the jsonize flag depending on
the output type.
+ */
+ private static class JsonQueryImplementor extends MethodImplementor {
+ JsonQueryImplementor(Method method) {
+ super(method, NullPolicy.ARG0, false);
+ }
+
+ @Override Expression implementSafe(RexToLixTranslator translator,
+ RexCall call, List<Expression> argValueList) {
+ final List<Expression> newOperands = new ArrayList<>(argValueList);
+
+ final Expression jsonize;
+ if (SqlTypeUtil.inCharFamily(call.getType())) {
+ jsonize = Expressions.constant(true);
+ } else {
+ jsonize = Expressions.constant(false);
Review Comment:
```suggestion
jsonize = FALSE_EXPR;
```
##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -8056,6 +8056,71 @@ private void checkGetTimestamp(Connection con) throws
SQLException {
.returns("C1=OBJECT; C2=ARRAY; C3=INTEGER; C4=BOOLEAN\n");
}
+ @Test void testJsonQuery() {
+ CalciteAssert.that()
+ .query("SELECT JSON_QUERY(v, '$.a') AS c1\n"
+ + ",JSON_QUERY(v, '$.a' RETURNING INTEGER ARRAY) AS c2\n"
+ + ",JSON_QUERY(v, '$.b' RETURNING INTEGER ARRAY EMPTY ARRAY ON
ERROR) AS c3\n"
+ + ",JSON_QUERY(v, '$.b' RETURNING VARCHAR ARRAY WITH ARRAY
WRAPPER) AS c4\n"
+ + "FROM (VALUES ('{\"a\": [1, 2],\"b\": \"[1, 2]\"}')) AS t(v)\n"
+ + "limit 10")
Review Comment:
not sure whether we need this `limit` since anyway only one line is in the
result
\+ imho: it's better to use the same case for all the keywords within the
query
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -2903,6 +2903,34 @@ private static class JsonValueImplementor extends
MethodImplementor {
}
}
+ /**
+ * Implementor for JSON_QUERY function. Passes the jsonize flag depending on
the output type.
+ */
+ private static class JsonQueryImplementor extends MethodImplementor {
+ JsonQueryImplementor(Method method) {
+ super(method, NullPolicy.ARG0, false);
+ }
+
+ @Override Expression implementSafe(RexToLixTranslator translator,
+ RexCall call, List<Expression> argValueList) {
+ final List<Expression> newOperands = new ArrayList<>(argValueList);
+
+ final Expression jsonize;
+ if (SqlTypeUtil.inCharFamily(call.getType())) {
+ jsonize = Expressions.constant(true);
Review Comment:
```suggestion
jsonize = TRUE_EXPR;
```
There are some constants defined above which could be reused here
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]