---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v8.11.0"
    reason: "ESQL is available in 8.11+"
    test_runner_features: "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          number_of_shards: 5
        mappings:
          properties:
            data:
              type: "long"
            data_d:
              type: "double"
            count:
              type: "long"
            count_d:
              type: "double"
            time:
              type: "long"
            color:
              type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "test"
      refresh: true
      body:
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275187
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275188
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275189
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275190
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275191
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275192
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275193
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275194
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275195
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275196
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275197
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275198
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275199
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275200
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275201
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275202
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275203
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275204
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275205
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275206
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275207
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275208
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275209
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275210
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275211
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275212
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275213
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275214
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275215
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275216
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275217
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275218
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275219
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275220
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275221
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275222
        color: "red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275223
        color: "red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275224
        color: "blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275225
        color: "green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275226
        color: "red"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "test_range"
      body:
        settings:
          number_of_shards: 5
        mappings:
          properties:
            date_1:
              type: "date"
              format: "dd-MM-yyyy-MM-dd HH:mm Z"
            date_2:
              type: "date"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      index: "test_range"
      refresh: true
      body:
      - index: {}
      - date_1: "12-01-1981-01-12 15:00 +0000"
        date_2: "2000"
      - index: {}
      - date_1: "31-12-1999-12-31 23:59 +0300"
      - index: {}
      - date_1: "31-12-1999-12-31 23:59 -0300"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test From:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "from test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "color"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "count"
- match:
    columns.1.type: "long"
- match:
    columns.2.name: "count_d"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "data"
- match:
    columns.3.type: "long"
- match:
    columns.4.name: "data_d"
- match:
    columns.4.type: "double"
- match:
    columns.5.name: "time"
- match:
    columns.5.type: "long"
- length:
    values: 40
---
Test From Sort Limit:
- do:
    esql.query:
      body:
        query: "from test | sort count | limit 1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    columns.1.name: "count"
- match:
    columns.1.type: "long"
- match:
    values.0.1: 40
---
basic:
- do:
    esql.query:
      body:
        query: "from test | keep data | sort data | limit 2"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    columns.0.name: "data"
- match:
    columns.0.type: "long"
- match:
    values.0:
    - 1
    - 1
---
basic with documents_found:
- requires:
    test_runner_features:
    - "capabilities"
    - "contains"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "documents_found_and_values_loaded"
    reason: "checks for documents_found and values_loaded"
- do:
    esql.query:
      body:
        query: "from test | keep data | sort data | limit 2"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- gte:
    documents_found: 2
- gte:
    values_loaded: 2
- match:
    columns.0.name: "data"
- match:
    columns.0.type: "long"
- match:
    values.0:
    - 1
    - 1
---
FROM EVAL SORT LIMIT:
- do:
    esql.query:
      body:
        query: "from test | eval x = count + 7 | sort x | limit 1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    columns.0.name: "color"
- match:
    columns.1.name: "count"
- match:
    columns.2.name: "count_d"
- match:
    columns.3.name: "data"
- match:
    columns.4.name: "data_d"
- match:
    columns.5.name: "time"
- match:
    columns.6.name: "x"
- match:
    values.0.6: 47
- length:
    values: 1
---
FROM EVAL SORT LIMIT with documents_found:
- requires:
    test_runner_features:
    - "capabilities"
    - "contains"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "documents_found_and_values_loaded"
    reason: "checks for documents_found and values_loaded"
- do:
    esql.query:
      body:
        query: "from test | eval x = count + 7 | sort x | limit 1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    documents_found: 40
- gte:
    values_loaded: 45
- match:
    columns.0.name: "color"
- match:
    columns.1.name: "count"
- match:
    columns.2.name: "count_d"
- match:
    columns.3.name: "data"
- match:
    columns.4.name: "data_d"
- match:
    columns.5.name: "time"
- match:
    columns.6.name: "x"
- match:
    values.0.6: 47
- length:
    values: 1
---
Test Eval With Multiple Expressions:
- do:
    esql.query:
      body:
        query: "from test | sort time | eval x = data + 1, y = data_d + count, z =\
          \ x + y | keep data, x, y, z, time | limit 2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    columns.0.name: "data"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "x"
- match:
    columns.1.type: "long"
- match:
    columns.2.name: "y"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "z"
