Explorar el Código

Add tests to check Alias field type support (ESQL-1044)

Alias type has no specific management in ESQL: an alias field is treated
as a normal field, with the original type (eg. an `alias` field defined
on another `keyword` field is considered as a normal `keyword` field);
an alias field defined on a field of undefined type is considered
undefined as well.
Luigi Dell'Aquila hace 2 años
padre
commit
ea630c4a0a

+ 137 - 16
x-pack/plugin/esql/qa/server/single-node/src/yamlRestTest/resources/rest-api-spec/test/30_types.yml

@@ -4,8 +4,6 @@ constant_keyword:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               kind:
@@ -50,8 +48,6 @@ multivalued keyword:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               card:
@@ -80,8 +76,6 @@ wildcard:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               card:
@@ -119,8 +113,6 @@ numbers:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               i:
@@ -174,8 +166,6 @@ small_numbers:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               b:
@@ -243,8 +233,6 @@ scaled_float:
       indices.create:
         index:  test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               f:
@@ -288,8 +276,6 @@ multivalued boolean:
       indices.create:
         index: test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               booleans:
@@ -318,8 +304,6 @@ ip:
       indices.create:
         index: test
         body:
-          settings:
-            number_of_shards: 5
           mappings:
             properties:
               ip:
@@ -356,3 +340,140 @@ ip:
   - match: {columns.0.type: ip }
   - length: {values: 1 }
   - match: {values.0.0: "127.0.0.1" }
+
+---
+alias:
+  - do:
+      indices.create:
+        index:  test
+        body:
+          mappings:
+            properties:
+              foo:
+                type: keyword
+              bar:
+                type: alias
+                path: foo
+              level1:
+                properties:
+                  level2:
+                    type: long
+              level2_alias:
+                type: alias
+                path: level1.level2
+              some_long:
+                type: long
+              some_long_alias:
+                type: alias
+                path: some_long
+              some_long_alias2:
+                type: alias
+                path: some_long
+              some_date:
+                type: date
+              some_date_alias:
+                type: alias
+                path: some_date
+
+  - do:
+      bulk:
+        index: test
+        refresh: true
+        body:
+          - { "index": { } }
+          - { "foo": "abc", "level1": {"level2": 10}, "some_long": 12, "some_date": "2015-01-01T12:00:00.000Z" }
+          - { "index": { } }
+          - { "foo": "def", "level1": {"level2": 50}, "some_long": 15, "some_date": "2015-01-01T12:00:00.000Z" }
+
+  - do:
+      esql.query:
+        body:
+          query: 'from test | project foo, bar, level1.level2, level2_alias, some_long, some_long_alias, some_long_alias2, some_date, some_date_alias | sort level2_alias'
+  - match: { columns.0.name: foo }
+  - match: { columns.0.type: keyword }
+  - match: { columns.1.name: bar }
+  - match: { columns.1.type: keyword }
+  - match: { columns.2.name: level1.level2 }
+  - match: { columns.2.type: long }
+  - match: { columns.3.name: level2_alias }
+  - match: { columns.3.type: long }
+  - match: { columns.4.name: some_long }
+  - match: { columns.4.type: long }
+  - match: { columns.5.name: some_long_alias }
+  - match: { columns.5.type: long }
+  - match: { columns.6.name: some_long_alias2 }
+  - match: { columns.6.type: long }
+  - match: { columns.7.name: some_date }
+  - match: { columns.7.type: date }
+  - match: { columns.8.name: some_date_alias }
+  - match: { columns.8.type: date }
+  - length: { values: 2 }
+  - match: { values.0.0: abc }
+  - match: { values.0.1: abc }
+  - match: { values.0.2: 10 }
+  - match: { values.0.3: 10 }
+  - match: { values.0.4: 12 }
+  - match: { values.0.5: 12 }
+  - match: { values.0.6: 12 }
+  - match: { values.0.7: 2015-01-01T12:00:00.000Z }
+  - match: { values.0.8: 2015-01-01T12:00:00.000Z }
+  - match: { values.1.0: def }
+  - match: { values.1.1: def }
+  - match: { values.1.2: 50 }
+  - match: { values.1.3: 50 }
+  - match: { values.1.4: 15 }
+  - match: { values.1.5: 15 }
+  - match: { values.1.6: 15 }
+  - match: { values.1.7: 2015-01-01T12:00:00.000Z }
+  - match: { values.1.8: 2015-01-01T12:00:00.000Z }
+
+  - do:
+      esql.query:
+        body:
+          query: 'from test | where bar == "abc" | project foo, bar, level1.level2, level2_alias'
+  - match: { columns.0.name: foo }
+  - match: { columns.0.type: keyword }
+  - match: { columns.1.name: bar }
+  - match: { columns.1.type: keyword }
+  - match: { columns.2.name: level1.level2 }
+  - match: { columns.2.type: long }
+  - match: { columns.3.name: level2_alias }
+  - match: { columns.3.type: long }
+  - length: { values: 1 }
+  - match: { values.0.0: abc }
+  - match: { values.0.1: abc }
+  - match: { values.0.2: 10 }
+  - match: { values.0.3: 10 }
+
+  - do:
+      esql.query:
+        body:
+          query: 'from test | where level2_alias == 10 | project foo, bar, level1.level2, level2_alias'
+  - match: { columns.0.name: foo }
+  - match: { columns.0.type: keyword }
+  - match: { columns.1.name: bar }
+  - match: { columns.1.type: keyword }
+  - match: { columns.2.name: level1.level2 }
+  - match: { columns.2.type: long }
+  - match: { columns.3.name: level2_alias }
+  - match: { columns.3.type: long }
+  - length: { values: 1 }
+  - match: { values.0.0: abc }
+  - match: { values.0.1: abc }
+  - match: { values.0.2: 10 }
+  - match: { values.0.3: 10 }
+
+  - do:
+      esql.query:
+        body:
+          query: 'from test | where level2_alias == 20'
+  - length: { values: 0 }
+
+  - do:
+      esql.query:
+        body:
+          query: 'from test | stats x = max(level2_alias)'
+  - match: { columns.0.name: x }
+  - match: { columns.0.type: long }
+  - length: { values: 1 }
+  - match: { values.0.0: 50 }

