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

Add BULK INSERT to tsql #3861

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sql/tsql/TSqlLexer.g4
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 all newly added tokens should be also added to the keyword list to allow they be identifiers if needed:

  • BATCHSIZE
  • CHECK_CONSTRAINTS
  • CODEPAGE
  • DATAFILETYPE
  • ERRORFILE
  • ERRORFILE_DATA_SOURCE
  • FIELDTERMINATOR
  • FIELDQUOTE
  • FIRE_TRIGGERS
  • FIRSTROW
  • FORMATFILE
  • FORMATFILE_DATA_SOURCE
  • KEEPNULLS
  • KILOBYTES_PER_BATCH
  • LASTROW
  • MAXERRORS
  • ROWS_PER_BATCH
  • ROWTERMINATOR

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ BACKUP: 'BACKUP';
BACKUP_CLONEDB: 'BACKUP_CLONEDB';
BACKUP_PRIORITY: 'BACKUP_PRIORITY';
BASE64: 'BASE64';
BATCHSIZE: 'BATCHSIZE';
BEFORE: 'BEFORE';
BEGIN: 'BEGIN';
BEGIN_DIALOG: 'BEGIN_DIALOG';
Expand Down Expand Up @@ -172,6 +173,7 @@ CHECKPOINT: 'CHECKPOINT';
CHECKSUM: 'CHECKSUM';
CHECKSUM_AGG: 'CHECKSUM_AGG';
CHECKTABLE: 'CHECKTABLE';
CHECK_CONSTRAINTS: 'CHECK_CONSTRAINTS';
CHECK_EXPIRATION: 'CHECK_EXPIRATION';
CHECK_POLICY: 'CHECK_POLICY';
CLASSIFIER_FUNCTION: 'CLASSIFIER_FUNCTION';
Expand All @@ -193,6 +195,7 @@ COLUMN_ENCRYPTION_KEY: 'COLUMN_ENCRYPTION_KEY';
COLUMN_MASTER_KEY: 'COLUMN_MASTER_KEY';
COL_LENGTH: 'COL_LENGTH';
COL_NAME: 'COL_NAME';
CODEPAGE: 'CODEPAGE';
COMMIT: 'COMMIT';
COMMITTED: 'COMMITTED';
COMPATIBILITY_LEVEL: 'COMPATIBILITY_LEVEL';
Expand Down Expand Up @@ -252,6 +255,7 @@ DATABASE: 'DATABASE';
DATABASEPROPERTYEX: 'DATABASEPROPERTYEX';
DATABASE_MIRRORING: 'DATABASE_MIRRORING';
DATABASE_PRINCIPAL_ID: 'DATABASE_PRINCIPAL_ID';
DATAFILETYPE: 'DATAFILETYPE';
DATALENGTH: 'DATALENGTH';
DATASPACE: 'DATASPACE';
DATA_COMPRESSION: 'DATA_COMPRESSION';
Expand Down Expand Up @@ -333,6 +337,8 @@ ENDPOINT: 'ENDPOINT';
ENDPOINT_URL: 'ENDPOINT_URL';
ERRLVL: 'ERRLVL';
ERROR: 'ERROR';
ERRORFILE: 'ERRORFILE';
ERRORFILE_DATA_SOURCE: 'ERRORFILE_DATA_SOURCE';
ERROR_BROKER_CONVERSATIONS: 'ERROR_BROKER_CONVERSATIONS';
ERROR_LINE: 'ERROR_LINE';
ERROR_MESSAGE: 'ERROR_MESSAGE';
Expand Down Expand Up @@ -372,6 +378,8 @@ FAN_IN: 'FAN_IN';
FAST: 'FAST';
FAST_FORWARD: 'FAST_FORWARD';
FETCH: 'FETCH';
FIELDTERMINATOR: 'FIELDTERMINATOR';
FIELDQUOTE: 'FIELDQUOTE';
FILE: 'FILE';
FILEGROUP: 'FILEGROUP';
FILEGROUPPROPERTY: 'FILEGROUPPROPERTY';
Expand All @@ -391,6 +399,8 @@ FILE_SNAPSHOT: 'FILE_SNAPSHOT';
FILLFACTOR: 'FILLFACTOR';
FILTER: 'FILTER';
FIRST: 'FIRST';
FIRE_TRIGGERS: 'FIRE_TRIGGERS';
FIRSTROW: 'FIRSTROW';
FIRST_VALUE: 'FIRST_VALUE';
FMTONLY: 'FMTONLY';
FOLLOWING: 'FOLLOWING';
Expand All @@ -404,6 +414,8 @@ FORCE_FAILOVER_ALLOW_DATA_LOSS: 'FORCE_FAILOVER_ALLOW_DATA_LOSS';
FORCE_SERVICE_ALLOW_DATA_LOSS: 'FORCE_SERVICE_ALLOW_DATA_LOSS';
FOREIGN: 'FOREIGN';
FORMAT: 'FORMAT';
FORMATFILE: 'FORMATFILE';
FORMATFILE_DATA_SOURCE: 'FORMATFILE_DATA_SOURCE';
FORMATMESSAGE: 'FORMATMESSAGE';
FORWARD_ONLY: 'FORWARD_ONLY';
FREE: 'FREE';
Expand Down Expand Up @@ -519,6 +531,7 @@ KEEP: 'KEEP';
KEEPDEFAULTS: 'KEEPDEFAULTS';
KEEPFIXED: 'KEEPFIXED';
KEEPIDENTITY: 'KEEPIDENTITY';
KEEPNULLS: 'KEEPNULLS';
KERBEROS: 'KERBEROS';
KEY: 'KEY';
KEYS: 'KEYS';
Expand All @@ -527,9 +540,11 @@ KEY_PATH: 'KEY_PATH';
KEY_SOURCE: 'KEY_SOURCE';
KEY_STORE_PROVIDER_NAME: 'KEY_STORE_PROVIDER_NAME';
KILL: 'KILL';
KILOBYTES_PER_BATCH: 'KILOBYTES_PER_BATCH';
LAG: 'LAG';
LANGUAGE: 'LANGUAGE';
LAST: 'LAST';
LASTROW: 'LASTROW';
LAST_VALUE: 'LAST_VALUE';
LEAD: 'LEAD';
LEAST: 'LEAST';
Expand Down Expand Up @@ -570,6 +585,7 @@ MATCHED: 'MATCHED';
MATERIALIZED: 'MATERIALIZED';
MAX: 'MAX';
MAXDOP: 'MAXDOP';
MAXERRORS: 'MAXERRORS';
MAXRECURSION: 'MAXRECURSION';
MAXSIZE: 'MAXSIZE';
MAXTRANSFER: 'MAXTRANSFER';
Expand Down Expand Up @@ -863,6 +879,8 @@ ROWGUIDCOL: 'ROWGUIDCOL';
ROWLOCK: 'ROWLOCK';
ROWS: 'ROWS';
ROW_NUMBER: 'ROW_NUMBER';
ROWS_PER_BATCH: 'ROWS_PER_BATCH';
ROWTERMINATOR: 'ROWTERMINATOR';
RSA_1024: 'RSA_1024';
RSA_2048: 'RSA_2048';
RSA_3072: 'RSA_3072';
Expand Down
35 changes: 35 additions & 0 deletions sql/tsql/TSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dml_clause
| insert_statement
| select_statement_standalone
| update_statement
| bulk_insert_statement
;

