Skip to content

Commit

Permalink
Add operator to ESQL signature for kibana
Browse files Browse the repository at this point in the history
This adds a field to the kibana defintion files for each signature that
looks like:
```
  "operator": "+",
```
Kibana wants these symbols.
  • Loading branch information
nik9000 committed Jan 15, 2025
1 parent 4462070 commit bb6ee3f
Show file tree
Hide file tree
Showing 35 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/add.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/div.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/in.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/like.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/reference/esql/functions/kibana/definition/match.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/mod.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/mul.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/neg.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/rlike.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/definition/sub.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface FunctionInfo {
/**
* If this function implements an operator, what is its symbol?
* <p>
* This exists entirely to add to the Kibana function definition
* json files.
* </p>
*/
String operator() default "";

/**
* The type(s) this function returns.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class Match extends FullTextFunction implements PostOptimizationVerificat

@FunctionInfo(
returnType = "boolean",
operator = "MATCH",
preview = true,
description = """
Use `MATCH` to perform a <<query-dsl-match-query,match query>> on the specified field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class RLike extends org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLike implements EvaluatorMapper {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "RLike", RLike::new);

@FunctionInfo(returnType = "boolean", description = """
@FunctionInfo(returnType = "boolean", operator = "RLIKE", description = """
Use `RLIKE` to filter data based on string patterns using using
<<regexp-syntax,regular expressions>>. `RLIKE` usually acts on a field placed on
the left-hand side of the operator, but it can also act on a constant (literal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WildcardLike extends org.elasticsearch.xpack.esql.core.expression.p
WildcardLike::new
);

@FunctionInfo(returnType = "boolean", description = """
@FunctionInfo(returnType = "boolean", operator = "LIKE", description = """
Use `LIKE` to filter data based on string patterns using wildcards. `LIKE`
usually acts on a field placed on the left-hand side of the operator, but it can
also act on a constant (literal) expression. The right-hand side of the operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Add extends DateTimeArithmeticOperation implements BinaryComparison
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Add", Add::new);

@FunctionInfo(
operator = "+",
returnType = { "double", "integer", "long", "date_nanos", "date_period", "datetime", "time_duration", "unsigned_long" },
description = "Add two numbers together. " + "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Div extends EsqlArithmeticOperation implements BinaryComparisonInve
private DataType type;

@FunctionInfo(
operator = "/",
returnType = { "double", "integer", "long", "unsigned_long" },
description = "Divide one number by another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Mod extends EsqlArithmeticOperation {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Mod", Mod::new);

@FunctionInfo(
operator = "%",
returnType = { "double", "integer", "long", "unsigned_long" },
description = "Divide one number by another and return the remainder. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Mul extends EsqlArithmeticOperation implements BinaryComparisonInve
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Mul", Mul::new);

@FunctionInfo(
operator = "*",
returnType = { "double", "integer", "long", "unsigned_long" },
description = "Multiply two numbers together. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Neg extends UnaryScalarFunction {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Neg", Neg::new);

@FunctionInfo(
operator = "-",
returnType = { "double", "integer", "long", "date_period", "time_duration" },
description = "Returns the negation of the argument."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Sub extends DateTimeArithmeticOperation implements BinaryComparison
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Sub", Sub::new);

@FunctionInfo(
operator = "-",
returnType = { "double", "integer", "long", "date_period", "datetime", "time_duration", "unsigned_long" },
description = "Subtract one number from another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Equals extends EsqlBinaryComparison implements Negatable<EsqlBinary
);

@FunctionInfo(
operator = "==",
returnType = { "boolean" },
description = "Check if two fields are equal. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class GreaterThan extends EsqlBinaryComparison implements Negatable<EsqlB
);

@FunctionInfo(
operator = ">",
returnType = { "boolean" },
description = "Check if one field is greater than another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class GreaterThanOrEqual extends EsqlBinaryComparison implements Negatabl
);

@FunctionInfo(
operator = ">=",
returnType = { "boolean" },
description = "Check if one field is greater than or equal to another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class In extends EsqlScalarFunction {
private final List<Expression> list;

@FunctionInfo(
operator = "IN",
returnType = "boolean",
description = "The `IN` operator allows testing whether a field or expression equals an element in a list of literals, "
+ "fields or expressions.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LessThan extends EsqlBinaryComparison implements Negatable<EsqlBina
);

@FunctionInfo(
operator = "<",
returnType = { "boolean" },
description = "Check if one field is less than another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LessThanOrEqual extends EsqlBinaryComparison implements Negatable<E
);

@FunctionInfo(
operator = "<=",
returnType = { "boolean" },
description = "Check if one field is less than or equal to another. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class NotEquals extends EsqlBinaryComparison implements Negatable<EsqlBin
);

@FunctionInfo(
operator = "!=",
returnType = { "boolean" },
description = "Check if two fields are unequal. "
+ "If either field is <<esql-multivalued-fields,multivalued>> then the result is `null`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,13 @@ private static void renderKibanaFunctionDefinition(
"comment",
"This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it."
);
builder.field("type", isAggregation() ? "agg" : OPERATORS.get(name) != null ? "operator" : "eval");
if (false == info.operator().isEmpty()) {
builder.field("type", "operator");
builder.field("operator", info.operator());
assertThat(isAggregation(), equalTo(false));
} else {
builder.field("type", isAggregation() ? "agg" : "eval");
}
builder.field("name", name);
builder.field("description", removeAsciidocLinks(info.description()));
if (Strings.isNullOrEmpty(info.note()) == false) {
Expand Down

0 comments on commit bb6ee3f

Please sign in to comment.