From c6c2652c894acb7845f14ab4a782e357711b1eb0 Mon Sep 17 00:00:00 2001 From: Alberic Liu Date: Mon, 8 Jul 2024 10:06:24 +0800 Subject: [PATCH] unified the code format in NestedDataOperatorConversions (#16695) --- .../NestedDataOperatorConversions.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 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..a6006046553 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 @@ -92,8 +92,9 @@ public class NestedDataOperatorConversions public static class JsonPathsOperatorConversion implements SqlOperatorConversion { + private static final String FUNCTION_NAME = "json_paths"; private static final SqlFunction SQL_FUNCTION = OperatorConversions - .operatorBuilder("JSON_PATHS") + .operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME)) .operandTypeChecker(OperandTypes.ANY) .functionCategory(SqlFunctionCategory.USER_DEFINED_FUNCTION) .returnTypeArrayWithNullableElements(SqlTypeName.VARCHAR) @@ -119,7 +120,7 @@ public class NestedDataOperatorConversions rexNode, druidExpressions -> DruidExpression.ofExpression( null, - DruidExpression.functionCall("json_paths"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ) ); @@ -128,8 +129,9 @@ public class NestedDataOperatorConversions public static class JsonKeysOperatorConversion implements SqlOperatorConversion { + private static final String FUNCTION_NAME = "json_keys"; private static final SqlFunction SQL_FUNCTION = OperatorConversions - .operatorBuilder("JSON_KEYS") + .operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME)) .operandNames("expr", "path") .operandTypes(SqlTypeFamily.ANY, SqlTypeFamily.STRING) .literalOperands(1) @@ -158,7 +160,7 @@ public class NestedDataOperatorConversions rexNode, druidExpressions -> DruidExpression.ofExpression( ColumnType.STRING_ARRAY, - DruidExpression.functionCall("json_keys"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ) ); @@ -167,9 +169,9 @@ public class NestedDataOperatorConversions public static class JsonQueryOperatorConversion implements SqlOperatorConversion { - private static final String FUNCTION_NAME = StringUtils.toUpperCase("json_query"); + private static final String FUNCTION_NAME = "json_query"; private static final SqlFunction SQL_FUNCTION = OperatorConversions - .operatorBuilder(FUNCTION_NAME) + .operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME)) .operandTypeChecker( OperandTypes.family( SqlTypeFamily.ANY, @@ -212,7 +214,7 @@ public class NestedDataOperatorConversions final Expr pathExpr = plannerContext.parseExpression(druidExpressions.get(1).getExpression()); if (!pathExpr.isLiteral()) { // if path argument is not constant, just use a pure expression - return DruidExpression.ofFunctionCall(ColumnType.NESTED_DATA, "json_query", druidExpressions); + return DruidExpression.ofFunctionCall(ColumnType.NESTED_DATA, FUNCTION_NAME, druidExpressions); } // pre-normalize path so that the same expressions with different json path syntax are collapsed final String path = (String) pathExpr.eval(InputBindings.nilBindings()).value(); @@ -723,7 +725,7 @@ public class NestedDataOperatorConversions { private static final String FUNCTION_NAME = "json_object"; private static final SqlFunction SQL_FUNCTION = OperatorConversions - .operatorBuilder(FUNCTION_NAME) + .operatorBuilder(StringUtils.toUpperCase(FUNCTION_NAME)) .operandTypeChecker(OperandTypes.variadic(SqlOperandCountRanges.from(1))) .operandTypeInference((callBinding, returnType, operandTypes) -> { RelDataTypeFactory typeFactory = callBinding.getTypeFactory(); @@ -756,7 +758,7 @@ public class NestedDataOperatorConversions DruidExpression.ofExpression( ColumnType.NESTED_DATA, null, - DruidExpression.functionCall("json_object"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ); @@ -809,7 +811,7 @@ public class NestedDataOperatorConversions rexNode, druidExpressions -> DruidExpression.ofExpression( ColumnType.NESTED_DATA, - DruidExpression.functionCall("to_json_string"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ) ); @@ -847,7 +849,7 @@ public class NestedDataOperatorConversions rexNode, druidExpressions -> DruidExpression.ofExpression( ColumnType.NESTED_DATA, - DruidExpression.functionCall("parse_json"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ) ); @@ -885,7 +887,7 @@ public class NestedDataOperatorConversions rexNode, druidExpressions -> DruidExpression.ofExpression( ColumnType.NESTED_DATA, - DruidExpression.functionCall("try_parse_json"), + DruidExpression.functionCall(FUNCTION_NAME), druidExpressions ) );