-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: support any number/order of merge operations #1938
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
feat: support any number/order of merge operations #1938
Conversation
5be8e87
to
6570d44
Compare
Greetings! First of all, thank you for your good work and the contribution. So what could be the way forward:
So just maybe, we should keep the Standard Merge and then derive an @wumpz @tomershay @AnEmortalKid @jxnu-liguobin @zaza @gitmotte @tvar Your have contributed the most to the project, so please let us know your opinion on this. |
Technically this PR is exceptionally well crafted! No concerns from this side. It's really all about the Snowflake specific syntax and how far we want to go under a RDBMS agnostic approach. |
Thanks so much for the fast feedback @manticore-projects - all very fair, and I'm happy to make whatever changes we feel are best overall 👍 |
I want to add one thought: I am using Washing up the syntax may allow for statements appearing valid when not valid on the big four RDBMS. Lets wait a week or so for opinions to hit and then we will make a joint decision. Thank you for understanding. |
I have created a Github Poll: #1939 |
I don't see it quite so strictly. A validator (FeatureSetValidation/DatabaseType and FeatureSetValidation/Version) can be built/extended to validate which syntax is correct for which RDMS.
I do not use Oracle, I have defined several validators for several widely used RDBMS. Besides the DatabaseType Validation classes ORACLE, MYSQL, SQLSERVER, MARIADB, POSTGRESQL, H2, there is a SQLVersion class that is supposed to define the ANSI SQL standard syntax. However, not all databases are fully ANSI-compatible for all statements.
Deprecation should only take place if the methods are completely outdated or incorrect. I agree that we should keep them.
The class-structure will never fulfill all the requirements of all RDBMSs, so successful parsing will never guarantee a valid statement for an RDBMS. We have this problem in many cases in this library. |
My 2 cents:
I didn't get a chance to look at the specific technical details of this change, so I'm mainly sharing thoughts based on the discussion above and initial understanding of the suggested change. |
I think adding one is acceptable if we have standalone support for that database (oracle, mysql,h2,pg). When there is no standalone support (a new database category), it may be more in line with the standard to not accept big changes. I have a similar problem, we are heavily using Doris which uses MySQL driver but still has some special operations and since Doris is not a legacy database and not currently popular, there is no such database category in jsqlparser so I didn't create PR for Doris. |
Thank you all for your feedback. I read it s supportive as long as the support for the Standard Merge statement stays intact. @davidjgoss Can you please amend your PR in order to make it as compatible as possible to the Standard Merge. E. g. don't deprecate the existing methods and assume that standard count of merge operations = 1 ( 1or zero INSERT and 1 or zero DELETE) -- unless more operations are either APPENDED or SET with an index. Then I would promptly merge the PR. |
e2017b7
to
49115da
Compare
@manticore-projects I've pushed a commit that I think addresses this. The original three standard fields in |
Great! Thank you for your contribution and support, much appreciated! |
Congrats, your new Snowflake syntax are online: https://manticore-projects.com/JSQLParser/syntax_snapshot.html#merge |
This PR changes the parser to account for any number of
WHEN MATCHED
and/orWHEN NOT MATCHED
clauses in aMERGE
statement. This is most directly applicable to Snowflake. From their docs:To achieve this, the parser now collects a list of
MergeOperation
s which can be aWHEN MATCHED THEN DELETE
(newly added also),WHEN MATCHED THEN UPDATE
orWHEN NOT MATCHED THEN INSERT
.The pre-existing getters that presume 0 or 1 ofMergeUpdate
andMergeInsert
are preserved, but deprecated and suggest using the newly addedMergeOperationVisitor
instead, which is itself used for the deparser and validation logic internally.