Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESQL] Add SPACE function #112350

Merged
merged 25 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6c961ad
Initial implementation of SPACE() function.
chrisberkhout Aug 25, 2024
6e6003c
SpaceTests.java
chrisberkhout Aug 25, 2024
4c4fa12
Add docs.
chrisberkhout Aug 26, 2024
43eb5bc
Remove warnExceptions parameter from the @Evaluator for processConstant.
chrisberkhout Aug 29, 2024
b47dc54
Extract duplicate checks of number parameter range.
chrisberkhout Aug 29, 2024
72350cf
Test and fix type resolution.
chrisberkhout Aug 29, 2024
991dd76
Add test for requesting space too large.
chrisberkhout Aug 29, 2024
bb3bc07
Improve example for documentation.
chrisberkhout Aug 29, 2024
91f62b9
Revert "Improve example for documentation." (Doc doesn't render extra…
chrisberkhout Aug 29, 2024
1f4ec7a
Add new capability for function SPACE.
chrisberkhout Aug 29, 2024
d2a452c
Update docs/changelog/112350.yaml
chrisberkhout Aug 29, 2024
f76cf79
Fix style.
chrisberkhout Aug 29, 2024
8ec8c6a
Test with input from an index.
chrisberkhout Aug 29, 2024
b1047ec
Add serialization tests.
chrisberkhout Aug 29, 2024
f804232
Add more testing advice to the guide to adding a new function.
chrisberkhout Aug 29, 2024
645730a
Remove constant evaluator in favor of building a literal.
chrisberkhout Aug 29, 2024
0540423
Use `field` in the superclass rather than adding `number`.
chrisberkhout Aug 29, 2024
bd688ee
Fix test.
chrisberkhout Aug 30, 2024
74ac4cc
Simplify test setup.
chrisberkhout Aug 31, 2024
f7d6435
Bulk fill with Arrays.fill rather than a loop.
chrisberkhout Aug 31, 2024
98e5cef
Update description as suggested.
chrisberkhout Aug 31, 2024
8a6c216
Make Space.MAX_LENGTH private.
chrisberkhout Aug 31, 2024
d03fef3
Add more complex test.
chrisberkhout Aug 31, 2024
8e4f1c5
Return null and warnings for a multi-value parameter.
chrisberkhout Aug 31, 2024
0408b00
Merge branch 'main' into esql-functions-space
chrisberkhout Sep 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/112350.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112350
summary: "[ESQL] Add `SPACE` function"
area: ES|QL
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/reference/esql/functions/description/space.asciidoc

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

13 changes: 13 additions & 0 deletions docs/reference/esql/functions/examples/space.asciidoc

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

23 changes: 23 additions & 0 deletions docs/reference/esql/functions/kibana/definition/space.json

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

10 changes: 10 additions & 0 deletions docs/reference/esql/functions/kibana/docs/space.md

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

15 changes: 15 additions & 0 deletions docs/reference/esql/functions/layout/space.asciidoc

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

6 changes: 6 additions & 0 deletions docs/reference/esql/functions/parameters/space.asciidoc

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

1 change: 1 addition & 0 deletions docs/reference/esql/functions/signature/space.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/reference/esql/functions/string-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* <<esql-replace>>
* <<esql-right>>
* <<esql-rtrim>>
* <<esql-space>>
* <<esql-split>>
* <<esql-starts_with>>
* <<esql-substring>>
Expand All @@ -39,6 +40,7 @@ include::layout/repeat.asciidoc[]
include::layout/replace.asciidoc[]
include::layout/right.asciidoc[]
include::layout/rtrim.asciidoc[]
include::layout/space.asciidoc[]
include::layout/split.asciidoc[]
include::layout/starts_with.asciidoc[]
include::layout/substring.asciidoc[]
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/esql/functions/types/space.asciidoc

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 @@ -72,6 +72,7 @@ double pi()
"double signum(number:double|integer|long|unsigned_long)"
"double sin(angle:double|integer|long|unsigned_long)"
"double sinh(number:double|integer|long|unsigned_long)"
"keyword space(number:integer)"
"keyword split(string:keyword|text, delim:keyword|text)"
"double sqrt(number:double|integer|long|unsigned_long)"
"geo_point|cartesian_point st_centroid_agg(field:geo_point|cartesian_point)"
Expand Down Expand Up @@ -196,6 +197,7 @@ rtrim |string |"keyword|text"
signum |number |"double|integer|long|unsigned_long" |"Numeric expression. If `null`, the function returns `null`."
sin |angle |"double|integer|long|unsigned_long" |An angle, in radians. If `null`, the function returns `null`.
sinh |number |"double|integer|long|unsigned_long" |Numeric expression. If `null`, the function returns `null`.
space |number |"integer" |Number of spaces in result.
split |[string, delim] |["keyword|text", "keyword|text"] |[String expression. If `null`\, the function returns `null`., Delimiter. Only single byte delimiters are currently supported.]
sqrt |number |"double|integer|long|unsigned_long" |"Numeric expression. If `null`, the function returns `null`."
st_centroid_ag|field |"geo_point|cartesian_point" |[""]
Expand Down Expand Up @@ -320,6 +322,7 @@ rtrim |Removes trailing whitespaces from a string.
signum |Returns the sign of the given number. It returns `-1` for negative numbers, `0` for `0` and `1` for positive numbers.
sin |Returns the {wikipedia}/Sine_and_cosine[sine] of an angle.
sinh |Returns the {wikipedia}/Hyperbolic_functions[hyperbolic sine] of a number.
space |Returns a string made of `number` spaces.
split |Split a single valued string into multiple strings.
sqrt |Returns the square root of a number. The input can be any numeric value, the return value is always a double. Square roots of negative numbers and infinities are null.
st_centroid_ag|Calculate the spatial centroid over a field with spatial point geometry type.
Expand Down Expand Up @@ -446,6 +449,7 @@ rtrim |"keyword|text"
signum |double |false |false |false
sin |double |false |false |false
sinh |double |false |false |false
space |keyword |false |false |false
split |keyword |[false, false] |false |false
sqrt |double |false |false |false
st_centroid_ag|"geo_point|cartesian_point" |false |false |true
Expand Down Expand Up @@ -508,5 +512,5 @@ countFunctions#[skip:-8.15.99]
meta functions | stats a = count(*), b = count(*), c = count(*) | mv_expand c;

a:long | b:long | c:long
115 | 115 | 115
116 | 116 | 116
;
Original file line number Diff line number Diff line change
Expand Up @@ -1595,4 +1595,100 @@ emp_no:integer | languages:integer | first_name:keyword
10004 | 5 | ChirstianChirstianChirstianChirstianChirstian
;

space
required_capability: space
// tag::space[]
ROW message = CONCAT("Hello", SPACE(1), "World!");
// end::space[]

// tag::space-result[]
message:keyword
Hello World!
// end::space-result[]
;

spaceLength
required_capability: space
ROW len = LENGTH(SPACE(12));

len:integer
12
;

spaceCalculated
required_capability: space
ROW inner_width = 20, title = "Title"
| EVAL lspace = SPACE((inner_width-LENGTH(title))/2),
rspace = SPACE(inner_width-LENGTH(lspace)-LENGTH(title)),
centered_title = CONCAT("<",lspace,title,rspace,">")
| KEEP inner_width, centered_title;

inner_width:integer | centered_title:keyword
20 | < Title >
;

spaceNumberFromIndex
required_capability: space
FROM employees
| EVAL s = CONCAT("<",SPACE(languages),">")
| WHERE emp_no < 10005
| SORT emp_no
| KEEP emp_no, languages, s;

emp_no:integer | languages:integer | s:keyword
10001 | 2 | < >
10002 | 5 | < >
10003 | 4 | < >
10004 | 5 | < >
;

spaceZero
required_capability: space
ROW s = SPACE(0);

s:keyword
""
;

spaceNull
required_capability: space
ROW s = SPACE(null);

s:keyword
null
;

spaceNegative
required_capability: space
FROM employees | SORT emp_no | LIMIT 1 | EVAL s = SPACE(-LENGTH(first_name)) | KEEP s;

warning:Line 1:51: evaluation of [SPACE(-LENGTH(first_name))] failed, treating result as null. Only first 20 failures recorded.
warning:Line 1:51: java.lang.IllegalArgumentException: Number parameter cannot be negative, found [-6]

s:keyword
chrisberkhout marked this conversation as resolved.
Show resolved Hide resolved
null
;
chrisberkhout marked this conversation as resolved.
Show resolved Hide resolved

spaceComplex
required_capability: space
ROW x = 1+2+3, y = null | EVAL z = x + 5 | LIMIT 1
| EVAL xs = SPACE(x), xsc = CONCAT("<",xs,">"),
xn = SPACE(null),
xz = SPACE(z), xzc = CONCAT("<",xz,">"),
lxz = LENGTH(xz), lxs = LENGTH(xs), ltr = LENGTH(TRIM(xz))
| DROP xs, xz;

x:integer | y:null | z:integer | xsc:keyword | xn:keyword | xzc:keyword | lxz:integer | lxs:integer | ltr:integer
6 | null | 11 | < > | null | < > | 11 | 6 | 0
;

spaceMV
required_capability: space
ROW mv = [1,2,3] | EVAL x = space(mv) | KEEP x;

warning:Line 1:29: evaluation of [space(mv)] failed, treating result as null. Only first 20 failures recorded.
warning:Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value

x:keyword
null
;

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 @@ -274,7 +274,12 @@ public enum Cap {
/**
* Allow mixed numeric types in coalesce
*/
MIXED_NUMERIC_TYPES_IN_COALESCE;
MIXED_NUMERIC_TYPES_IN_COALESCE,

/**
* Support for requesting the "SPACE" function.
*/
SPACE;

private final boolean snapshotOnly;
private final FeatureFlag featureFlag;
Expand Down
Loading