limitations.asciidoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-limitations]]
  4. == SQL Limitations
  5. [float]
  6. [[sys-columns-describe-table-nested-fields]]
  7. === Nested fields in `SYS COLUMNS` and `DESCRIBE TABLE`
  8. {es} has a special type of relationship fields called `nested` fields. In {es-sql} they can be used by referencing their inner
  9. sub-fields. Even though `SYS COLUMNS` in non-driver mode (in the CLI and in REST calls) and `DESCRIBE TABLE` will still display
  10. them as having the type `NESTED`, they cannot be used in a query. One can only reference its sub-fields in the form:
  11. [source, sql]
  12. --------------------------------------------------
  13. [nested_field_name].[sub_field_name]
  14. --------------------------------------------------
  15. For example:
  16. [source, sql]
  17. --------------------------------------------------
  18. SELECT dep.dep_name.keyword FROM test_emp GROUP BY languages;
  19. --------------------------------------------------
  20. [float]
  21. === Multi-nested fields
  22. {es-sql} doesn't support multi-nested documents, so a query cannot reference more than one nested field in an index.
  23. This applies to multi-level nested fields, but also multiple nested fields defined on the same level. For example, for this index:
  24. [source, sql]
  25. ----------------------------------------------------
  26. column | type | mapping
  27. ----------------------+---------------+-------------
  28. nested_A |STRUCT |NESTED
  29. nested_A.nested_X |STRUCT |NESTED
  30. nested_A.nested_X.text|VARCHAR |KEYWORD
  31. nested_A.text |VARCHAR |KEYWORD
  32. nested_B |STRUCT |NESTED
  33. nested_B.text |VARCHAR |KEYWORD
  34. ----------------------------------------------------
  35. `nested_A` and `nested_B` cannot be used at the same time, nor `nested_A`/`nested_B` and `nested_A.nested_X` combination.
  36. For such situations, {es-sql} will display an error message.
  37. [float]
  38. === Paginating nested inner hits
  39. When SELECTing a nested field, pagination will not work as expected, {es-sql} will return __at least__ the page size records.
  40. This is because of the way nested queries work in {es}: the root nested field will be returned and it's matching inner nested fields as well,
  41. pagination taking place on the **root nested document and not on its inner hits**.
  42. [float]
  43. [[normalized-keyword-fields]]
  44. === Normalized `keyword` fields
  45. `keyword` fields in {es} can be normalized by defining a `normalizer`. Such fields are not supported in {es-sql}.
  46. [float]
  47. === Array type of fields
  48. Array fields are not supported due to the "invisible" way in which {es} handles an array of values: the mapping doesn't indicate whether
  49. a field is an array (has multiple values) or not, so without reading all the data, {es-sql} cannot know whether a field is a single or multi value.
  50. When multiple values are returned for a field, by default, {es-sql} will throw an exception. However, it is possible to change this behavior through `field_multi_value_leniency` parameter in REST (disabled by default) or
  51. `field.multi.value.leniency` in drivers (enabled by default).
  52. [float]
  53. === Sorting by aggregation
  54. When doing aggregations (`GROUP BY`) {es-sql} relies on {es}'s `composite` aggregation for its support for paginating results.
  55. However this type of aggregation does come with a limitation: sorting can only be applied on the key used for the aggregation's buckets.
  56. {es-sql} overcomes this limitation by doing client-side sorting however as a safety measure, allows only up to *512* rows.
  57. It is recommended to use `LIMIT` for queries that use sorting by aggregation, essentially indicating the top N results that are desired:
  58. [source, sql]
  59. --------------------------------------------------
  60. SELECT * FROM test GROUP BY age ORDER BY COUNT(*) LIMIT 100;
  61. --------------------------------------------------
  62. It is possible to run the same queries without a `LIMIT` however in that case if the maximum size (*512*) is passed, an exception will be
  63. returned as {es-sql} is unable to track (and sort) all the results returned.
  64. [float]
  65. === Using aggregation functions on top of scalar functions
  66. Aggregation functions like <<sql-functions-aggs-min,`MIN`>>, <<sql-functions-aggs-max,`MAX`>>, etc. can only be used
  67. directly on fields, and so queries like `SELECT MAX(abs(age)) FROM test` are not possible.
  68. [float]
  69. === Using a sub-select
  70. Using sub-selects (`SELECT X FROM (SELECT Y)`) is **supported to a small degree**: any sub-select that can be "flattened" into a single
  71. `SELECT` is possible with {es-sql}. For example:
  72. ["source","sql",subs="attributes,macros"]
  73. --------------------------------------------------
  74. include-tagged::{sql-specs}/docs/docs.csv-spec[limitationSubSelect]
  75. --------------------------------------------------
  76. The query above is possible because it is equivalent with:
  77. ["source","sql",subs="attributes,macros"]
  78. --------------------------------------------------
  79. include-tagged::{sql-specs}/docs/docs.csv-spec[limitationSubSelectRewritten]
  80. --------------------------------------------------
  81. But, if the sub-select would include a `GROUP BY` or `HAVING` or the enclosing `SELECT` would be more complex than `SELECT X
  82. FROM (SELECT ...) WHERE [simple_condition]`, this is currently **un-supported**.
  83. [float]
  84. [[first-last-agg-functions-having-clause]]
  85. === Using <<sql-functions-aggs-first, `FIRST`>>/<<sql-functions-aggs-last,`LAST`>> aggregation functions in `HAVING` clause
  86. Using `FIRST` and `LAST` in the `HAVING` clause is not supported. The same applies to
  87. <<sql-functions-aggs-min,`MIN`>> and <<sql-functions-aggs-max,`MAX`>> when their target column
  88. is of type <<keyword, `keyword`>> as they are internally translated to `FIRST` and `LAST`.
  89. [float]
  90. [[group-by-time]]
  91. === Using TIME data type in GROUP BY or <<sql-functions-grouping-histogram>>
  92. Using `TIME` data type as a grouping key is currently not supported. For example:
  93. [source, sql]
  94. -------------------------------------------------------------
  95. SELECT count(*) FROM test GROUP BY CAST(date_created AS TIME);
  96. -------------------------------------------------------------
  97. On the other hand, it can still be used if it's wrapped with a scalar function that returns another data type,
  98. for example:
  99. [source, sql]
  100. -------------------------------------------------------------
  101. SELECT count(*) FROM test GROUP BY MINUTE((CAST(date_created AS TIME));
  102. -------------------------------------------------------------
  103. `TIME` data type is also currently not supported in histogram grouping function. For example:
  104. [source, sql]
  105. -------------------------------------------------------------
  106. SELECT HISTOGRAM(CAST(birth_date AS TIME), INTERVAL '10' MINUTES) as h, COUNT(*) FROM t GROUP BY h
  107. -------------------------------------------------------------