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

Partiql eval wildcard #1374

Merged
merged 9 commits into from
Mar 7, 2024
Merged

Partiql eval wildcard #1374

merged 9 commits into from
Mar 7, 2024

Conversation

yliuuuu
Copy link
Contributor

@yliuuuu yliuuuu commented Feb 19, 2024

Relevant Issues

  • [Closes/Related To] Issue #XXX

Description

  • To be reviewed after PR#1365 is merged.
  • Adding support for Path Wildcard.
  • This PR does so by rewriting the unresolved plan.
Path Expressions with Wildcards PartiQL also provides multi-step path expressions, called path collection expressions.Their semantics is a generalization of the semantics of a path expression with a single [∗] or .∗. Consider the path collection expression:
ew1p1 . . . wnpn
where e is any expression; n > 0; each wildcard step wi is either [∗] or .∗; each series of plain path steps pi
is a sequence of zero or more tuple path navigations or array navigations (potentially mixed).
Then the path collection expression is equivalent to the SFW query
SELECT VALUE vn.pn
FROM
u1 e AS v1,
u2 @v1.p1 AS v2,
. . .,
un @vn−1.pn−1 AS vn,
where each vi is a fresh variable and each ui is UNPIVOT if wi is a .∗ and it is nothing if wi
is a [∗]. Intuitively vi corresponds to the i-th star.

Other Information

  • Updated Unreleased Section in CHANGELOG: [YES/NO]

    • < If NO, why? >
  • Any backward-incompatible changes? [YES/NO]

    • < If YES, why? >
    • < For this purpose, we define backward-incompatible changes as changes that—when consumed—can potentially result in
      errors for users that are using our public APIs or the entities that have public visibility in our code-base. >
  • Any new external dependencies? [YES/NO]

    • < If YES, which ones and why? >
    • < In addition, please also mention any other alternatives you've considered and the reason they've been discarded >
  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES/NO]

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (partiql-eval@f2369ba). Click here to learn what that means.

Additional details and impacted files
@@               Coverage Diff               @@
##             partiql-eval    #1374   +/-   ##
===============================================
  Coverage                ?   50.32%           
  Complexity              ?     1045           
===============================================
  Files                   ?      165           
  Lines                   ?    13129           
  Branches                ?     2452           
===============================================
  Hits                    ?     6607           
  Misses                  ?     5862           
  Partials                ?      660           
Flag Coverage Δ
CLI 13.77% <ø> (?)
EXAMPLES 80.28% <ø> (?)
LANG 54.71% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Feb 19, 2024

Conformance comparison report-Cross Engine

Base (eval) legacy +/-
% Passing 78.64% 92.51% 13.87%
✅ Passing 4575 5382 807
❌ Failing 1243 436 -807
🔶 Ignored 0 0 0
Total Tests 5818 5818 0
Number passing in both: 4406

Number failing in both: 267

Number passing in eval engine but fail in legacy engine: 169

Number failing in eval engine but pass in legacy engine: 976
⁉️ CONFORMANCE REPORT REGRESSION DETECTED ⁉️
The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.
976 test(s) were failing in eval but now pass in legacy. Before merging, confirm they are intended to pass.
The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.

Conformance comparison report-Cross Commit-EVAL

Base (f2369ba) 3d2aa2e +/-
% Passing 77.84% 78.64% 0.79%
✅ Passing 4529 4575 46
❌ Failing 1289 1243 -46
🔶 Ignored 0 0 0
Total Tests 5818 5818 0
Number passing in both: 4529

Number failing in both: 1243

Number passing in Base (f2369ba) but now fail: 0

Number failing in Base (f2369ba) but now pass: 46
46 test(s) were previously failing but now pass. Before merging, confirm they are intended to pass
The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.

Conformance comparison report-Cross Commit-LEGACY

Base (f2369ba) 3d2aa2e +/-
% Passing 92.51% 92.51% 0.00%
✅ Passing 5382 5382 0
❌ Failing 436 436 0
🔶 Ignored 0 0 0
Total Tests 5818 5818 0
Number passing in both: 5382

