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 parsing SQL Server INSERT INTO sql #29152 #29329

Merged
merged 5 commits into from
Dec 12, 2023
Merged

Support parsing SQL Server INSERT INTO sql #29152 #29329

merged 5 commits into from
Dec 12, 2023

Conversation

TherChenYang
Copy link
Collaborator

@TherChenYang TherChenYang commented Dec 8, 2023

Fixes #29152.

Changes proposed in this pull request:

  • Support parsing SQL Server INSERT INTO sql
  1. INSERT INTO dbo.T1 VALUES (1, N'Natalia')
  2. SELECT x.$(ColumnName) FROM Person.Person x WHERE x.BusinessEntityID < 5
  3. INSERT INTO AdventureWorks2022.dbo.VariableTest(Col1) VALUES('$(tablename)')
  • Fix the error parser in oracle Nchar

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes

@@ -151,7 +152,7 @@ sequenceName
;

tableName
: (owner DOT_)? name
: ((databaseName DOT_)? owner DOT_)? name
Copy link
Member

Choose a reason for hiding this comment

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

Hi according to the definition of SQL Server insert syntax, databaseName is a selection pattern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hello, could you please tell me how to modify here, thank you

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

We can use the selection mode of antlr.

;

scriptVariableName
: DOLLAR_ LP_ name RP_
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this grammar rule definition in columnName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In SqlServer, $(ColumnName) looks more like a whole, and the '($' and '()' need to be preserved. After parsing, when using it, you need to determine if '$()' is a script variable. Then, when executing SQL similar to 'sqlcmd -v ColumnName="FirstName" -i c:\testscript.sql', replace the corresponding script variable.

Copy link
Member

Choose a reason for hiding this comment

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

@strongduanmu
Copy link
Member

Hi @TherChenYang, can you refer the original issue? I will assign it to you.

@TherChenYang
Copy link
Collaborator Author

Hi @TherChenYang, can you refer the original issue? I will assign it to you.

Thank you. The corresponding issue is this one #29152

@TherChenYang
Copy link
Collaborator Author

@zihaoAK47 Hello, I have refactored the code according to your request. Please review it again. Thank you very mach

Copy link
Member

@zihaoAK47 zihaoAK47 left a comment

Choose a reason for hiding this comment

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

Great PR, thank you

@zihaoAK47 zihaoAK47 merged commit bedd9ca into apache:master Dec 12, 2023
133 checks passed
@TherChenYang TherChenYang deleted the 29152-local branch December 12, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support parsing SQL Server INSERT INTO sql
3 participants