Browse Source

Move IS_NULL, POW, ROUND, STARTS_WITH, SUBSTRING code snippets to CSV files

Abdon Pijpelink 2 years ago
parent
commit
68b74bea34

+ 13 - 7
docs/reference/esql/functions/is_null.asciidoc

@@ -1,17 +1,23 @@
 [[esql-is_null]]
 === `IS_NULL`
-Returns a boolean than indicates whether its input is `null`.
+Returns a boolean that indicates whether its input is `null`.
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| WHERE IS_NULL(first_name)
+include::{esql-specs}/docs.csv-spec[tag=isNull]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=isNull-result]
+|===
 
 Combine this function with `NOT` to filter out any `null` data:
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| WHERE NOT IS_NULL(first_name)
+include::{esql-specs}/docs.csv-spec[tag=notIsNull]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=notIsNull-result]
+|===

+ 6 - 3
docs/reference/esql/functions/pow.asciidoc

@@ -3,8 +3,11 @@
 Returns the the value of a base (first argument) raised to a power (second
 argument).
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-ROW base = 2.0, exponent = 2.0
-| EVAL s = POW(base, exponent)
+include::{esql-specs}/math.csv-spec[tag=pow]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/math.csv-spec[tag=pow-result]
+|===

+ 6 - 4
docs/reference/esql/functions/round.asciidoc

@@ -4,9 +4,11 @@ Rounds a number to the closest number with the specified number of digits.
 Defaults to 0 digits if no number of digits is provided. If the specified number
 of digits is negative, rounds to the number of digits left of the decimal point.
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| KEEP first_name, last_name, height
-| EVAL height = ROUND(height * 3.281, 1)
+include::{esql-specs}/docs.csv-spec[tag=round]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=round-result]
+|===

+ 6 - 4
docs/reference/esql/functions/starts_with.asciidoc

@@ -3,9 +3,11 @@
 Returns a boolean that indicates whether a keyword string starts with another
 string:
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| KEEP first_name, last_name, height
-| EVAL ln_S = STARTS_WITH(last_name, "S")
+include::{esql-specs}/docs.csv-spec[tag=startsWith]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=startsWith-result]
+|===

+ 18 - 12
docs/reference/esql/functions/substring.asciidoc

@@ -3,29 +3,35 @@
 Returns a substring of a string, specified by a start position and an optional
 length. This example returns the first three characters of every last name:
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| KEEP last_name
-| EVAL ln_sub = SUBSTRING(last_name, 1, 3)
+include::{esql-specs}/docs.csv-spec[tag=substring]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=substring-result]
+|===
 
 A negative start position is interpreted as being relative to the end of the
 string. This example returns the last three characters of of every last name:
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| KEEP last_name
-| EVAL ln_sub = SUBSTRING(last_name, -3, 3)
+include::{esql-specs}/docs.csv-spec[tag=substringEnd]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=substringEnd-result]
+|===
 
 If length is omitted, substring returns the remainder of the string. This
 example returns all characters except for the first:
 
-[source,esql]
+[source.merge.styled,esql]
 ----
-FROM employees
-| KEEP last_name
-| EVAL ln_sub = SUBSTRING(last_name, 2)
+include::{esql-specs}/docs.csv-spec[tag=substringRemainder]
 ----
+[%header.monospaced.styled,format=dsv,separator=|]
+|===
+include::{esql-specs}/docs.csv-spec[tag=substringRemainder-result]
+|===

+ 129 - 0
x-pack/plugin/esql/qa/testFixtures/src/main/resources/docs.csv-spec

@@ -286,3 +286,132 @@ Tse            |Herber         |1.45
 Udi            |Jansch         |1.93
 Uri            |Lenart         |1.75
 ;