+ 65 - 57
x-pack/plugin/esql/qa/server/single-node/src/yamlRestTest/resources/rest-api-spec/test/40_unsupported_types.yml

@@ -38,6 +38,9 @@ unsupported:
                 type: keyword
               geo_point:
                 type: geo_point
+              geo_point_alias:
+                type: alias
+                path: geo_point
               ip_range:
                 type: ip_range
               long_range:
@@ -125,42 +128,44 @@ unsupported:
   - match: { columns.8.type: unsupported }
   - match: { columns.9.name: geo_point }
   - match: { columns.9.type: unsupported }
-  - match: { columns.10.name: histogram }
+  - match: { columns.10.name: geo_point_alias }
   - match: { columns.10.type: unsupported }
-  - match: { columns.11.name: integer_range }
+  - match: { columns.11.name: histogram }
   - match: { columns.11.type: unsupported }
-  - match: { columns.12.name: ip_range }
+  - match: { columns.12.name: integer_range }
   - match: { columns.12.type: unsupported }
-  - match: { columns.13.name: long_range }
+  - match: { columns.13.name: ip_range }
   - match: { columns.13.type: unsupported }
-  - match: { columns.14.name: match_only_text }
+  - match: { columns.14.name: long_range }
   - match: { columns.14.type: unsupported }
-  - match: { columns.15.name: name }
-  - match: { columns.15.type: keyword }
-  - match: { columns.16.name: rank_feature }
-  - match: { columns.16.type: unsupported }
-  - match: { columns.17.name: rank_features }
+  - match: { columns.15.name: match_only_text }
+  - match: { columns.15.type: unsupported }
+  - match: { columns.16.name: name }
+  - match: { columns.16.type: keyword }
+  - match: { columns.17.name: rank_feature }
   - match: { columns.17.type: unsupported }
-  - match: { columns.18.name: search_as_you_type }
+  - match: { columns.18.name: rank_features }
   - match: { columns.18.type: unsupported }
-  - match: { columns.19.name: search_as_you_type._2gram }
+  - match: { columns.19.name: search_as_you_type }
   - match: { columns.19.type: unsupported }
-  - match: { columns.20.name: search_as_you_type._3gram }
+  - match: { columns.20.name: search_as_you_type._2gram }
   - match: { columns.20.type: unsupported }
-  - match: { columns.21.name: search_as_you_type._index_prefix }
+  - match: { columns.21.name: search_as_you_type._3gram }
   - match: { columns.21.type: unsupported }
-  - match: { columns.22.name: shape }
+  - match: { columns.22.name: search_as_you_type._index_prefix }
   - match: { columns.22.type: unsupported }
-  - match: { columns.23.name: some_doc.bar }
-  - match: { columns.23.type: long }
-  - match: { columns.24.name: some_doc.foo }
-  - match: { columns.24.type: keyword }
-  - match: { columns.25.name: text }
-  - match: { columns.25.type: unsupported }
-  - match: { columns.26.name: token_count }
-  - match: { columns.26.type: integer }
-  - match: { columns.27.name: version }
-  - match: { columns.27.type: unsupported }
+  - match: { columns.23.name: shape }
+  - match: { columns.23.type: unsupported }
+  - match: { columns.24.name: some_doc.bar }
+  - match: { columns.24.type: long }
+  - match: { columns.25.name: some_doc.foo }
+  - match: { columns.25.type: keyword }
+  - match: { columns.26.name: text }
+  - match: { columns.26.type: unsupported }
+  - match: { columns.27.name: token_count }
+  - match: { columns.27.type: integer }
+  - match: { columns.28.name: version }
+  - match: { columns.28.type: unsupported }
 
   - length: { values: 1 }
   - match: { values.0.0: "<unsupported>" }
