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

[v1] Migrate parser to new AST #1626

Merged
merged 3 commits into from
Oct 28, 2024
Merged

[v1] Migrate parser to new AST #1626

merged 3 commits into from
Oct 28, 2024

Conversation

alancai98
Copy link
Member

@alancai98 alancai98 commented Oct 22, 2024

Relevant Issues

Description

  • Migrates the partiql-parser to use the new AST

Other Information

  • Updated Unreleased Section in CHANGELOG: [NO]

    • On v1 branch
  • Any backward-incompatible changes? [NO]

    • Some changes but on v1 and hasn't been release yet
  • Any new external dependencies? [NO]

  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES]

License Information

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

@alancai98 alancai98 self-assigned this Oct 22, 2024
Copy link

github-actions bot commented Oct 22, 2024

CROSS-ENGINE-REPORT ❌

BASE (LEGACY-V0.14.8) TARGET (EVAL-5E66224) +/-
% Passing 89.67% 94.39% 4.72% ✅
Passing 5287 5565 278 ✅
Failing 609 50 -559 ✅
Ignored 0 281 281 🔶
Total Tests 5896 5896 0 ✅

Testing Details

  • Base Commit: v0.14.8
  • Base Engine: LEGACY
  • Target Commit: 5e66224
  • Target Engine: EVAL

Result Details

  • ❌ REGRESSION DETECTED. See Now Failing/Ignored Tests. ❌
  • Passing in both: 2643
  • Failing in both: 17
  • Ignored in both: 0
  • PASSING in BASE but now FAILING in TARGET: 3
  • PASSING in BASE but now IGNORED in TARGET: 108
  • FAILING in BASE but now PASSING in TARGET: 180
  • IGNORED in BASE but now PASSING in TARGET: 0

Now FAILING Tests ❌

The following 3 test(s) were previously PASSING in BASE but are now FAILING in TARGET:

Click here to see
  1. undefinedUnqualifiedVariableWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE
  2. undefinedUnqualifiedVariableIsNullExprWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE
  3. undefinedUnqualifiedVariableIsMissingExprWithUndefinedVariableBehaviorMissing, compileOption: PERMISSIVE

Now IGNORED Tests ❌

The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact.

Now Passing Tests

180 test(s) were previously failing in BASE (LEGACY-V0.14.8) but now pass in TARGET (EVAL-5E66224). 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.

CROSS-COMMIT-REPORT ✅

BASE (EVAL-246B63C) TARGET (EVAL-5E66224) +/-
% Passing 94.39% 94.39% 0.00% ✅
Passing 5565 5565 0 ✅
Failing 50 50 0 ✅
Ignored 281 281 0 ✅
Total Tests 5896 5896 0 ✅

Testing Details

  • Base Commit: 246b63c
  • Base Engine: EVAL
  • Target Commit: 5e66224
  • Target Engine: EVAL

Result Details

  • Passing in both: 5565
  • Failing in both: 50
  • Ignored in both: 281
  • PASSING in BASE but now FAILING in TARGET: 0
  • PASSING in BASE but now IGNORED in TARGET: 0
  • FAILING in BASE but now PASSING in TARGET: 0
  • IGNORED in BASE but now PASSING in TARGET: 0

@alancai98 alancai98 changed the base branch from v1 to v1-migrate-ast-enum-methods October 23, 2024 21:52
@alancai98 alancai98 changed the title [v1][WIP] Migrate parser to new AST [v1] Migrate parser to new AST Oct 23, 2024
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.int32Value
import org.partiql.value.stringValue
import kotlin.test.assertEquals

class PartiQLParserBagOpTests {

private val parser = PartiQLParserDefault()
Copy link
Member Author

Choose a reason for hiding this comment

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

All of the partiql-parser tests were modified to use the V1PartiQLParserDefault. Existing tests other than the DDL tests (since DDL will be added in a later v1 release candidate), still passes with the new parser.

@@ -358,7 +358,7 @@ excludeExprSteps
;

fromClause
: FROM tableReference;
: FROM ( tableReference ( COMMA tableReference)* );
Copy link
Member Author

Choose a reason for hiding this comment

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

Made some ANTLR grammar changes to account for the new modeling of FROM clauses to be better aligned with the SQL1999 BNF definition. See #1579 (comment) for some further context.

Comment on lines +20 to +23
public final FromTableRef lhs;

@NotNull
public final From rhs;
public final FromTableRef rhs;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an error in the original PR adding the hand-written ASTs. The lhs and rhs should have been FromTableRefs.

@alancai98 alancai98 marked this pull request as ready for review October 23, 2024 22:08
@alancai98 alancai98 force-pushed the v1-migrate-ast-parser branch 2 times, most recently from 8eae47f to 43584f9 Compare October 24, 2024 00:47
@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v1-migrate-ast-enum-methods@bb30367). Learn more about missing BASE report.