- match:
    columns.3.type: "double"
- match:
    columns.4.name: "time"
- match:
    columns.4.type: "long"
- length:
    values: 2
- length:
    values.0: 5
- match:
    values.0.0: 1
- match:
    values.0.1: 2
- match:
    values.0.2: 41.0
- match:
    values.0.3: 43.0
- length:
    values.1: 5
- match:
    values.1.0: 2
- match:
    values.1.1: 3
- match:
    values.1.2: 44.0
- match:
    values.1.3: 47.0
---
Test keep After TopN:
- do:
    esql.query:
      body:
        query: "from test | sort time | limit 2 | keep count"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 1
- match:
    columns.0.name: "count"
- match:
    columns.0.type: "long"
- match:
    values.0:
    - 40
    - 42
---
Test keep After TopN Desc:
- do:
    esql.query:
      body:
        query: "from test | sort time desc | limit 2 | keep count"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 1
- match:
    columns.0.name: "count"
- match:
    columns.0.type: "long"
- match:
    values.0:
    - 46
    - 44
---
Test TopN keep Eval:
- do:
    esql.query:
      body:
        query: "from test | sort time | limit 2 | keep count | eval x = count + 1"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 2
- match:
    columns.0.name: "count"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "x"
- match:
    columns.1.type: "long"
- length:
    values: 2
- match:
    values.0:
    - 40
    - 42
- match:
    values.1:
    - 41
    - 43
---
Test TopN keep Eval Project:
- do:
    esql.query:
      body:
        query: "from test | sort time | limit 2 | keep count | eval x = count + 1\
          \ | keep x"
        columnar: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 1
- match:
    columns.0.name: "x"
- match:
    columns.0.type: "long"
- length:
    values: 1
- match:
    values.0:
    - 41
    - 43
---
Test Multi Limit Project:
- do:
    esql.query:
      body:
        query: "from test | limit 10 | sort time | limit 1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 6
- length:
    values: 1
---
Test Input Params:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "row a = ? | eval b = ?, c = 1 + ?"
        params:
        - "foo"
        - 15
        - 10
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    columns: 3
- match:
    columns.0.name: "a"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "integer"
- match:
    columns.2.name: "c"
- match:
    columns.2.type: "integer"
- length:
    values: 1
- match:
    values.0:
    - "foo"
    - 15
    - 11
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "from test | where color == ? and count == ? and time == ? | keep data,\
          \ count, color"
        params:
        - "green"
        - 44
        - 1674835275193
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    columns: 3
- match:
    columns.0.name: "data"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "count"
- match:
    columns.1.type: "long"
- match:
    columns.2.name: "color"
- match:
    columns.2.type: "keyword"
- length:
    values: 1
- match:
    values.0:
    - 1
    - 44
    - "green"
---
Test Unnamed Input Params:
- do:
    esql.query:
      body:
        query: "from test | eval x = ?, y = ?, z = ?, t = ?, u = ?, v = ? | keep x,\
          \ y, z, t, u, v | limit 3"
        params:
        - "1"
        - 2.0
        - null
        - true
        - 123
        - 1674835275193
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 6
- match:
    columns.0.name: "x"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "y"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "z"
- match:
    columns.2.type: "null"
- match:
    columns.3.name: "t"
- match:
    columns.3.type: "boolean"
- match:
    columns.4.name: "u"
- match:
    columns.4.type: "integer"
- match:
    columns.5.name: "v"
- match:
    columns.5.type: "long"
- length:
    values: 3
- match:
    values.0:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.1:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.2:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
---
Test Unnamed Input Params Also For Limit And Sample:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "parameter_for_limit"
      - "parameter_for_sample"
    reason: "named or positional parameters"
- do:
    esql.query:
      body:
        query: "from test | sort time | sample ? | eval x = ?, y = ?, z = ?, t = ?,\
          \ u = ?, v = ? | keep x, y, z, t, u, v | limit ?"
        params:
        - 0.999999999999
        - "1"
        - 2.0
        - null
        - true
        - 123
        - 1674835275193
        - 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 6
- match:
    columns.0.name: "x"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "y"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "z"
- match:
    columns.2.type: "null"
- match:
    columns.3.name: "t"
- match:
    columns.3.type: "boolean"
- match:
    columns.4.name: "u"
