Skip to content

Commit d96f7fa

Browse files
authored
Require all functions to provide examples (#135094)
1 parent 0308ee2 commit d96f7fa

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

docs/reference/query-languages/esql/_snippets/functions/examples/copy_sign.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/copy_sign.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/copy_sign.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/docs/functions/copy_sign.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,15 +1855,19 @@ cs1:double | cs2:integer | cs3:integer
18551855
copySignWithMixedNumericValuesWithMV
18561856
required_capability: copy_sign
18571857

1858+
// tag::copy_sign[]
18581859
FROM employees
18591860
| EVAL cs1 = COPY_SIGN(salary, LEAST(salary_change))
1861+
// end::copy_sign[]
18601862
| KEEP emp_no, salary, salary_change, cs1
18611863
| SORT emp_no
18621864
| LIMIT 3
18631865
;
18641866

1865-
emp_no:integer | salary:integer | salary_change:double | cs1:integer
1866-
10001 | 57305 | 1.19 | 57305
1867-
10002 | 56371 | [-7.23, 11.17] | -56371
1868-
10003 | 61805 | [12.82, 14.68] | 61805
1867+
// tag::copy_sign-result[]
1868+
emp_no:integer | salary:integer | salary_change:double | cs1:integer
1869+
10001 | 57305 | 1.19 | 57305
1870+
10002 | 56371 | [-7.23, 11.17] | -56371
1871+
10003 | 61805 | [12.82, 14.68] | 61805
1872+
// end::copy_sign-result[]
18691873
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/CopySign.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2020
import org.elasticsearch.xpack.esql.core.tree.Source;
2121
import org.elasticsearch.xpack.esql.core.type.DataType;
22+
import org.elasticsearch.xpack.esql.expression.function.Example;
2223
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
2324
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
2425
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
@@ -69,7 +70,8 @@ EvalOperator.ExpressionEvaluator.Factory create(
6970
This function is similar to Java's Math.copySign(double magnitude, double sign) which is
7071
similar to `copysign` from [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754).""",
7172
returnType = { "double", "integer", "long" },
72-
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.GA, version = "9.1.0") }
73+
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.GA, version = "9.1.0") },
74+
examples = { @Example(file = "math", tag = "copy_sign") }
7375
)
7476
public CopySign(
7577
Source source,

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,11 @@ void renderKibanaFunctionDefinition(
14021402
builder.value(loadExample(example.file(), example.tag()));
14031403
}
14041404
builder.endArray();
1405+
} else if (info.operator().isEmpty()) {
1406+
// CI will fail in Kibana if we add a function with no examples
1407+
throw new IllegalArgumentException(
1408+
"Failed to write Kibana function definition: no examples found for function [" + name + "]."
1409+
);
14051410
}
14061411
builder.field("preview", info.preview());
14071412
builder.field("snapshot_only", EsqlFunctionRegistry.isSnapshotOnly(name));

0 commit comments

Comments
 (0)