Additional details and impacted files
@@                      Coverage Diff                       @@
##             v1-migrate-ast-enum-methods    #1626   +/-   ##
==============================================================
  Coverage                               ?   80.03%           
  Complexity                             ?       47           
==============================================================
  Files                                  ?       19           
  Lines                                  ?      506           
  Branches                               ?       23           
==============================================================
  Hits                                   ?      405           
  Misses                                 ?       88           
  Partials                               ?       13           
Flag Coverage Δ
EXAMPLES 80.03% <ø> (?)

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.

override fun visitTableCrossJoin(ctx: PartiQLParser.TableCrossJoinContext): FromTableRef = translate(ctx) {
val lhs = visitAs<FromTableRef>(ctx.lhs)
val rhs = visitAs<FromTableRef>(ctx.rhs)
// TODO support other CROSS JOIN variants (e.g. LEFT CROSS JOIN)
Copy link
Member Author

Choose a reason for hiding this comment

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

The previous ANTLR parser visitor would parse l LEFT CROSS JOIN r to the AST equivalent of l LEFT JOIN r ON TRUE. This was mentioned in the PartiQL spec in section 5.4 (https://partiql.org/dql/joins.html#left-join), but I couldn't find it mentioned in the SQL1999 spec. It's not yet clear to me what other JOIN types (e.g. RIGHT, LEFT OUTER, INNER, FULL, etc.) should support this behavior so I've left it out of the new ANTLR parser visitor for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

From offline discussion, will change the ANTLR parsing rules slightly:

  1. Remove the optional joinType before the CROSS JOIN since that's what is defined in SQL99 spec
  2. Add an explicit rule for LEFT CROSS JOIN since that's what is defined in the PartiQL spec
  3. Add TODO linking Vladimir's issue for the other cross join variant investigation -- Explore SQL-consistent syntax for joins #1013

Base automatically changed from v1-migrate-ast-enum-methods to v1 October 25, 2024 16:45
@alancai98
Copy link
Member Author

Marking as a draft since I need to rebase and incorporate the latest error reporting changes (#1615).

@alancai98 alancai98 marked this pull request as draft October 25, 2024 16:46
@alancai98 alancai98 changed the base branch from v1 to v1-migrate-ast October 25, 2024 22:16
@alancai98 alancai98 marked this pull request as ready for review October 25, 2024 22:22
Base automatically changed from v1-migrate-ast to v1 October 28, 2024 17:52
Copy link
Member

@RCHowell RCHowell left a comment

Choose a reason for hiding this comment

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

Small comments, otherwise let's get it merged.

}
}

companion object {
Copy link
Member

Choose a reason for hiding this comment

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

nit no reason for a companion object here unless maybe static?

Copy link
Member Author

Choose a reason for hiding this comment

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

These were just copied from the existing PartiQLParserDefault for context. Since the static methods within the companion object are all private, I will just move them out of the companion object.

@OptIn(PartiQLValueExperimental::class)
private class Visitor(
private val tokens: CommonTokenStream,
private val locations: SourceLocations.Mutable,
Copy link
Member

Choose a reason for hiding this comment

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

not for this PR, but I would like to put source locations class under the microscope..

"trail" -> GraphRestrictor.TRAIL()
"acyclic" -> GraphRestrictor.ACYCLIC()
"simple" -> GraphRestrictor.SIMPLE()
else -> throw error(ctx, "Unrecognized pattern restrictor")
Copy link
Member

Choose a reason for hiding this comment

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

Curious if the message ever propagates beyond here

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested locally with a misspelt graph restrictor (i.e. TRAILL rather than TRAIL). The message will be part of a syntax PError with a message captured in the "CAUSE" field -- "org.partiql.parser.PartiQLParserException: Unrecognized pattern restrictor".

ErrorException{error=PError{code=1, severity=ERROR, kind=SYNTAX, location=null, properties={CAUSE=org.partiql.parser.PartiQLParserException: Unrecognized pattern restrictor}}}

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't been following the latest PError developments. Is this the expected behavior?

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's ok, we explicitly state that properties are not semvered

"trail" -> GraphRestrictor.TRAIL()
"acyclic" -> GraphRestrictor.ACYCLIC()
"simple" -> GraphRestrictor.SIMPLE()
else -> throw error(ctx, "Unrecognized pattern restrictor")
Copy link
Member

Choose a reason for hiding this comment

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

Yes it's ok, we explicitly state that properties are not semvered

@alancai98 alancai98 merged commit f0569bd into v1 Oct 28, 2024
14 checks passed
@alancai98 alancai98 deleted the v1-migrate-ast-parser branch October 28, 2024 23:14
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