unified the code format in NestedDataOperatorConversions (#16695)

This commit is contained in:
Alberic Liu 2024-07-08 10:06:24 +08:00 committed by GitHub
parent 586c713d12
commit c6c2652c89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 12 deletions

View File

@ -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
)
);