Skip to content

Commit

Permalink
make getTargetType private and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fang-xing-esql committed Nov 8, 2024
1 parent 9c9a95f commit 67b6885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ public static String normalizeName(String name) {
}

public record ArgSignature(String name, String[] type, String description, boolean optional, DataType targetDataType) {

public ArgSignature(String name, String[] type, String description, boolean optional) {
this(name, type, description, optional, UNSUPPORTED);
}

@Override
public String toString() {
return "ArgSignature{"
Expand Down Expand Up @@ -481,13 +486,13 @@ public List<String> argDescriptions() {
/**
* Build a list target data types, which is used by ImplicitCasting to convert string literals to a target data type.
*/
public static DataType getTargetType(String[] names) {
private static DataType getTargetType(String[] names) {
List<DataType> types = new ArrayList<>();
for (String name : names) {
DataType type = DataType.fromTypeName(name);
if (type != null && type != UNSUPPORTED) { // A type should not be null or UNSUPPORTED, just a sanity check here
// If the function takes strings as input, there is no need to cast a string literal to it.
// Return UNSUPPORTED, so that ImplicitCasting doesn't process it.
// Return UNSUPPORTED means that ImplicitCasting doesn't support this argument, and it will be skipped by ImplicitCasting.
if (isString(type)) {
return UNSUPPORTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,7 @@ public static void renderDocs() throws IOException {
"elseValue",
trueValue.type(),
"The value that's returned when no condition evaluates to `true`.",
true,
EsqlFunctionRegistry.getTargetType(trueValue.type())
true
);
description = new EsqlFunctionRegistry.FunctionDescription(
description.name(),
Expand Down Expand Up @@ -1085,8 +1084,7 @@ private static void renderDocsForOperators(String name) throws IOException {
String[] type = paramInfo == null ? new String[] { "?" } : paramInfo.type();
String desc = paramInfo == null ? "" : paramInfo.description().replace('\n', ' ');
boolean optional = paramInfo == null ? false : paramInfo.optional();
DataType targetDataType = EsqlFunctionRegistry.getTargetType(type);
args.add(new EsqlFunctionRegistry.ArgSignature(paramName, type, desc, optional, targetDataType));
args.add(new EsqlFunctionRegistry.ArgSignature(paramName, type, desc, optional));
}
}
renderKibanaFunctionDefinition(name, functionInfo, args, likeOrInOperator(name));
Expand Down

0 comments on commit 67b6885

Please sign in to comment.