Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ExistsSubquery in PPL #769

Merged
merged 2 commits into from
Oct 12, 2024

Conversation

LantaoJin
Copy link
Member

Description

ExistsSubquery usage

Assumptions: a, b are fields of table outer, c, d are fields of table inner, e, f are fields of table inner2

  • source = outer | where exists [ source = inner | where a = c ]
  • source = outer | where not exists [ source = inner | where a = c ]
  • source = outer | where exists [ source = inner | where a = c and b = d ]
  • source = outer | where not exists [ source = inner | where a = c and b = d ]
  • source = outer | where exists [ source = inner1 | where a = c and exists [ source = inner2 | where c = e ] ] (nested)
  • source = outer | where exists [ source = inner1 | where a = c | where exists [ source = inner2 | where c = e ] ] (nested)
  • source = outer | where exists [ source = inner | where c > 10 ] (uncorrelated exists)
  • source = outer | where not exists [ source = inner | where c > 10 ] (uncorrelated exists)
  • source = outer | where exists [ source = inner ] | eval l = "nonEmpty" | fields l (special uncorrelated exists)

SQL Migration examples with Exists-Subquery PPL:

tpch q4 (exists subquery with aggregation)

select
  o_orderpriority,
  count(*) as order_count
from
  orders
where
  o_orderdate >= date '1993-07-01'
  and o_orderdate < date '1993-07-01' + interval '3' month
  and exists (
    select
      l_orderkey
    from
      lineitem
    where l_orderkey = o_orderkey
      and l_commitdate < l_receiptdate
  )
group by
  o_orderpriority
order by
  o_orderpriority

Rewritten by PPL ExistsSubquery query:

source = orders
| where o_orderdate >= "1993-07-01" and o_orderdate < "1993-10-01"
    and exists [
      source = lineitem
      | where l_orderkey = o_orderkey and l_commitdate < l_receiptdate
    ]
| stats count(1) as order_count by o_orderpriority
| sort o_orderpriority
| fields o_orderpriority, order_count

Issues Resolved

Resolve #711 as a sub-task of #661

Check List

  • Updated documentation (ppl-spark-integration/README.md)
  • Implemented unit tests
  • Implemented tests for combination with other commands
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@LantaoJin LantaoJin changed the title Support Exists Subquery in PPL Support ExistsSubquery in PPL Oct 11, 2024
@LantaoJin LantaoJin added Lang:PPL Pipe Processing Language support 0.6 labels Oct 11, 2024
@LantaoJin LantaoJin marked this pull request as ready for review October 11, 2024 13:58
@YANG-DB
Copy link
Member

YANG-DB commented Oct 11, 2024

@LantaoJin plz resolve minor conflict
thanks

@LantaoJin LantaoJin merged commit d83f61d into opensearch-project:main Oct 12, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6 Lang:PPL Pipe Processing Language support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support ExistsSubQuery PPL
2 participants