From 1b7dd8fd3ce76ec22379a2f4a5227892e2d37385 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 26 Jun 2024 10:07:47 +0000 Subject: [PATCH] stuff --- .../builtin/NestedDataOperatorConversions.java | 7 +++++-- .../sql/calcite/CalciteNestedDataQueryTest.java | 2 +- .../druid/sql/calcite/CalciteSysQueryTest.java | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/NestedDataOperatorConversions.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/NestedDataOperatorConversions.java index 3fe049bdcb4..266b8bb2d8f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/NestedDataOperatorConversions.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/NestedDataOperatorConversions.java @@ -722,7 +722,9 @@ public class NestedDataOperatorConversions public static class JsonObjectOperatorConversion implements SqlOperatorConversion { private static final String FUNCTION_NAME = "json_object"; - private static final SqlFunction SQL_FUNCTION = OperatorConversions + private static final SqlFunction SQL_FUNCTION = SqlStdOperatorTable.JSON_OBJECT; + + private static final SqlFunction SQL_FUNCTION0 = OperatorConversions .operatorBuilder(FUNCTION_NAME) .operandTypeChecker(OperandTypes.variadic(SqlOperandCountRanges.from(1))) .operandTypeInference((callBinding, returnType, operandTypes) -> { @@ -781,7 +783,8 @@ public class NestedDataOperatorConversions public static class ToJsonStringOperatorConversion implements SqlOperatorConversion { private static final String FUNCTION_NAME = "to_json_string"; - private static final SqlFunction SQL_FUNCTION = OperatorConversions + private static final SqlFunction SQL_FUNCTION = + OperatorConversions .operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME)) .operandTypes(SqlTypeFamily.ANY) .returnTypeCascadeNullable(SqlTypeName.VARCHAR) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java index 95a4d0c1c32..3e0e13281f2 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java @@ -4882,7 +4882,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest public void testJsonQueryAndJsonObject() { testQuery( - "SELECT JSON_OBJECT(KEY 'n' VALUE JSON_QUERY(nester, '$.n'), KEY 'x' VALUE JSON_VALUE(nest, '$.x'))\n" + "SELECT TO_JSON_STRING(JSON_OBJECT(KEY 'n' VALUE JSON_QUERY(nester, '$.n'), KEY 'x' VALUE JSON_VALUE(nest, '$.x')))\n" + "FROM druid.nested", ImmutableList.of( Druids.newScanQueryBuilder() diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java index f03b13d8e26..c6d8307c99a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java @@ -97,4 +97,21 @@ public class CalciteSysQueryTest extends BaseCalciteQueryTest + " LogicalTableScan(table=[[sys, tasks]])\n") .run(); } + + @Test + public void testJsonObject() + { + testBuilder() + .sql( + "select JSON_OBJECT('name': COLUMN_NAME, 'type': \"DATA_TYPE\")" + + "from INFORMATION_SCHEMA.COLUMNS order by COLUMN_NAME limit 1" + ) + .expectedResults( + ImmutableList.of( + new Object[] {"{\"name\":\"CATALOG_NAME\",\"type\":\"VARCHAR\"}"} + ) + ) + .run(); + } + }