123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- [[esql-syntax]]
- === {esql} syntax reference
- ++++
- <titleabbrev>Syntax reference</titleabbrev>
- ++++
- [discrete]
- [[esql-basic-syntax]]
- === Basic syntax
- An {esql} query is composed of a <<esql-commands,source command>> followed
- by an optional series of <<esql-commands,processing commands>>,
- separated by a pipe character: `|`. For example:
- [source,esql]
- ----
- source-command
- | processing-command1
- | processing-command2
- ----
- The result of a query is the table produced by the final processing command.
- For an overview of all supported commands, functions, and operators, refer to <<esql-commands>> and <<esql-functions-operators>>.
- [NOTE]
- ====
- For readability, this documentation puts each processing command on a new
- line. However, you can write an {esql} query as a single line. The following
- query is identical to the previous one:
- [source,esql]
- ----
- source-command | processing-command1 | processing-command2
- ----
- ====
- [discrete]
- [[esql-identifiers]]
- ==== Identifiers
- The identifiers can be used as they are and don't require quoting, unless
- containing special characters, in which case they must be quoted with
- backticks (+{backtick}+). What "special characters" means is command dependent.
- For <<esql-from, FROM>>, <<esql-keep, KEEP>>, <<esql-drop, DROP>>,
- <<esql-rename, RENAME>>, <<esql-mv_expand, MV_EXPAND>> and
- <<esql-enrich, ENRICH>> these are: `=`, +{backtick}+, `,`, ` ` (space), `|` ,
- `[`, `]`, `\t` (TAB), `\r` (CR), `\n` (LF); one `/` is allowed unquoted, but
- a sequence of two or more require quoting.
- The rest of the commands - those allowing for identifiers be used in
- expressions - require quoting if the identifier contains characters other than
- letters, numbers and `_` and doesn't start with a letter, `_` or `@`.
- For instance:
- [source,esql]
- ----
- // Retain just one field
- FROM index
- | KEEP 1.field
- ----
- is legal. However, if same field is to be used with an <<esql-eval, EVAL>>,
- it'd have to be quoted:
- [source,esql]
- ----
- // Copy one field
- FROM index
- | EVAL my_field = `1.field`
- ----
- [discrete]
- [[esql-literals]]
- ==== Literals
- {esql} currently supports numeric and string literals.
- [discrete]
- [[esql-string-literals]]
- ===== String literals
- A string literal is a sequence of unicode characters delimited by double
- quotes (`"`).
- [source,esql]
- ----
- // Filter by a string value
- FROM index
- | WHERE first_name == "Georgi"
- ----
- If the literal string itself contains quotes, these need to be escaped (`\\"`).
- {esql} also supports the triple-quotes (`"""`) delimiter, for convenience:
- [source,esql]
- ----
- ROW name = """Indiana "Indy" Jones"""
- ----
- The special characters CR, LF and TAB can be provided with the usual escaping:
- `\r`, `\n`, `\t`, respectively.
- [discrete]
- [[esql-numeric-literals]]
- ===== Numerical literals
- The numeric literals are accepted in decimal and in the scientific notation
- with the exponent marker (`e` or `E`), starting either with a digit, decimal
- point `.` or the negative sign `-`:
- [source, sql]
- ----
- 1969 -- integer notation
- 3.14 -- decimal notation
- .1234 -- decimal notation starting with decimal point
- 4E5 -- scientific notation (with exponent marker)
- 1.2e-3 -- scientific notation with decimal point
- -.1e2 -- scientific notation starting with the negative sign
- ----
- The integer numeric literals are implicitly converted to the `integer`, `long`
- or the `double` type, whichever can first accommodate the literal's value.
- The floating point literals are implicitly converted the `double` type.
- To obtain constant values of different types, use one of the numeric
- <<esql-type-conversion-functions, conversion functions>>.
- [discrete]
- [[esql-comments]]
- ==== Comments
- {esql} uses C++ style comments:
- * double slash `//` for single line comments
- * `/*` and `*/` for block comments
- [source,esql]
- ----
- // Query the employees index
- FROM employees
- | WHERE height > 2
- ----
- [source,esql]
- ----
- FROM /* Query the employees index */ employees
- | WHERE height > 2
- ----
- [source,esql]
- ----
- FROM employees
- /* Query the
- * employees
- * index */
- | WHERE height > 2
- ----
- [discrete]
- [[esql-timespan-literals]]
- ==== Timespan literals
- Datetime intervals and timespans can be expressed using timespan literals.
- Timespan literals are a combination of a number and a qualifier. These
- qualifiers are supported:
- * `millisecond`/`milliseconds`
- * `second`/`seconds`
- * `minute`/`minutes`
- * `hour`/`hours`
- * `day`/`days`
- * `week`/`weeks`
- * `month`/`months`
- * `year`/`years`
- Timespan literals are not whitespace sensitive. These expressions are all valid:
- * `1day`
- * `1 day`
- * `1 day`
|