Skip to content

Commit 4d8244c

Browse files
committed
Added generated test examples to change_point docs
1 parent 9f01187 commit 4d8244c

File tree

4 files changed

+89
-13
lines changed

4 files changed

+89
-13
lines changed

docs/reference/query-languages/esql/README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,78 @@ These are also generated as part of the unit tests described above.
7979

8080
### Adding a new command
8181

82-
When adding a new command, for example adding the `CHANGE_POINT` comamand, do the following:
82+
When adding a new command, for example adding the `CHANGE_POINT` command, do the following:
8383
1. Create a new file in the `_snippets/commands/layout` directory with the name of the command, for example `change_point.md`.
8484
2. Add the content for the command to the file. See other files in this directory for examples.
8585
3. Add the command to the list in `_snippets/lists/processing-commands-md`.
8686
4. Add an include directive to the `commands/processing-commands.md` file to include the new command.
8787
5. Add tested examples to the `_snippets/commands/examples` directory. See below for details.
88+
89+
### Adding examples to commands
90+
91+
When adding tested examples to a command, for example adding an example to the `CHANGE_POINT` command, do the following:
92+
* Make sure you have an example in an appropriate csv-spec file in the `x-pack/plugin/esql/qa/testFixtures/src/main/resources/` directory.
93+
* Make sure the example has a tag that is unique in that file, and matches the intent of the test, or the docs reason for including that test.
94+
* If you only want to show the query, and no results, then do not tag the results table,
95+
otherwise tag the results table with a tag that has the same name as the query tag, but with the suffix `-result`.
96+
* Create a file with the name of the tag in a subdirectory with the name of the csv-spec file
97+
in the `_snippets/commands/examples` directory. While you could add the content to that file, it is not necessary, merely that the file exists
98+
* Run the test `CommandsDocsTests` in the `x-pack/plugin/esql` module to generate the content.
99+
100+
For example, we tag the following test in change_point.csv-spec:
101+
102+
```
103+
example for docs
104+
required_capability: change_point
105+
106+
// tag::changePointForDocs[]
107+
ROW key=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
108+
| MV_EXPAND key
109+
| EVAL value = CASE(key<13, 0, 42)
110+
| CHANGE_POINT value ON key
111+
| WHERE type IS NOT NULL
112+
// end::changePointForDocs[]
113+
;
114+
115+
// tag::changePointForDocs-result[]
116+
key:integer | value:integer | type:keyword | pvalue:double
117+
13 | 42 | step_change | 0.0
118+
// end::changePointForDocs-result[]
119+
;
120+
```
121+
122+
Then we create the file `_snippets/commands/examples/change_point.csv-spec/changePointForDocs.md` with the content:
123+
```
124+
This should be overwritten
125+
```
126+
127+
Then we run the test `CommandsDocsTests` in the `x-pack/plugin/esql` module to generate the content.
128+
129+
Now the content of the changePointForDocs.md file should have been updated:
130+
131+
```
132+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
133+
134+
\```esql
135+
ROW key=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
136+
| MV_EXPAND key
137+
| EVAL value = CASE(key<13, 0, 42)
138+
| CHANGE_POINT value ON key
139+
| WHERE type IS NOT NULL
140+
\```
141+
142+
| key:integer | value:integer | type:keyword | pvalue:double |
143+
| --- | --- | --- | --- |
144+
| 13 | 42 | step_change | 0.0 |
145+
```
146+
147+
Finally include this file in the `CHANGE_POINT` command file `_snippets/commands/layout/change_point.md`:
148+
149+
```
150+
**Examples**
151+
152+
The following example shows the detection of a step change:
153+
154+
:::{include} ../examples/change_point.csv-spec/changePointForDocs.md
155+
:::
156+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
```esql
4+
ROW key=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
5+
| MV_EXPAND key
6+
| EVAL value = CASE(key<13, 0, 42)
7+
| CHANGE_POINT value ON key
8+
| WHERE type IS NOT NULL
9+
```
10+
11+
| key:integer | value:integer | type:keyword | pvalue:double |
12+
| --- | --- | --- | --- |
13+
| 13 | 42 | step_change | 0.0 |

docs/reference/query-languages/esql/_snippets/commands/layout/change_point.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,5 @@ There must be at least 22 values for change point detection. Fewer than 1,000 is
5050

5151
The following example shows the detection of a step change:
5252

53-
```
54-
ROW key = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
55-
| MV_EXPAND key
56-
| EVAL value = CASE(key<13, 0, 42)
57-
| CHANGE_POINT value ON key
58-
| WHERE type IS NOT NULL
59-
;
60-
```
61-
62-
| key:integer | value:integer | type:keyword | pvalue:double |
63-
|-------------|---------------|--------------|---------------|
64-
| 13 | 42 | step_change | 0.0 |
53+
:::{include} ../examples/change_point.csv-spec/changePointForDocs.md
54+
:::

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,13 +1203,17 @@ true | 1 | null | null
12031203
example for docs
12041204
required_capability: change_point
12051205

1206+
// tag::changePointForDocs[]
12061207
ROW key=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
12071208
| MV_EXPAND key
12081209
| EVAL value = CASE(key<13, 0, 42)
12091210
| CHANGE_POINT value ON key
12101211
| WHERE type IS NOT NULL
1212+
// end::changePointForDocs[]
12111213
;
12121214

1215+
// tag::changePointForDocs-result[]
12131216
key:integer | value:integer | type:keyword | pvalue:double
12141217
13 | 42 | step_change | 0.0
1218+
// end::changePointForDocs-result[]
12151219
;

0 commit comments

Comments
 (0)