// Data Definition Language: https://msdn.microsoft.com/en-us/library/ff848799.aspx)
Expand Down Expand Up @@ -1994,6 +1995,40 @@ output_dml_list_elem
: (expression | asterisk) as_column_alias?
;

bulk_insert_statement
: BULK INSERT
ddl_object
FROM STRING
(WITH LR_BRACKET (bulk_insert_option (COMMA bulk_insert_option)*) RR_BRACKET)?
Copy link
Member

Choose a reason for hiding this comment

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

Remove useless parentheses:

Suggested change
(WITH LR_BRACKET (bulk_insert_option (COMMA bulk_insert_option)*) RR_BRACKET)?
(WITH LR_BRACKET bulk_insert_option (COMMA bulk_insert_option)* RR_BRACKET)?

;

bulk_insert_option
: BATCHSIZE EQUAL DECIMAL
| CHECK_CONSTRAINTS
| CODEPAGE EQUAL STRING
| DATAFILETYPE EQUAL STRING
| DATA_SOURCE EQUAL STRING
| ERRORFILE EQUAL STRING
| ERRORFILE_DATA_SOURCE EQUAL STRING
| FIRSTROW EQUAL DECIMAL
| FIRE_TRIGGERS
| FORMATFILE_DATA_SOURCE EQUAL STRING
| KEEPIDENTITY
| KEEPNULLS
| KILOBYTES_PER_BATCH EQUAL DECIMAL
| LASTROW EQUAL DECIMAL
| MAXERRORS EQUAL DECIMAL
| ORDER LR_BRACKET column_name_list_with_order RR_BRACKET
| ROWS_PER_BATCH EQUAL DECIMAL
| ROWTERMINATOR EQUAL STRING
| TABLOCK
| FORMAT EQUAL STRING
| FIELDQUOTE EQUAL STRING
| FORMATFILE EQUAL STRING
| FIELDTERMINATOR EQUAL STRING
| ROWTERMINATOR EQUAL STRING
Comment on lines +2006 to +2029
Copy link
Member

