---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    test_runner_features:
    - "capabilities"
    - "contains"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "join_lookup_v12"
    reason: "uses LOOKUP JOIN"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            key:
              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:
    indices.create:
      index: "test-lookup-1"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            key:
              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:
    indices.create:
      index: "test-lookup-2"
      body:
        settings:
          index:
            mode: "lookup"
        mappings:
          properties:
            key:
              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: {}
      - key: 1
        color: "red"
      - index: {}
      - key: 2
        color: "blue"
    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-lookup-1"
      refresh: true
      body:
      - index: {}
      - key: 1
        color: "cyan"
      - index: {}
      - key: 2
        color: "yellow"
    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"
---
basic:
- skip:
    awaits_fix: "New SORT warning not in original test"
- do:
    esql.query:
      body:
        query: "FROM test | SORT key | LOOKUP JOIN test-lookup-1 ON key | LIMIT 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"
- match:
    columns.0.name: "key"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "color"
- match:
    columns.1.type: "keyword"
- match:
    values.0:
    - 1
    - "cyan"
- match:
    values.1:
    - 2
    - "yellow"
---
fails with non-lookup index:
- skip:
    awaits_fix: "Error message changed"
- requires:
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "update_lookup_join_error_messages"
    reason: "checks updated error messages"
- do:
    esql.query:
      body:
        query: "FROM test-lookup-1 | SORT key | LOOKUP JOIN test ON key | LIMIT 3"
    catch: "bad_request"
    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:
    error.type: "verification_exception"
- contains:
    error.reason: "Found 1 problem\nline 1:45: Lookup Join requires a single lookup\
      \ mode index; [test] resolves to [test] in [standard] mode"
---
pattern-multiple:
- do:
    esql.query:
      body:
        query: "FROM test-lookup-1 | LOOKUP JOIN test-lookup-* ON key"
    catch: "bad_request"
    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:
    error.type: "parsing_exception"
- contains:
    error.reason: "line 1:34: invalid index pattern [test-lookup-*], * is not allowed\
      \ in LOOKUP JOIN"
---
pattern-single:
- do:
    esql.query:
      body:
        query: "FROM test | SORT key | LOOKUP JOIN test-lookup-1* ON key | LIMIT 3"
    catch: "bad_request"
    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:
    error.type: "parsing_exception"
- contains:
    error.reason: "line 1:36: invalid index pattern [test-lookup-1*], * is not allowed\
      \ in LOOKUP JOIN"
