1
0

eval.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. [discrete]
  2. [[esql-eval]]
  3. === `EVAL`
  4. The `EVAL` processing command enables you to append new columns with calculated
  5. values.
  6. **Syntax**
  7. [source,esql]
  8. ----
  9. EVAL [column1 =] value1[, ..., [columnN =] valueN]
  10. ----
  11. *Parameters*
  12. `columnX`::
  13. The column name.
  14. `valueX`::
  15. The value for the column. Can be a literal, an expression, or a
  16. <<esql-functions,function>>.
  17. *Description*
  18. The `EVAL` processing command enables you to append new columns with calculated
  19. values. `EVAL` supports various functions for calculating values. Refer to
  20. <<esql-functions,Functions>> for more information.
  21. *Examples*
  22. [source.merge.styled,esql]
  23. ----
  24. include::{esql-specs}/eval.csv-spec[tag=eval]
  25. ----
  26. [%header.monospaced.styled,format=dsv,separator=|]
  27. |===
  28. include::{esql-specs}/eval.csv-spec[tag=eval-result]
  29. |===
  30. If the specified column already exists, the existing column will be dropped, and
  31. the new column will be appended to the table:
  32. [source.merge.styled,esql]
  33. ----
  34. include::{esql-specs}/eval.csv-spec[tag=evalReplace]
  35. ----
  36. [%header.monospaced.styled,format=dsv,separator=|]
  37. |===
  38. include::{esql-specs}/eval.csv-spec[tag=evalReplace-result]
  39. |===
  40. Specifying the output column name is optional. If not specified, the new column
  41. name is equal to the expression. The following query adds a column named
  42. `height*3.281`:
  43. [source.merge.styled,esql]
  44. ----
  45. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn]
  46. ----
  47. [%header.monospaced.styled,format=dsv,separator=|]
  48. |===
  49. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn-result]
  50. |===
  51. Because this name contains special characters, <<esql-identifiers,it needs to be
  52. quoted>> with backticks (+{backtick}+) when using it in subsequent commands:
  53. [source.merge.styled,esql]
  54. ----
  55. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats]
  56. ----
  57. [%header.monospaced.styled,format=dsv,separator=|]
  58. |===
  59. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats-result]
  60. |===