Number failing in both: 436

Number passing in Base (f2369ba) but now fail: 0

Number failing in Base (f2369ba) but now pass: 0

@yliuuuu yliuuuu force-pushed the partiql-eval-wildcard branch from 397ed08 to 467a954 Compare February 20, 2024 01:37
@yliuuuu yliuuuu marked this pull request as ready for review February 20, 2024 03:30
@@ -29,6 +29,7 @@ internal data class TypeEnv(
internal fun getScope(depth: Int): TypeEnv {
return when (depth) {
0 -> this
// TODO: Consider resolve the variable to the correct index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We calculate the correct index in Compiler. There are a couple reasons that we can discuss.

@yliuuuu yliuuuu force-pushed the partiql-eval-wildcard branch from 30fe790 to a9aca3a Compare February 26, 2024 23:20
@yliuuuu yliuuuu requested a review from johnedquinn February 27, 2024 00:03
@Test
fun wildCard2() {
val query = """
{'a':1, 'b':2}.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a query for <someTuple>.*.a?

is Expr.Path.Step.Unpivot -> {
// Unpivot produces two binding, in this context we want the value,
// which always going to be the second binding
val op = rexOpVarLocal(1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter at all what values you put in here? Same goes for the Wildcard below.

If so, does this work when you have more than two path expressions with wildcards/unpivots? Can you add a test to PartiQLEngineDefaultTest for an example like: <someList>[*].books[*].author[*].name[*].middle_initial and maybe something similar for unpivots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Specifically:

SELECT VALUE vn.pn
                          |_ this came from pathNavi, which is rexOpVarLocal(1,$last).pn
                          |_ we change the root node to rexOpVarLocal(0, $last_in_from_schema).pn
FROM
u1 e AS v1,
u2 @v1.p1 AS v2,
       |_ this needs to be rexOpVarLocal(1,$last). 
. . .,
un @vn−1.pn−1 AS vn,
      |_ this needs to be rexOpVarLocal(1,$last)

Those tests you asking are included in the conformance test:

  {
    name:"pathDoubleWildCard",
    statement:"stores[*].books[*].title",
    assert:{
      evalMode:[EvalModeCoerce, EvalModeError],
      result:EvaluationSuccess,
      output:$bag::[
        "A",
        "B",
        "C",
        "D",
        "A",
        "E",
        "F"
      ]
    }
  },
  {
    name:"pathDoubleUnpivotWildCard",
    statement:"friends.*.likes.*.type",
    assert:{
      evalMode:[EvalModeCoerce, EvalModeError],
      result:EvaluationSuccess,
      output:$bag::[
        "dog",
        "human",
        "dog",
        "cat"
      ]
    }
  },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check the conformance report details here.

I think the conformance tests should be sufficient. But I can also port the tests to PartiQLEngineDefaultTest

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, does this work when you have more than two path expressions with wildcards/unpivots?

This doesn't work when you have more than two path expressions. See this commit: e8e31d9.

The example above doesn't compile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to do with the 1, 1 and 1, 0 you've used for rexOpVarLocal for unpivots and wildcards. Those only work for the test cases you've written. Since JOINs really concatenate the LHS schema with the RHS schema, you can't always assume that the item you'll be referencing will always be at some specific index. It needs to be calculated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean. You are right.

@yliuuuu yliuuuu requested a review from johnedquinn February 28, 2024 01:51
Copy link
Member

@johnedquinn johnedquinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comments.

@yliuuuu yliuuuu force-pushed the partiql-eval-wildcard branch from a9aca3a to 490c708 Compare February 29, 2024 00:40
Copy link
Member

@johnedquinn johnedquinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yliuuuu yliuuuu merged commit 5fb9a1c into partiql-eval Mar 7, 2024
10 checks passed
@yliuuuu yliuuuu deleted the partiql-eval-wildcard branch March 7, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants