mirror of https://github.com/apache/druid.git
stuff
This commit is contained in:
parent
1a5faf1afb
commit
1b7dd8fd3c
|
@ -722,7 +722,9 @@ public class NestedDataOperatorConversions
|
||||||
public static class JsonObjectOperatorConversion implements SqlOperatorConversion
|
public static class JsonObjectOperatorConversion implements SqlOperatorConversion
|
||||||
{
|
{
|
||||||
private static final String FUNCTION_NAME = "json_object";
|
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)
|
.operatorBuilder(FUNCTION_NAME)
|
||||||
.operandTypeChecker(OperandTypes.variadic(SqlOperandCountRanges.from(1)))
|
.operandTypeChecker(OperandTypes.variadic(SqlOperandCountRanges.from(1)))
|
||||||
.operandTypeInference((callBinding, returnType, operandTypes) -> {
|
.operandTypeInference((callBinding, returnType, operandTypes) -> {
|
||||||
|
@ -781,7 +783,8 @@ public class NestedDataOperatorConversions
|
||||||
public static class ToJsonStringOperatorConversion implements SqlOperatorConversion
|
public static class ToJsonStringOperatorConversion implements SqlOperatorConversion
|
||||||
{
|
{
|
||||||
private static final String FUNCTION_NAME = "to_json_string";
|
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))
|
.operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME))
|
||||||
.operandTypes(SqlTypeFamily.ANY)
|
.operandTypes(SqlTypeFamily.ANY)
|
||||||
.returnTypeCascadeNullable(SqlTypeName.VARCHAR)
|
.returnTypeCascadeNullable(SqlTypeName.VARCHAR)
|
||||||
|
|
|
@ -4882,7 +4882,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest
|
||||||
public void testJsonQueryAndJsonObject()
|
public void testJsonQueryAndJsonObject()
|
||||||
{
|
{
|
||||||
testQuery(
|
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",
|
+ "FROM druid.nested",
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
Druids.newScanQueryBuilder()
|
Druids.newScanQueryBuilder()
|
||||||
|
|
|
@ -97,4 +97,21 @@ public class CalciteSysQueryTest extends BaseCalciteQueryTest
|
||||||
+ " LogicalTableScan(table=[[sys, tasks]])\n")
|
+ " LogicalTableScan(table=[[sys, tasks]])\n")
|
||||||
.run();
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue