Skip to content

Commit

Permalink
unified the code format in NestedDataOperatorConversions (#16695)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbericByte authored Jul 8, 2024
1 parent 586c713 commit c6c2652
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -119,7 +120,7 @@ public DruidExpression toDruidExpression(
rexNode,
druidExpressions -> DruidExpression.ofExpression(
null,
DruidExpression.functionCall("json_paths"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
)
);
Expand All @@ -128,8 +129,9 @@ public DruidExpression toDruidExpression(

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)
Expand Down Expand Up @@ -158,7 +160,7 @@ public DruidExpression toDruidExpression(
rexNode,
druidExpressions -> DruidExpression.ofExpression(
ColumnType.STRING_ARRAY,
DruidExpression.functionCall("json_keys"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
)
);
Expand All @@ -167,9 +169,9 @@ public DruidExpression toDruidExpression(

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,
Expand Down Expand Up @@ -212,7 +214,7 @@ public DruidExpression toDruidExpression(
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();
Expand Down Expand Up @@ -723,7 +725,7 @@ public static class JsonObjectOperatorConversion implements SqlOperatorConversio
{
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();
Expand Down Expand Up @@ -756,7 +758,7 @@ public DruidExpression toDruidExpression(PlannerContext plannerContext, RowSigna
DruidExpression.ofExpression(
ColumnType.NESTED_DATA,
null,
DruidExpression.functionCall("json_object"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
);

Expand Down Expand Up @@ -809,7 +811,7 @@ public DruidExpression toDruidExpression(
rexNode,
druidExpressions -> DruidExpression.ofExpression(
ColumnType.NESTED_DATA,
DruidExpression.functionCall("to_json_string"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
)
);
Expand Down Expand Up @@ -847,7 +849,7 @@ public DruidExpression toDruidExpression(
rexNode,
druidExpressions -> DruidExpression.ofExpression(
ColumnType.NESTED_DATA,
DruidExpression.functionCall("parse_json"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
)
);
Expand Down Expand Up @@ -885,7 +887,7 @@ public DruidExpression toDruidExpression(
rexNode,
druidExpressions -> DruidExpression.ofExpression(
ColumnType.NESTED_DATA,
DruidExpression.functionCall("try_parse_json"),
DruidExpression.functionCall(FUNCTION_NAME),
druidExpressions
)
);
Expand Down

0 comments on commit c6c2652

Please sign in to comment.