+
+docsSubstring
+// tag::substring[]
+FROM employees
+| KEEP last_name
+| EVAL ln_sub = SUBSTRING(last_name, 1, 3)
+// end::substring[]
+| SORT last_name ASC
+| LIMIT 5
+;
+
+// tag::substring-result[]
+last_name:keyword | ln_sub:keyword
+Awdeh          |Awd
+Azuma          |Azu
+Baek           |Bae
+Bamford        |Bam
+Bernatsky      |Ber
+// end::substring-result[]
+;
+
+docsSubstringEnd
+// tag::substringEnd[]
+FROM employees
+| KEEP last_name
+| EVAL ln_sub = SUBSTRING(last_name, -3, 3)
+// end::substringEnd[]
+| SORT last_name ASC
+| LIMIT 5
+;
+
+// tag::substringEnd-result[]
+last_name:keyword | ln_sub:keyword
+Awdeh          |deh
+Azuma          |uma
+Baek           |aek
+Bamford        |ord
+Bernatsky      |sky
+// end::substringEnd-result[]
+;
+
+docsSubstringRemainder
+// tag::substringRemainder[]
+FROM employees
+| KEEP last_name
+| EVAL ln_sub = SUBSTRING(last_name, 2)
+// end::substringRemainder[]
+| SORT last_name ASC
+| LIMIT 5
+;
+
+// tag::substringRemainder-result[]
+last_name:keyword | ln_sub:keyword
+Awdeh          |wdeh
+Azuma          |zuma
+Baek           |aek
+Bamford        |amford
+Bernatsky      |ernatsky
+// end::substringRemainder-result[]
+;
+
+docsStartsWith
+// tag::startsWith[]
+FROM employees
+| KEEP last_name
+| EVAL ln_S = STARTS_WITH(last_name, "B")
+// end::startsWith[]
+| SORT last_name ASC
+| LIMIT 5
+;
+
+// tag::startsWith-result[]
+last_name:keyword | ln_S:boolean
+Awdeh          |false
+Azuma          |false
+Baek           |true
+Bamford        |true
+Bernatsky      |true
+// end::startsWith-result[]
+;
+
+docsRound
+// tag::round[]
+FROM employees
+| KEEP first_name, last_name, height
+| EVAL height_ft = ROUND(height * 3.281, 1)
+// end::round[]
+| SORT height DESC, first_name ASC
+| LIMIT 3;
+
+// tag::round-result[]
+first_name:keyword | last_name:keyword | height:double | height_ft:double
+Arumugam       |Ossenbruggen   |2.1          |6.9
+Kwee           |Schusler       |2.1          |6.9
+Saniya         |Kalloufi       |2.1          |6.9
+// end::round-result[]
+;
+
+docsIsNull
+// tag::isNull[]
+FROM employees
+| KEEP first_name, last_name
+| WHERE IS_NULL(first_name)
+// end::isNull[]
+| LIMIT 3;
+
+// tag::isNull-result[]
+first_name:keyword | last_name:keyword
+null           |Demeyer
+null           |Joslin
+null           |Reistad
+// end::isNull-result[]
+;
+
+docsNotIsNull
+// tag::notIsNull[]
+FROM employees
+| KEEP first_name, last_name
+| WHERE NOT IS_NULL(first_name)
+// end::notIsNull[]
+| LIMIT 3;
+
+// tag::notIsNull-result[]
+first_name:keyword | last_name:keyword
+Georgi         |Facello
+Bezalel        |Simmel
+Parto          |Bamford
+// end::notIsNull-result[]
+;

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

@@ -215,10 +215,16 @@ Infinity | true
 ;
 
 powDoubleDouble
-row base = 2.0, exponent = 2.0 | eval s = pow(base, exponent);
+// tag::pow[]
+ROW base = 2.0, exponent = 2.0
+| EVAL s = POW(base, exponent)
+// end::pow[]
+;
 
+// tag::pow-result[]
 base:double | exponent:double | s:double
 2.0         | 2.0             | 4.0
+// end::pow-result[]
 ;
 
 powDoubleInt