@@ -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:
83831 . Create a new file in the ` _snippets/commands/layout ` directory with the name of the command, for example ` change_point.md ` .
84842 . Add the content for the command to the file. See other files in this directory for examples.
85853 . Add the command to the list in ` _snippets/lists/processing-commands-md ` .
86864 . Add an include directive to the ` commands/processing-commands.md ` file to include the new command.
87875 . 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+ ```
0 commit comments