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

Adds DML (INSERT, DELETE, UPDATE, UPSERT, REPLACE) #1666

Merged
merged 9 commits into from
Dec 9, 2024

Conversation

johnedquinn
Copy link
Member

@johnedquinn johnedquinn commented Nov 27, 2024

Relevant Issues & Links

Description

  • Adds DML (INSERT, DELETE, UPDATE, UPSERT, REPLACE)
  • Fixed the modelling, naming, and parsing of many nodes.
  • Adds DQL, DML, and Common G4 files to make it easier to see what's going on.
    • The only reason you would want to look at DQL is because I fixed ExprRow and the table value constructor (VALUES ..., ...). If you want, you can manually invoke diff to see what's different between DQL and PartiQLParser, but it's really just a removal of the DML.
    • I removed the legacy DML stuff.
    • I've left some TODOs on the DML for unanswered questions.
  • Named the nodes as close as I reasonably could to the SQL:1999 EBNF.
  • I did NOT bring over the FROM INSERT, FROM SET, FROM REMOVE, and RETURNING AST nodes since they are not SQL Spec and are not used by active customers. Please see the issues that reference this PR further below.

License Information

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

partiql-ast/src/main/java/org/partiql/ast/Delete.java Outdated Show resolved Hide resolved
partiql-ast/src/main/java/org/partiql/ast/Delete.java Outdated Show resolved Hide resolved
partiql-ast/src/main/java/org/partiql/ast/Delete.java Outdated Show resolved Hide resolved
* TODO
*/
@Nullable
public final List<Identifier> columns;
Copy link
Member

Choose a reason for hiding this comment

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

Syntactically, could a FromDefault also include a list of columns? I couldn't find if there was this restriction from the RFCs. The EBNF seems to indicate there could be a list of columns with a DEFAULT VALUES specified:

<upsert statement> ::= UPSERT INTO <table name> [ AS <alias> ] 
    [  ( <attr name> [, <attr name> ]... ) ]
        <values>
...
<values> ::= DEFAULT VALUES | <values clause>
      | <bag value> | <sub-select>

Copy link
Member Author

Choose a reason for hiding this comment

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

See partiql/partiql-lang#95. I meant to cut an issue earlier, but the modelling in the RFCs is very likely wrong (and it's also unspecified). That being said, this PR adds the correct modelling while also allowing for the addition of the insert column list in the future if it is eventually specified. And, the ANTLR grammar can be updated accordingly. But for now, looking at the SQL:1999 EBNF in contrast with the RFC's EBNF, it is immediately apparent that one is wrong.

partiql-ast/src/main/java/org/partiql/ast/Update.java Outdated Show resolved Hide resolved
partiql-parser/src/main/antlr/Common.g4 Outdated Show resolved Hide resolved
partiql-parser/src/main/antlr/DML.g4 Outdated Show resolved Hide resolved
Copy link
Member

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

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

Thanks for all the detailed work adding DML to the new AST -- think we're almost there.

*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public final class Insert extends Statement {
Copy link
Member

Choose a reason for hiding this comment

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

I guess the idea is that these DML statements do have shared functionality in being DML statements. Yingtao had done a similar thing for DDL statements:

It can make it a bit easier to case on the statements to apply the same logic to DQL, DML, DDL. Whatever we choose, we should try to be consistent (i.e. have DDL and DML have separate abstract classes or have the statements directly extend Statement).

*/
// TODO: Should this be a list of identifiers? Or paths? Expressions?
@NotNull
public final List<Identifier> indexes;
Copy link
Member

Choose a reason for hiding this comment

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

So does <attr name> in the RFC (https://github.com/partiql/partiql-lang/blob/main/RFCs/0011-partiql-insert.md?plain=1#L123) refer to Identifier or IdentifierChain AstNode? In the other comment (#1666 (comment)), <index attr name> is an <attr name> which we then define as an IdentifierChain.

I'm thinking if we're inclined at all to classify it as an IdentifierChain in the AST, it is more backwards compatible API-wise since an IdentifierChain without a next is just an Identifier.

@alancai98
Copy link
Member

From the most recent changes (may also apply to earlier changes), there are some conformance tests failing -- https://github.com/partiql/partiql-lang-kotlin/actions/runs/12205681348.

@partiql partiql deleted a comment from alancai98 Dec 7, 2024
@partiql partiql deleted a comment from alancai98 Dec 7, 2024
Adds SqlDialect for the DML statements

Fixes the getChildren for multiple DML AST nodes

Updates Javadocs to reference unimplemented, future features
Adds the conversion for ExprValues to a plan node
@johnedquinn
Copy link
Member Author

Alright! I fixed the table value construction issue with the conformance tests, and for the other 4 remaining failing tests, I believe those tests are actually wrong. See partiql/partiql-tests#130

Copy link
Member

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

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

Pre-approving following rebase from v1. Thanks for the deep dive into adding DML along with all the partiql-lang issues!

Regarding the conformance test failures, seems very likely that's an error in the conformance tests, but we should look more into it. Since it doesn't affect the public APIs, we could figure things out in a later work stream.

/**
* TODO
*/
// TODO: Change this to a literal, not an ExprLit
Copy link
Member

Choose a reason for hiding this comment

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

The updated literal modeling (#1650) has been merged in, so we can address this TODO. Think we'll have to otherwise build will fail.

@johnedquinn johnedquinn merged commit 9b6d7cc into partiql:v1 Dec 9, 2024
7 checks passed
@johnedquinn johnedquinn deleted the v1-dml branch December 9, 2024 17:59
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.

2 participants