---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          number_of_shards: 1
        mappings:
          properties:
            data:
              type: "long"
            data_d:
              type: "double"
            count:
              type: "long"
            count_d:
              type: "double"
            time:
              type: "long"
            color:
              type: "keyword"
            text:
              type: "text"
    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:
    cluster.health:
      wait_for_no_initializing_shards: true
      wait_for_events: "languid"
    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"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275188
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275189
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275190
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275191
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275192
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275193
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275194
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275195
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275196
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275197
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275198
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275199
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275200
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275201
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275202
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275203
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275204
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275205
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275206
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275207
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275208
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275209
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275210
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275211
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275212
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275213
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275214
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275215
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275216
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275217
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275218
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275219
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275220
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275221
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275222
        color: "red"
        text: "rr red"
      - index: {}
      - data: 1
        count: 40
        data_d: 1
        count_d: 40
        time: 1674835275223
        color: "red"
        text: "rr red"
      - index: {}
      - data: 2
        count: 42
        data_d: 2
        count_d: 42
        time: 1674835275224
        color: "blue"
        text: "bb blue"
      - index: {}
      - data: 1
        count: 44
        data_d: 1
        count_d: 44
        time: 1674835275225
        color: "green"
        text: "gg green"
      - index: {}
      - data: 2
        count: 46
        data_d: 2
        count_d: 46
        time: 1674835275226
        color: "red"
        text: "rr 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"
---
avg 8.14 or after:
- requires:
    cluster_features:
    - "gte_v8.14.0"
    reason: "avg changed starting 8.14"
- do:
    esql.query:
      body:
        query: "FROM test | STATS AVG(data) | LIMIT 1"
        columnar: true
        profile: 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: "AVG(data)"
- match:
    columns.0.type: "double"
- match:
    values.0.0: 1.5
- match:
    profile.drivers.0.operators.0.operator: "/ExchangeSourceOperator|LuceneSourceOperator.+/"
- gte:
    profile.drivers.0.took_nanos: 0
- gte:
    profile.drivers.0.cpu_nanos: 0
- gte:
    profile.drivers.1.took_nanos: 0
- gte:
    profile.drivers.1.cpu_nanos: 0
---
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 | LIMIT 1"
        profile: 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:
    profile.drivers: 3
- match:
    profile.drivers.0.operators.0.operator: "/ExchangeSourceOperator|LuceneSourceOperator.+/"
- gte:
    profile.drivers.0.documents_found: 0
- gte:
    profile.drivers.0.values_loaded: 0
- gte:
    profile.drivers.1.documents_found: 0
- gte:
    profile.drivers.1.values_loaded: 0
- gte:
    profile.drivers.2.documents_found: 0
- gte:
    profile.drivers.2.values_loaded: 0
