esql-functions.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. [[esql-functions]]
  2. == ESQL functions
  3. <<esql-eval,`EVAL`>> and <<esql-where,`WHERE`>> support the following functions:
  4. [discrete]
  5. [[esql-abs]]
  6. === `ABS`
  7. Returns the absolute value.
  8. [source,esql]
  9. ----
  10. FROM employees
  11. | PROJECT first_name, last_name, height
  12. | EVAL abs_height = ABS(0.0 - height)
  13. ----
  14. [discrete]
  15. [[esql-concat]]
  16. === `CONCAT`
  17. Concatenates two or more strings.
  18. [source,esql]
  19. ----
  20. FROM employees
  21. | PROJECT first_name, last_name, height
  22. | EVAL fullname = CONCAT(first_name, " ", last_name)
  23. ----
  24. [discrete]
  25. [[esql-date_format]]
  26. === `DATE_FORMAT`
  27. Returns a string representation of a date in the provided format. If no format
  28. is specified, the `yyyy-MM-dd'T'HH:mm:ss.SSSZ` format is used.
  29. [source,esql]
  30. ----
  31. FROM employees
  32. | PROJECT first_name, last_name, hire_date
  33. | EVAL hired = DATE_FORMAT(hire_date, "YYYY-MM-dd")
  34. ----
  35. [discrete]
  36. [[esql-date_trunc]]
  37. === `DATE_TRUNC`
  38. Rounds down a date to the closest interval. Intervals can be expressed using the
  39. <<esql-timespan-literals,timespan literal syntax>>.
  40. [source,esql]
  41. ----
  42. FROM employees
  43. | EVAL year_hired = DATE_TRUNC(hire_date, 1 year)
  44. | STATS count(emp_no) BY year_hired
  45. | SORT year_hired
  46. ----
  47. [discrete]
  48. [[esql-is_null]]
  49. === `IS_NULL`
  50. Returns a boolean than indicates whether its input is `null`.
  51. [source,esql]
  52. ----
  53. FROM employees
  54. | WHERE is_null(first_name)
  55. ----
  56. Combine this function with `NOT` to filter out any `null` data:
  57. [source,esql]
  58. ----
  59. FROM employees
  60. | WHERE NOT is_null(first_name)
  61. ----
  62. [discrete]
  63. [[esql-length]]
  64. === `LENGTH`
  65. Returns the character length of a string.
  66. [source,esql]
  67. ----
  68. FROM employees
  69. | PROJECT first_name, last_name, height
  70. | EVAL fn_length = LENGTH(first_name)
  71. ----
  72. [discrete]
  73. [[esql-round]]
  74. === `ROUND`
  75. Rounds a number to the closest number with the specified number of digits.
  76. Defaults to 0 digits if no number of digits is provided. If the specified number
  77. of digits is negative, rounds to the number of digits left of the decimal point.
  78. [source,esql]
  79. ----
  80. FROM employees
  81. | PROJECT first_name, last_name, height
  82. | EVAL height = ROUND(height * 3.281, 1)
  83. ----
  84. [discrete]
  85. [[esql-starts_with]]
  86. === `STARTS_WITH`
  87. Returns a boolean that indicates whether a keyword string starts with another
  88. string:
  89. [source,esql]
  90. ----
  91. FROM employees
  92. | PROJECT first_name, last_name, height
  93. | EVAL ln_S = STARTS_WITH(last_name, "S")
  94. ----
  95. [discrete]
  96. [[esql-substring]]
  97. === `SUBSTRING`
  98. Returns a substring of a string, specified by a start position and an optional
  99. length. This example returns the first three characters of every last name:
  100. [source,esql]
  101. ----
  102. FROM employees
  103. | PROJECT last_name
  104. | EVAL ln_sub = SUBSTRING(last_name, 1, 3)
  105. ----
  106. A negative start position is interpreted as being relative to the end of the
  107. string. This example returns the last three characters of of every last name:
  108. [source,esql]
  109. ----
  110. FROM employees
  111. | PROJECT last_name
  112. | EVAL ln_sub = SUBSTRING(last_name, -3, 3)
  113. ----
  114. If length is omitted, substring returns the remainder of the string. This
  115. example returns all characters except for the first:
  116. [source,esql]
  117. ----
  118. FROM employees
  119. | PROJECT last_name
  120. | EVAL ln_sub = SUBSTRING(last_name, 2)
  121. ----