Skip to content

Commit

Permalink
ESQL: All descriptions are a full sentence (elastic#110791)
Browse files Browse the repository at this point in the history
This asserts that all functions have descriptions that are complete
sentences.
  • Loading branch information
nik9000 authored Jul 11, 2024
1 parent 473dc5a commit 55532c8
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/reference/esql/functions/description/locate.asciidoc

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.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/docs/locate.md

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

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/docs/substring.md

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 @@ -275,7 +275,7 @@ ip_prefix |Truncates an IP to a given prefix length.
least |Returns the minimum value from multiple columns. This is similar to <<esql-mv_min>> except it is intended to run on multiple columns at once.
left |Returns the substring that extracts 'length' chars from 'string' starting from the left.
length |Returns the character length of a string.
locate |Returns an integer that indicates the position of a keyword substring within another string
locate |Returns an integer that indicates the position of a keyword substring within another string.
log |Returns the logarithm of a value to a base. The input can be any numeric value, the return value is always a double. Logs of zero, negative numbers, and base of one return `null` as well as a warning.
log10 |Returns the logarithm of a value to base 10. The input can be any numeric value, the return value is always a double. Logs of 0 and negative numbers return `null` as well as a warning.
ltrim |Removes leading whitespaces from a string.
Expand Down Expand Up @@ -320,7 +320,7 @@ st_within |Returns whether the first geometry is within the second geometry.
st_x |Extracts the `x` coordinate from the supplied point. If the points is of type `geo_point` this is equivalent to extracting the `longitude` value.
st_y |Extracts the `y` coordinate from the supplied point. If the points is of type `geo_point` this is equivalent to extracting the `latitude` value.
starts_with |Returns a boolean that indicates whether a keyword string starts with another string.
substring |Returns a substring of a string, specified by a start position and an optional length
substring |Returns a substring of a string, specified by a start position and an optional length.
sum |The sum of a numeric field.
tan |Returns the {wikipedia}/Sine_and_cosine[Tangent] trigonometric function of an angle.
tanh |Returns the {wikipedia}/Hyperbolic_functions[Tangent] hyperbolic function of an angle.
Expand Down Expand Up @@ -351,7 +351,7 @@ to_unsigned_lo|Converts an input value to an unsigned long value. If the input p
to_upper |Returns a new string representing the input string converted to upper case.
to_ver |Converts an input string to a version value.
to_version |Converts an input string to a version value.
top |Collects the top values for a field. Includes repeated values.
top |Collects the top values for a field. Includes repeated values.
trim |Removes leading and trailing whitespaces from a string.
values |Collect values for a field.
weighted_avg |The weighted average of a numeric field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* The description of the function rendered in {@code META FUNCTIONS}
* and the docs.
* and the docs. These should be complete sentences.
*/
String description() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Locate extends EsqlScalarFunction implements OptionalArgument {

@FunctionInfo(
returnType = "integer",
description = "Returns an integer that indicates the position of a keyword substring within another string",
description = "Returns an integer that indicates the position of a keyword substring within another string.",
examples = @Example(file = "string", tag = "locate")
)
public Locate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Substring extends EsqlScalarFunction implements OptionalArgument {

@FunctionInfo(
returnType = "keyword",
description = "Returns a substring of a string, specified by a start position and an optional length",
description = "Returns a substring of a string, specified by a start position and an optional length.",
examples = {
@Example(file = "docs", tag = "substring", description = "This example returns the first three characters of every last name:"),
@Example(file = "docs", tag = "substringEnd", description = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
import static org.elasticsearch.xpack.esql.SerializationTestUtils.assertSerialization;
import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.CARTESIAN;
import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.GEO;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
Expand Down Expand Up @@ -349,6 +351,12 @@ public static void testFunctionInfo() {
List<EsqlFunctionRegistry.ArgSignature> args = description.args();

assertTrue("expect description to be defined", description.description() != null && false == description.description().isEmpty());
assertThat(
"descriptions should be complete sentences",
description.description(),
either(endsWith(".")) // A full sentence
.or(endsWith("∅")) // Math
);

List<Set<String>> typesFromSignature = new ArrayList<>();
Set<String> returnFromSignature = new HashSet<>();
Expand Down

0 comments on commit 55532c8

Please sign in to comment.