to_long.asciidoc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. [[esql-to_long]]
  2. === `TO_LONG`
  3. Converts an input value to a long value.
  4. The input can be a single- or multi-valued field or an expression. The input
  5. type must be of a boolean, date, string or numeric type.
  6. Example:
  7. [source.merge.styled,esql]
  8. ----
  9. include::{esql-specs}/ints.csv-spec[tag=to_long-str]
  10. ----
  11. [%header.monospaced.styled,format=dsv,separator=|]
  12. |===
  13. include::{esql-specs}/ints.csv-spec[tag=to_long-str-result]
  14. |===
  15. Note that in this example, the last conversion of the string isn't
  16. possible. When this happens, the result is a *null* value. In this case a
  17. _Warning_ header is added to the response. The header will provide information
  18. on the source of the failure:
  19. `"Line 1:113: evaluation of [TO_LONG(str3)] failed, treating result as null. Only first 20 failures recorded."`
  20. A following header will contain the failure reason and the offending value:
  21. `"java.lang.NumberFormatException: For input string: \"foo\""`
  22. If the input parameter is of a date type, its value will be interpreted as
  23. milliseconds since the https://en.wikipedia.org/wiki/Unix_time[Unix epoch],
  24. converted to long.
  25. Boolean *true* will be converted to long *1*, *false* to *0*.