esql-syntax.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. [[esql-syntax]]
  2. === {esql} syntax reference
  3. ++++
  4. <titleabbrev>Syntax reference</titleabbrev>
  5. ++++
  6. [discrete]
  7. [[esql-basic-syntax]]
  8. === Basic syntax
  9. An {esql} query is composed of a <<esql-commands,source command>> followed
  10. by an optional series of <<esql-commands,processing commands>>,
  11. separated by a pipe character: `|`. For example:
  12. [source,esql]
  13. ----
  14. source-command
  15. | processing-command1
  16. | processing-command2
  17. ----
  18. The result of a query is the table produced by the final processing command.
  19. For an overview of all supported commands, functions, and operators, refer to <<esql-commands>> and <<esql-functions-operators>>.
  20. [NOTE]
  21. ====
  22. For readability, this documentation puts each processing command on a new
  23. line. However, you can write an {esql} query as a single line. The following
  24. query is identical to the previous one:
  25. [source,esql]
  26. ----
  27. source-command | processing-command1 | processing-command2
  28. ----
  29. ====
  30. [discrete]
  31. [[esql-identifiers]]
  32. ==== Identifiers
  33. The identifiers can be used as they are and don't require quoting, unless
  34. containing special characters, in which case they must be quoted with
  35. backticks (+{backtick}+). What "special characters" means is command dependent.
  36. For <<esql-from, FROM>>, <<esql-keep, KEEP>>, <<esql-drop, DROP>>,
  37. <<esql-rename, RENAME>>, <<esql-mv_expand, MV_EXPAND>> and
  38. <<esql-enrich, ENRICH>> these are: `=`, +{backtick}+, `,`, ` ` (space), `|` ,
  39. `[`, `]`, `\t` (TAB), `\r` (CR), `\n` (LF); one `/` is allowed unquoted, but
  40. a sequence of two or more require quoting.
  41. The rest of the commands - those allowing for identifiers be used in
  42. expressions - require quoting if the identifier contains characters other than
  43. letters, numbers and `_` and doesn't start with a letter, `_` or `@`.
  44. For instance:
  45. [source,esql]
  46. ----
  47. // Retain just one field
  48. FROM index
  49. | KEEP 1.field
  50. ----
  51. is legal. However, if same field is to be used with an <<esql-eval, EVAL>>,
  52. it'd have to be quoted:
  53. [source,esql]
  54. ----
  55. // Copy one field
  56. FROM index
  57. | EVAL my_field = `1.field`
  58. ----
  59. [discrete]
  60. [[esql-literals]]
  61. ==== Literals
  62. {esql} currently supports numeric and string literals.
  63. [discrete]
  64. [[esql-string-literals]]
  65. ===== String literals
  66. A string literal is a sequence of unicode characters delimited by double
  67. quotes (`"`).
  68. [source,esql]
  69. ----
  70. // Filter by a string value
  71. FROM index
  72. | WHERE first_name == "Georgi"
  73. ----
  74. If the literal string itself contains quotes, these need to be escaped (`\\"`).
  75. {esql} also supports the triple-quotes (`"""`) delimiter, for convenience:
  76. [source,esql]
  77. ----
  78. ROW name = """Indiana "Indy" Jones"""
  79. ----
  80. The special characters CR, LF and TAB can be provided with the usual escaping:
  81. `\r`, `\n`, `\t`, respectively.
  82. [discrete]
  83. [[esql-numeric-literals]]
  84. ===== Numerical literals
  85. The numeric literals are accepted in decimal and in the scientific notation
  86. with the exponent marker (`e` or `E`), starting either with a digit, decimal
  87. point `.` or the negative sign `-`:
  88. [source, sql]
  89. ----
  90. 1969 -- integer notation
  91. 3.14 -- decimal notation
  92. .1234 -- decimal notation starting with decimal point
  93. 4E5 -- scientific notation (with exponent marker)
  94. 1.2e-3 -- scientific notation with decimal point
  95. -.1e2 -- scientific notation starting with the negative sign
  96. ----
  97. The integer numeric literals are implicitly converted to the `integer`, `long`
  98. or the `double` type, whichever can first accommodate the literal's value.
  99. The floating point literals are implicitly converted the `double` type.
  100. To obtain constant values of different types, use one of the numeric
  101. <<esql-type-conversion-functions, conversion functions>>.
  102. [discrete]
  103. [[esql-comments]]
  104. ==== Comments
  105. {esql} uses C++ style comments:
  106. * double slash `//` for single line comments
  107. * `/*` and `*/` for block comments
  108. [source,esql]
  109. ----
  110. // Query the employees index
  111. FROM employees
  112. | WHERE height > 2
  113. ----
  114. [source,esql]
  115. ----
  116. FROM /* Query the employees index */ employees
  117. | WHERE height > 2
  118. ----
  119. [source,esql]
  120. ----
  121. FROM employees
  122. /* Query the
  123. * employees
  124. * index */
  125. | WHERE height > 2
  126. ----
  127. [discrete]
  128. [[esql-timespan-literals]]
  129. ==== Timespan literals
  130. Datetime intervals and timespans can be expressed using timespan literals.
  131. Timespan literals are a combination of a number and a qualifier. These
  132. qualifiers are supported:
  133. * `millisecond`/`milliseconds`
  134. * `second`/`seconds`
  135. * `minute`/`minutes`
  136. * `hour`/`hours`
  137. * `day`/`days`
  138. * `week`/`weeks`
  139. * `month`/`months`
  140. * `year`/`years`
  141. Timespan literals are not whitespace sensitive. These expressions are all valid:
  142. * `1day`
  143. * `1 day`
  144. * `1 day`