esql-functions.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. [[esql-functions]]
  2. == ESQL functions
  3. <<esql-eval,`EVAL`>> and <<esql-where,`WHERE`>> support these functions:
  4. * <<esql-abs>>
  5. * <<esql-concat>>
  6. * <<esql-date_format>>
  7. * <<esql-date_trunc>>
  8. * <<esql-is_null>>
  9. * <<esql-length>>
  10. * <<esql-round>>
  11. * <<esql-starts_with>>
  12. * <<esql-substring>>
  13. [[esql-abs]]
  14. === `ABS`
  15. Returns the absolute value.
  16. [source,esql]
  17. ----
  18. FROM employees
  19. | PROJECT first_name, last_name, height
  20. | EVAL abs_height = ABS(0.0 - height)
  21. ----
  22. [[esql-concat]]
  23. === `CONCAT`
  24. Concatenates two or more strings.
  25. [source,esql]
  26. ----
  27. FROM employees
  28. | PROJECT first_name, last_name, height
  29. | EVAL fullname = CONCAT(first_name, " ", last_name)
  30. ----
  31. [[esql-date_format]]
  32. === `DATE_FORMAT`
  33. Returns a string representation of a date in the provided format. If no format
  34. is specified, the `yyyy-MM-dd'T'HH:mm:ss.SSSZ` format is used.
  35. [source,esql]
  36. ----
  37. FROM employees
  38. | PROJECT first_name, last_name, hire_date
  39. | EVAL hired = DATE_FORMAT(hire_date, "YYYY-MM-dd")
  40. ----
  41. [[esql-date_trunc]]
  42. === `DATE_TRUNC`
  43. Rounds down a date to the closest interval. Intervals can be expressed using the
  44. <<esql-timespan-literals,timespan literal syntax>>.
  45. [source,esql]
  46. ----
  47. FROM employees
  48. | EVAL year_hired = DATE_TRUNC(hire_date, 1 year)
  49. | STATS count(emp_no) BY year_hired
  50. | SORT year_hired
  51. ----
  52. [[esql-is_null]]
  53. === `IS_NULL`
  54. Returns a boolean than indicates whether its input is `null`.
  55. [source,esql]
  56. ----
  57. FROM employees
  58. | WHERE is_null(first_name)
  59. ----
  60. Combine this function with `NOT` to filter out any `null` data:
  61. [source,esql]
  62. ----
  63. FROM employees
  64. | WHERE NOT is_null(first_name)
  65. ----
  66. [[esql-length]]
  67. === `LENGTH`
  68. Returns the character length of a string.
  69. [source,esql]
  70. ----
  71. FROM employees
  72. | PROJECT first_name, last_name, height
  73. | EVAL fn_length = LENGTH(first_name)
  74. ----
  75. [[esql-round]]
  76. === `ROUND`
  77. Rounds a number to the closest number with the specified number of digits.
  78. Defaults to 0 digits if no number of digits is provided. If the specified number
  79. of digits is negative, rounds to the number of digits left of the decimal point.
  80. [source,esql]
  81. ----
  82. FROM employees
  83. | PROJECT first_name, last_name, height
  84. | EVAL height = ROUND(height * 3.281, 1)
  85. ----
  86. [[esql-starts_with]]
  87. === `STARTS_WITH`
  88. Returns a boolean that indicates whether a keyword string starts with another
  89. string:
  90. [source,esql]
  91. ----
  92. FROM employees
  93. | PROJECT first_name, last_name, height
  94. | EVAL ln_S = STARTS_WITH(last_name, "S")
  95. ----
  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. ----