- match:
    columns.4.type: "integer"
- match:
    columns.5.name: "v"
- match:
    columns.5.type: "long"
- length:
    values: 3
- match:
    values.0:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.1:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.2:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
---
Test Named Input Params:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "parameter_for_limit"
      - "parameter_for_sample"
    reason: "named or positional parameters"
- do:
    esql.query:
      body:
        query: "from test | sort time | sample ? | eval x = ?, y = ?, z = ?, t = ?,\
          \ u = ?, v = ? | keep x, y, z, t, u, v | limit ?"
        params:
        - s: 0.99999999999
        - n1: "1"
        - n2: 2.0
        - n3: null
        - n4: true
        - n5: 123
        - n6: 1674835275193
        - l: 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 6
- match:
    columns.0.name: "x"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "y"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "z"
- match:
    columns.2.type: "null"
- match:
    columns.3.name: "t"
- match:
    columns.3.type: "boolean"
- match:
    columns.4.name: "u"
- match:
    columns.4.type: "integer"
- match:
    columns.5.name: "v"
- match:
    columns.5.type: "long"
- length:
    values: 3
- match:
    values.0:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.1:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
- match:
    values.2:
    - "1"
    - 2.0
    - null
    - true
    - 123
    - 1674835275193
---
Test Interval in Input Params:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "cast_string_literal_to_temporal_amount"
    reason: "interval in parameters"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "row x = ?n1::datetime | eval y = x - ?n2::date_period, z = x + ?n3::time_duration"
        params:
        - n1: "2024-08-06"
        - n2: "3 days"
        - n3: "3 hours"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    columns: 3
- match:
    columns.0.name: "x"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "y"
- match:
    columns.1.type: "date"
- match:
    columns.2.name: "z"
- match:
    columns.2.type: "date"
- length:
    values: 1
- match:
    values.0:
    - "2024-08-06T00:00:00.000Z"
    - "2024-08-03T00:00:00.000Z"
    - "2024-08-06T03:00:00.000Z"
---
Test Named Input Params For Field Names:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "parameter_for_limit"
      - "parameter_for_sample"
    reason: "named or positional parameters for field names"
- do:
    esql.query:
      body:
        query: "from test | sort time | sample ?s | stats x = count(?f1), y = sum(?f2)\
          \ by ?f3 | sort ?f3 | keep ?f3, x, y  | limit ?l"
        params:
        - s: 0.99999999999
        - f1:
            identifier: "time"
        - f2:
            identifier: "count"
        - f3:
            identifier: "color"
        - l: 3
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    columns: 3
- match:
    columns.0.name: "color"
- match:
    columns.0.type: "keyword"
- match:
    columns.1.name: "x"
- match:
    columns.1.type: "long"
- match:
    columns.2.name: "y"
- match:
    columns.2.type: "long"
- length:
    values: 3
- match:
    values.0:
    - "blue"
    - 10
    - 420
- match:
    values.1:
    - "green"
    - 10
    - 440
- match:
    values.2:
    - "red"
    - 20
    - 860
---
Test wrong LIMIT parameter:
- skip:
    awaits_fix: "Error message changed"
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "normalized_limit_error_message"
    reason: "named or positional parameters for field names"
- do:
    catch: "/value of \\[limit \\?l\\] must be a non negative integer, found value\
      \ \\[\\?l\\] type \\[keyword\\]/"
    esql.query:
      body:
        query: "from test | limit ?l"
        params:
        - l: "foo"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
version is not allowed:
- requires:
    cluster_features:
    - "gte_v8.14.0"
    reason: "version allowed in 8.13.latest"
- do:
    catch: "/unknown field \\[version\\]/"
    esql.query:
      body:
        query: "from test"
        version: "cat"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test Internal Range:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
    esql.query:
      body:
        query: "from test_range | where date_1 > \"1990\" and date_1 < \"2000\" or\
          \ date_2 >= \"2000\" | sort date_1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    columns: 2
- match:
    columns.0.name: "date_1"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "date_2"
- match:
    columns.1.type: "date"
- length:
    values: 2
- match:
    values.0:
    - "1981-01-12T15:00:00.000Z"
    - "2000-01-01T00:00:00.000Z"
- match:
    values.1:
    - "1999-12-31T20:59:00.000Z"
    - null