@@ -178,19 +183,20 @@ unsupported:
   - match: { values.0.12: "<unsupported>" }
   - match: { values.0.13: "<unsupported>" }
   - match: { values.0.14: "<unsupported>" }
-  - match: { values.0.15: Alice }
-  - match: { values.0.16: "<unsupported>" }
+  - match: { values.0.15: "<unsupported>" }
+  - match: { values.0.16: Alice }
   - match: { values.0.17: "<unsupported>" }
   - match: { values.0.18: "<unsupported>" }
   - match: { values.0.19: "<unsupported>" }
   - match: { values.0.20: "<unsupported>" }
   - match: { values.0.21: "<unsupported>" }
   - match: { values.0.22: "<unsupported>" }
-  - match: { values.0.23: 12 }
-  - match: { values.0.24: xy }
-  - match: { values.0.25: "<unsupported>" }
-  - match: { values.0.26: 3 }
-  - match: { values.0.27: "<unsupported>" }
+  - match: { values.0.23: "<unsupported>" }
+  - match: { values.0.24: 12 }
+  - match: { values.0.25: xy }
+  - match: { values.0.26: "<unsupported>" }
+  - match: { values.0.27: 3 }
+  - match: { values.0.28: "<unsupported>" }
 
 
 # limit 0
@@ -218,42 +224,44 @@ unsupported:
   - match: { columns.8.type: unsupported }
   - match: { columns.9.name: geo_point }
   - match: { columns.9.type: unsupported }
-  - match: { columns.10.name: histogram }
+  - match: { columns.10.name: geo_point_alias }
   - match: { columns.10.type: unsupported }
-  - match: { columns.11.name: integer_range }
+  - match: { columns.11.name: histogram }
   - match: { columns.11.type: unsupported }
-  - match: { columns.12.name: ip_range }
+  - match: { columns.12.name: integer_range }
   - match: { columns.12.type: unsupported }
-  - match: { columns.13.name: long_range }
+  - match: { columns.13.name: ip_range }
   - match: { columns.13.type: unsupported }
-  - match: { columns.14.name: match_only_text }
+  - match: { columns.14.name: long_range }
   - match: { columns.14.type: unsupported }
-  - match: { columns.15.name: name }
-  - match: { columns.15.type: keyword }
-  - match: { columns.16.name: rank_feature }
-  - match: { columns.16.type: unsupported }
-  - match: { columns.17.name: rank_features }
+  - match: { columns.15.name: match_only_text }
+  - match: { columns.15.type: unsupported }
+  - match: { columns.16.name: name }
+  - match: { columns.16.type: keyword }
+  - match: { columns.17.name: rank_feature }
   - match: { columns.17.type: unsupported }
-  - match: { columns.18.name: search_as_you_type }
+  - match: { columns.18.name: rank_features }
   - match: { columns.18.type: unsupported }
-  - match: { columns.19.name: search_as_you_type._2gram }
+  - match: { columns.19.name: search_as_you_type }
   - match: { columns.19.type: unsupported }
-  - match: { columns.20.name: search_as_you_type._3gram }
+  - match: { columns.20.name: search_as_you_type._2gram }
   - match: { columns.20.type: unsupported }
-  - match: { columns.21.name: search_as_you_type._index_prefix }
+  - match: { columns.21.name: search_as_you_type._3gram }
   - match: { columns.21.type: unsupported }
-  - match: { columns.22.name: shape }
+  - match: { columns.22.name: search_as_you_type._index_prefix }
   - match: { columns.22.type: unsupported }
-  - match: { columns.23.name: some_doc.bar }
-  - match: { columns.23.type: long }
-  - match: { columns.24.name: some_doc.foo }
-  - match: { columns.24.type: keyword }
-  - match: { columns.25.name: text }
-  - match: { columns.25.type: unsupported }
-  - match: { columns.26.name: token_count }
-  - match: { columns.26.type: integer }
-  - match: { columns.27.name: version }
-  - match: { columns.27.type: unsupported }
+  - match: { columns.23.name: shape }
+  - match: { columns.23.type: unsupported }
+  - match: { columns.24.name: some_doc.bar }
+  - match: { columns.24.type: long }
+  - match: { columns.25.name: some_doc.foo }
+  - match: { columns.25.type: keyword }
+  - match: { columns.26.name: text }
+  - match: { columns.26.type: unsupported }
+  - match: { columns.27.name: token_count }
+  - match: { columns.27.type: integer }
+  - match: { columns.28.name: version }
+  - match: { columns.28.type: unsupported }
 
   - length: { values: 0 }