Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6474,7 +6474,8 @@ private class JsonFunctionRexRewriter extends RexShuttle {
}

@Override public RexNode visitCall(RexCall call) {
if (call.getOperator() == SqlStdOperatorTable.JSON_OBJECT) {
if (call.getOperator().getName().equals(SqlStdOperatorTable.JSON_OBJECT.getName())
&& call.getOperator().getKind() == SqlStdOperatorTable.JSON_OBJECT.getKind()) {
final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
for (int i = 0; i < call.operands.size(); ++i) {
if ((i & 1) == 0 && i != 0) {
Expand All @@ -6485,7 +6486,8 @@ private class JsonFunctionRexRewriter extends RexShuttle {
}
return rexBuilder.makeCall(SqlStdOperatorTable.JSON_OBJECT, builder.build());
}
if (call.getOperator() == SqlStdOperatorTable.JSON_ARRAY) {
if (call.getOperator().getName().equals(SqlStdOperatorTable.JSON_ARRAY.getName())
&& call.getOperator().getKind() == SqlStdOperatorTable.JSON_ARRAY.getKind()) {
final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
builder.add(call.operands.get(0));
for (int i = 1; i < call.operands.size(); ++i) {
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/resources/sql/agg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -3777,5 +3777,22 @@ select distinct sum(deptno + '1') as deptsum from dept order by 1;
+---------+
(1 row)

!ok

# Test cases for [CALCITE-6437] For druid sql JSON_OBJECT() function results in RUNTIME_FAILURE when querying
# INFORMATION_SCHEMA.COLUMNS
select json_object('name': job, 'value': deptno) as options
from "scott".emp
where deptno = 10
group by deptno, job;
+---------------------------------+
| OPTIONS |
+---------------------------------+
| {"name":"CLERK","value":10} |
| {"name":"MANAGER","value":10} |
| {"name":"PRESIDENT","value":10} |
+---------------------------------+
(3 rows)

!ok
# End agg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -6330,6 +6330,12 @@ void checkRegexpExtract(SqlOperatorFixture f0, FunctionAlias functionAlias) {
"{\"foo\":{\"foo\":\"bar\"}}", "VARCHAR(2000) NOT NULL");
f.checkString("json_object('foo': json_object('foo': 'bar') format json)",
"{\"foo\":{\"foo\":\"bar\"}}", "VARCHAR(2000) NOT NULL");
final SqlOperatorFixture f1 = SqlOperatorFixtureImpl.DEFAULT.withTester(t -> TESTER);
f1.check(
"select json_object('key':x, 'value':y)\n"
+ "from (select 1 as x, 2 as y\n"
+ " from (values (true)))",
SqlTests.ANY_TYPE_CHECKER, "{\"value\":2,\"key\":1}");
}

@Test void testJsonObjectAgg() {
Expand Down