Choose a reason for hiding this comment

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

Please extract common parts:

Suggested change
: BATCHSIZE EQUAL DECIMAL
| CHECK_CONSTRAINTS
| CODEPAGE EQUAL STRING
| DATAFILETYPE EQUAL STRING
| DATA_SOURCE EQUAL STRING
| ERRORFILE EQUAL STRING
| ERRORFILE_DATA_SOURCE EQUAL STRING
| FIRSTROW EQUAL DECIMAL
| FIRE_TRIGGERS
| FORMATFILE_DATA_SOURCE EQUAL STRING
| KEEPIDENTITY
| KEEPNULLS
| KILOBYTES_PER_BATCH EQUAL DECIMAL
| LASTROW EQUAL DECIMAL
| MAXERRORS EQUAL DECIMAL
| ORDER LR_BRACKET column_name_list_with_order RR_BRACKET
| ROWS_PER_BATCH EQUAL DECIMAL
| ROWTERMINATOR EQUAL STRING
| TABLOCK
| FORMAT EQUAL STRING
| FIELDQUOTE EQUAL STRING
| FORMATFILE EQUAL STRING
| FIELDTERMINATOR EQUAL STRING
| ROWTERMINATOR EQUAL STRING
: ( BATCHSIZE
| FIRSTROW
| KILOBYTES_PER_BATCH
| LASTROW
| MAXERRORS
| ROWS_PER_BATCH
) EQUAL DECIMAL
| ( CODEPAGE
| DATAFILETYPE
| DATA_SOURCE
| ERRORFILE
| ERRORFILE_DATA_SOURCE
| FORMATFILE_DATA_SOURCE
| ROWTERMINATOR
| FORMAT
| FIELDQUOTE
| FORMATFILE
| FIELDTERMINATOR
| ROWTERMINATOR
) EQUAL STRING
| CHECK_CONSTRAINTS
| FIRE_TRIGGERS
| KEEPIDENTITY
| KEEPNULLS
| ORDER LR_BRACKET column_name_list_with_order RR_BRACKET
| TABLOCK

;

// DDL

// https://msdn.microsoft.com/en-ie/library/ms176061.aspx
Expand Down