2018-06-22 18:40:25 -04:00
|
|
|
[role="xpack"]
|
|
|
|
[testenv="basic"]
|
2017-12-13 10:19:31 -05:00
|
|
|
[[sql-functions]]
|
|
|
|
== Functions and Operators
|
|
|
|
|
2018-09-05 18:19:49 -04:00
|
|
|
{es-sql} provides a comprehensive set of built-in operators and functions:
|
|
|
|
|
|
|
|
* <<sql-operators, Operators>>
|
2019-04-01 11:01:03 -04:00
|
|
|
** <<sql-operators-equality>>
|
|
|
|
** <<sql-operators-null-safe-equality>>
|
|
|
|
** <<sql-operators-inequality>>
|
|
|
|
** <<sql-operators-comparison>>
|
|
|
|
** <<sql-operators-between>>
|
|
|
|
** <<sql-operators-is-null>>
|
|
|
|
** <<sql-operators-in>>
|
|
|
|
** <<sql-operators-and>>
|
|
|
|
** <<sql-operators-or>>
|
|
|
|
** <<sql-operators-not>>
|
|
|
|
** <<sql-operators-plus>>
|
|
|
|
** <<sql-operators-subtract>>
|
|
|
|
** <<sql-operators-negate>>
|
|
|
|
** <<sql-operators-multiply>>
|
|
|
|
** <<sql-operators-divide>>
|
|
|
|
** <<sql-operators-remainder>>
|
|
|
|
** <<sql-operators-cast-cast>>
|
|
|
|
* <<sql-like-rlike-operators>>
|
|
|
|
** <<sql-like-operator>>
|
|
|
|
** <<sql-rlike-operator>>
|
|
|
|
* <<sql-functions-aggs>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-aggs-avg>>
|
|
|
|
** <<sql-functions-aggs-count>>
|
|
|
|
** <<sql-functions-aggs-count-all>>
|
|
|
|
** <<sql-functions-aggs-count-distinct>>
|
|
|
|
** <<sql-functions-aggs-first>>
|
|
|
|
** <<sql-functions-aggs-last>>
|
|
|
|
** <<sql-functions-aggs-max>>
|
|
|
|
** <<sql-functions-aggs-min>>
|
|
|
|
** <<sql-functions-aggs-sum>>
|
|
|
|
** <<sql-functions-aggs-kurtosis>>
|
|
|
|
** <<sql-functions-aggs-mad>>
|
|
|
|
** <<sql-functions-aggs-percentile>>
|
|
|
|
** <<sql-functions-aggs-percentile-rank>>
|
|
|
|
** <<sql-functions-aggs-skewness>>
|
|
|
|
** <<sql-functions-aggs-stddev-pop>>
|
|
|
|
** <<sql-functions-aggs-sum-squares>>
|
|
|
|
** <<sql-functions-aggs-var-pop>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-grouping>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-grouping-histogram>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-datetime-interval, Date-Time Operators>>
|
|
|
|
* <<sql-functions-current-date, Date-Time Functions>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-current-date>>
|
2019-04-03 13:35:37 -04:00
|
|
|
** <<sql-functions-current-time>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-current-timestamp>>
|
|
|
|
** <<sql-functions-datetime-day>>
|
|
|
|
** <<sql-functions-datetime-dow>>
|
|
|
|
** <<sql-functions-datetime-doy>>
|
|
|
|
** <<sql-functions-datetime-dayname>>
|
|
|
|
** <<sql-functions-datetime-hour>>
|
|
|
|
** <<sql-functions-datetime-isodow>>
|
|
|
|
** <<sql-functions-datetime-isoweek>>
|
|
|
|
** <<sql-functions-datetime-minuteofday>>
|
|
|
|
** <<sql-functions-datetime-minute>>
|
|
|
|
** <<sql-functions-datetime-month>>
|
|
|
|
** <<sql-functions-datetime-monthname>>
|
|
|
|
** <<sql-functions-now>>
|
|
|
|
** <<sql-functions-datetime-second>>
|
|
|
|
** <<sql-functions-datetime-quarter>>
|
|
|
|
** <<sql-functions-today>>
|
|
|
|
** <<sql-functions-datetime-week>>
|
|
|
|
** <<sql-functions-datetime-year>>
|
|
|
|
** <<sql-functions-datetime-extract>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-search>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-search-match>>
|
|
|
|
** <<sql-functions-search-query>>
|
|
|
|
** <<sql-functions-search-score>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-math>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-math-abs>>
|
|
|
|
** <<sql-functions-math-cbrt>>
|
|
|
|
** <<sql-functions-math-ceil>>
|
|
|
|
** <<sql-functions-math-e>>
|
|
|
|
** <<sql-functions-math-exp>>
|
|
|
|
** <<sql-functions-math-expm1>>
|
|
|
|
** <<sql-functions-math-floor>>
|
|
|
|
** <<sql-functions-math-log>>
|
|
|
|
** <<sql-functions-math-log10>>
|
|
|
|
** <<sql-functions-math-pi>>
|
|
|
|
** <<sql-functions-math-power>>
|
|
|
|
** <<sql-functions-math-random>>
|
|
|
|
** <<sql-functions-math-round>>
|
|
|
|
** <<sql-functions-math-sign>>
|
|
|
|
** <<sql-functions-math-sqrt>>
|
|
|
|
** <<sql-functions-math-truncate>>
|
|
|
|
** <<sql-functions-math-acos>>
|
|
|
|
** <<sql-functions-math-asin>>
|
|
|
|
** <<sql-functions-math-atan>>
|
|
|
|
** <<sql-functions-math-atan2>>
|
|
|
|
** <<sql-functions-math-cos>>
|
|
|
|
** <<sql-functions-math-cosh>>
|
|
|
|
** <<sql-functions-math-cot>>
|
|
|
|
** <<sql-functions-math-degrees>>
|
|
|
|
** <<sql-functions-math-radians>>
|
|
|
|
** <<sql-functions-math-sin>>
|
|
|
|
** <<sql-functions-math-sinh>>
|
|
|
|
** <<sql-functions-math-tan>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-string>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-string-ascii>>
|
|
|
|
** <<sql-functions-string-bit-length>>
|
|
|
|
** <<sql-functions-string-char>>
|
|
|
|
** <<sql-functions-string-char-length>>
|
|
|
|
** <<sql-functions-string-concat>>
|
|
|
|
** <<sql-functions-string-insert>>
|
|
|
|
** <<sql-functions-string-lcase>>
|
|
|
|
** <<sql-functions-string-left>>
|
|
|
|
** <<sql-functions-string-length>>
|
|
|
|
** <<sql-functions-string-locate>>
|
|
|
|
** <<sql-functions-string-ltrim>>
|
|
|
|
** <<sql-functions-string-octet-length>>
|
|
|
|
** <<sql-functions-string-position>>
|
|
|
|
** <<sql-functions-string-repeat>>
|
|
|
|
** <<sql-functions-string-replace>>
|
|
|
|
** <<sql-functions-string-right>>
|
|
|
|
** <<sql-functions-string-rtrim>>
|
|
|
|
** <<sql-functions-string-space>>
|
|
|
|
** <<sql-functions-string-substring>>
|
|
|
|
** <<sql-functions-string-ucase>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-type-conversion>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-type-conversion-cast>>
|
|
|
|
** <<sql-functions-type-conversion-convert>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-conditional>>
|
2019-04-22 12:26:15 -04:00
|
|
|
** <<sql-functions-conditional-case>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-conditional-coalesce>>
|
|
|
|
** <<sql-functions-conditional-greatest>>
|
|
|
|
** <<sql-functions-conditional-ifnull>>
|
2019-04-23 09:30:37 -04:00
|
|
|
** <<sql-functions-conditional-iif>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-conditional-isnull>>
|
|
|
|
** <<sql-functions-conditional-least>>
|
|
|
|
** <<sql-functions-conditional-nullif>>
|
|
|
|
** <<sql-functions-conditional-nvl>>
|
SQL: Add initial geo support (#42031) (#42135)
Adds an initial limited implementations of geo features to SQL. This implementation is based on the [OpenGIS® Implementation Standard for Geographic information - Simple feature access](http://www.opengeospatial.org/standards/sfs), which is the current standard for GIS system implementation. This effort is concentrate on SQL option AKA ISO 19125-2.
Queries that are supported as a result of this initial implementation
Metadata commands
- `DESCRIBE table` - returns the correct column types `GEOMETRY` for geo shapes and geo points.
- `SHOW FUNCTIONS` - returns a list that includes supported `ST_` functions
- `SYS TYPES` and `SYS COLUMNS` display correct types `GEO_SHAPE` and `GEO_POINT` for geo shapes and geo points accordingly.
Returning geoshapes and geopoints from elasticsearch
- `SELECT geom FROM table` - returns the geoshapes and geo_points as libs/geo objects in JDBC or as WKT strings in console.
- `SELECT ST_AsWKT(geom) FROM table;` and `SELECT ST_AsText(geom) FROM table;`- returns the geoshapes ang geopoints in their WKT representation;
Using geopoints to elasticsearch
- The following functions will be supported for geopoints in queries, sorting and aggregations: `ST_GeomFromText`, `ST_X`, `ST_Y`, `ST_Z`, `ST_GeometryType`, and `ST_Distance`. In most cases when used in queries, sorting and aggregations, these function are translated into script. These functions can be used in the SELECT clause for both geopoints and geoshapes.
- `SELECT * FROM table WHERE ST_Distance(ST_GeomFromText(POINT(1 2), point) < 10;` - returns all records for which `point` is located within 10m from the `POINT(1 2)`. In this case the WHERE clause is translated into a range query.
Limitations:
Geoshapes cannot be used in queries, sorting and aggregations as part of this initial effort. In order to fully take advantage of geoshapes we would need to have access to geoshape doc values, which is coming in #37206. `ST_Z` cannot be used on geopoints in queries, sorting and aggregations since we don't store altitude in geo_point doc values.
Relates to #29872
Backport of #42031
2019-05-14 19:57:12 -04:00
|
|
|
* <<sql-functions-geo>>
|
|
|
|
** <<sql-functions-geo-st-as-wkt>>
|
|
|
|
** <<sql-functions-geo-st-distance>>
|
|
|
|
** <<sql-functions-geo-st-geometrytype>>
|
|
|
|
** <<sql-functions-geo-st-wkt-to-sql>>
|
|
|
|
** <<sql-functions-geo-st-x>>
|
|
|
|
** <<sql-functions-geo-st-y>>
|
|
|
|
** <<sql-functions-geo-st-z>>
|
2019-04-01 11:01:03 -04:00
|
|
|
* <<sql-functions-system>>
|
2019-03-28 08:28:07 -04:00
|
|
|
** <<sql-functions-system-database>>
|
|
|
|
** <<sql-functions-system-user>>
|
2018-09-05 18:19:49 -04:00
|
|
|
|
|
|
|
include::operators.asciidoc[]
|
2019-04-01 11:01:03 -04:00
|
|
|
include::like-rlike.asciidoc[]
|
2018-09-05 18:19:49 -04:00
|
|
|
include::aggs.asciidoc[]
|
2018-12-14 11:20:37 -05:00
|
|
|
include::grouping.asciidoc[]
|
2018-09-05 18:19:49 -04:00
|
|
|
include::date-time.asciidoc[]
|
|
|
|
include::search.asciidoc[]
|
|
|
|
include::math.asciidoc[]
|
|
|
|
include::string.asciidoc[]
|
|
|
|
include::type-conversion.asciidoc[]
|
SQL: Add initial geo support (#42031) (#42135)
Adds an initial limited implementations of geo features to SQL. This implementation is based on the [OpenGIS® Implementation Standard for Geographic information - Simple feature access](http://www.opengeospatial.org/standards/sfs), which is the current standard for GIS system implementation. This effort is concentrate on SQL option AKA ISO 19125-2.
Queries that are supported as a result of this initial implementation
Metadata commands
- `DESCRIBE table` - returns the correct column types `GEOMETRY` for geo shapes and geo points.
- `SHOW FUNCTIONS` - returns a list that includes supported `ST_` functions
- `SYS TYPES` and `SYS COLUMNS` display correct types `GEO_SHAPE` and `GEO_POINT` for geo shapes and geo points accordingly.
Returning geoshapes and geopoints from elasticsearch
- `SELECT geom FROM table` - returns the geoshapes and geo_points as libs/geo objects in JDBC or as WKT strings in console.
- `SELECT ST_AsWKT(geom) FROM table;` and `SELECT ST_AsText(geom) FROM table;`- returns the geoshapes ang geopoints in their WKT representation;
Using geopoints to elasticsearch
- The following functions will be supported for geopoints in queries, sorting and aggregations: `ST_GeomFromText`, `ST_X`, `ST_Y`, `ST_Z`, `ST_GeometryType`, and `ST_Distance`. In most cases when used in queries, sorting and aggregations, these function are translated into script. These functions can be used in the SELECT clause for both geopoints and geoshapes.
- `SELECT * FROM table WHERE ST_Distance(ST_GeomFromText(POINT(1 2), point) < 10;` - returns all records for which `point` is located within 10m from the `POINT(1 2)`. In this case the WHERE clause is translated into a range query.
Limitations:
Geoshapes cannot be used in queries, sorting and aggregations as part of this initial effort. In order to fully take advantage of geoshapes we would need to have access to geoshape doc values, which is coming in #37206. `ST_Z` cannot be used on geopoints in queries, sorting and aggregations since we don't store altitude in geo_point doc values.
Relates to #29872
Backport of #42031
2019-05-14 19:57:12 -04:00
|
|
|
include::geo.asciidoc[]
|
2018-11-20 19:43:05 -05:00
|
|
|
include::conditional.asciidoc[]
|
2018-11-28 08:20:04 -05:00
|
|
|
include::system.asciidoc[]
|