Skip to content

Commit

Permalink
ESQL: Add type tables for operators to docs
Browse files Browse the repository at this point in the history
This adds a tiny blurb for each operator to the docs with a railroad
diagram of the operator's syntax and a table of the input and output
types. This also fixes the tests to correctly generate the tables for
operators.
  • Loading branch information
nik9000 committed Dec 8, 2023
1 parent 6e0c031 commit 42e8e68
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 21 deletions.
88 changes: 80 additions & 8 deletions docs/reference/esql/functions/binary.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,91 @@
[[esql-binary-operators]]
=== Binary operators

These binary comparison operators are supported:
[[esql-binary-operators-equality]]
==== Equality
[.text-center]
image::esql/functions/signature/equals.svg[Embedded,opts=inline]

Supported types:

include::types/equals.asciidoc[]

==== Inequality `!=`
[.text-center]
image::esql/functions/signature/not_equals.svg[Embedded,opts=inline]

* equality: `==`
* inequality: `!=`
* less than: `<`
* less than or equal: `<=`
* larger than: `>`
* larger than or equal: `>=`
Supported types:

And these mathematical operators are supported:
include::types/not_equals.asciidoc[]

==== Less than `<`
[.text-center]
image::esql/functions/signature/less_than.svg[Embedded,opts=inline]

Supported types:

include::types/less_than.asciidoc[]

==== Less than or equal to `<=`
[.text-center]
image::esql/functions/signature/less_than_or_equal.svg[Embedded,opts=inline]

Supported types:

include::types/less_than_or_equal.asciidoc[]

==== Greater than `>`
[.text-center]
image::esql/functions/signature/greater_than.svg[Embedded,opts=inline]

Supported types:

include::types/greater_than.asciidoc[]

==== Greater than or equal to `>=`
[.text-center]
image::esql/functions/signature/greater_than_or_equal.svg[Embedded,opts=inline]

Supported types:

include::types/greater_than_or_equal.asciidoc[]

==== Add `+`
[.text-center]
image::esql/functions/signature/add.svg[Embedded,opts=inline]

Supported types:

include::types/add.asciidoc[]

==== Subtract `-`
[.text-center]
image::esql/functions/signature/sub.svg[Embedded,opts=inline]

Supported types:

include::types/sub.asciidoc[]

==== Multiply `*`
[.text-center]
image::esql/functions/signature/mul.svg[Embedded,opts=inline]

Supported types:

include::types/mul.asciidoc[]

==== Divide `/`
[.text-center]
image::esql/functions/signature/div.svg[Embedded,opts=inline]

Supported types:

include::types/div.asciidoc[]

==== Modulus `%`
[.text-center]
image::esql/functions/signature/mod.svg[Embedded,opts=inline]

Supported types:

include::types/mod.asciidoc[]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/reference/esql/functions/signature/to_degrees.svg

This file was deleted.

12 changes: 12 additions & 0 deletions docs/reference/esql/functions/types/add.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
date_period | date_period | date_period
date_period | datetime | datetime
datetime | date_period | datetime
datetime | time_duration | datetime
double | double | double
integer | integer | integer
long | long | long
time_duration | time_duration | time_duration
|===
7 changes: 7 additions & 0 deletions docs/reference/esql/functions/types/div.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
double | double | double
integer | integer | integer
long | long | long
|===
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/types/equals.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/types/greater_than.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/types/less_than.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
7 changes: 7 additions & 0 deletions docs/reference/esql/functions/types/mod.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
double | double | double
integer | integer | integer
long | long | long
|===
7 changes: 7 additions & 0 deletions docs/reference/esql/functions/types/mul.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
double | double | double
integer | integer | integer
long | long | long
|===
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
v | result
date_period | date_period
double | double
integer | double
long | double
unsigned_long | double
integer | integer
long | long
time_duration | time_duration
|===
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/types/not_equals.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
integer | integer | boolean
|===
11 changes: 11 additions & 0 deletions docs/reference/esql/functions/types/sub.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
lhs | rhs | result
date_period | date_period | date_period
datetime | date_period | datetime
datetime | time_duration | datetime
double | double | double
integer | integer | integer
long | long | long
time_duration | time_duration | time_duration
|===
6 changes: 5 additions & 1 deletion docs/reference/esql/functions/unary.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
[[esql-unary-operators]]
=== Unary operators

These unary mathematical operators are supported:
The only unary operators is negation (`-`):

[.text-center]
image::esql/functions/signature/neg.svg[Embedded,opts=inline]

Supported types:

include::types/neg.asciidoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -976,23 +976,33 @@ public static void renderTypesTable() throws IOException {
if (System.getProperty("generateDocs") == null) {
return;
}
String name = functionName(); // TODO types table for operators
String name = functionName();
if (binaryOperator(name) != null) {
renderTypesTable(List.of("lhs", "rhs"));
return;
}
if (unaryOperator(name) != null) {
renderTypesTable(List.of("v"));
return;
}
FunctionDefinition definition = definition(name);
if (definition == null) {
LogManager.getLogger(getTestClass()).info("Skipping rendering types because the function isn't registered");
if (definition != null) {
renderTypesTable(EsqlFunctionRegistry.description(definition).argNames());
return;
}
LogManager.getLogger(getTestClass()).info("Skipping rendering types because the function isn't registered");
}

List<String> args = EsqlFunctionRegistry.description(definition).argNames();
private static void renderTypesTable(List<String> argNames) throws IOException {
StringBuilder header = new StringBuilder();
for (String arg : args) {
for (String arg : argNames) {
header.append(arg).append(" | ");
}
header.append("result");

List<String> table = new ArrayList<>();
for (Map.Entry<List<DataType>, DataType> sig : signatures.entrySet()) {
if (sig.getKey().size() != args.size()) {
if (sig.getKey().size() != argNames.size()) {
continue;
}
StringBuilder b = new StringBuilder();
Expand Down Expand Up @@ -1035,9 +1045,9 @@ private static String binaryOperator(String name) {
case "div" -> "/";
case "equals" -> "==";
case "greater_than" -> ">";
case "greater_than_or_equal_to" -> ">=";
case "greater_than_or_equal" -> ">=";
case "less_than" -> "<";
case "less_than_or_equal_to" -> "<=";
case "less_than_or_equal" -> "<=";
case "mod" -> "%";
case "mul" -> "*";
case "not_equals" -> "!=";
Expand Down

0 comments on commit 42e8e68

Please sign in to comment.