-
Notifications
You must be signed in to change notification settings - Fork 259
CSV import options for DELIMITER, NULL, and QUOTE #256
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
Merged
Greenscreen23
merged 11 commits into
hyrise:main
from
Greenscreen23:lukas/better-csv-import
Sep 17, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
38e3258
This branch implements more csv parsing options. The goal is that the…
Greenscreen23 062a6ec
move csv options to separate struct and check whether the format is c…
Greenscreen23 f7d7b9f
Use single CSV option, simplify parsing and add more test cases
Greenscreen23 0110e59
Add type specifier to std::pair
Greenscreen23 14069d8
Implement destructor, switch, remove namespace prefix and add more ba…
Greenscreen23 9b4f431
Add addtitional anti testcase
Greenscreen23 95f98b8
Add more good query examples
Greenscreen23 9c638a7
Shorten csv option handling
Greenscreen23 7d8171f
Merge branch 'main' of https://github.com/hyrise/sql-parser into luka…
Greenscreen23 31b8916
Move accept_csv_option to struct CsvOptions
Greenscreen23 5166a80
Last changes
Greenscreen23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -168,6 +168,7 @@ | |||||||||||
| hsql::RowLockWaitPolicy lock_wait_policy_t; | ||||||||||||
|
|
||||||||||||
| hsql::ImportExportOptions* import_export_option_t; | ||||||||||||
| std::pair<hsql::CsvOptionType, char*>* csv_option_t; | ||||||||||||
|
|
||||||||||||
| // clang-format off | ||||||||||||
| } | ||||||||||||
|
|
@@ -198,6 +199,7 @@ | |||||||||||
| } | ||||||||||||
| delete ($$); | ||||||||||||
| } <table_vec> <table_element_vec> <update_vec> <expr_vec> <order_vec> <stmt_vec> | ||||||||||||
| %destructor { free($$->second); delete ($$); } <csv_option_t> | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| %destructor { delete ($$); } <*> | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -292,6 +294,7 @@ | |||||||||||
| // ImportType is used for compatibility reasons | ||||||||||||
| %type <import_type_t> file_type | ||||||||||||
| %type <import_export_option_t> opt_import_export_options import_export_options | ||||||||||||
| %type <csv_option_t> csv_option | ||||||||||||
|
|
||||||||||||
| %type <str_vec> ident_commalist opt_column_list | ||||||||||||
| %type <expr_vec> expr_list select_list opt_extended_literal_list extended_literal_list hint_list opt_hints opt_partition | ||||||||||||
|
|
@@ -467,6 +470,10 @@ import_statement : IMPORT FROM file_type FILE file_path INTO table_name { | |||||||||||
| $$->encoding = $5->encoding; | ||||||||||||
| $5->encoding = nullptr; | ||||||||||||
| } | ||||||||||||
| if ($5->csv_options) { | ||||||||||||
| $$->csv_options = $5->csv_options; | ||||||||||||
| $5->csv_options = nullptr; | ||||||||||||
| } | ||||||||||||
| delete $5; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
|
|
@@ -497,6 +504,11 @@ import_export_options : import_export_options ',' FORMAT file_type { | |||||||||||
| yyerror(&yyloc, result, scanner, "File type must only be provided once."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
| if ($1->csv_options && $4 != kImportCSV && $4 != kImportAuto) { | ||||||||||||
| delete $1; | ||||||||||||
| yyerror(&yyloc, result, scanner, "CSV options (DELIMITER, NULL, QUOTE) are only allowed for CSV files."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
| $1->format = $4; | ||||||||||||
| $$ = $1; | ||||||||||||
| } | ||||||||||||
|
|
@@ -517,7 +529,97 @@ import_export_options : import_export_options ',' FORMAT file_type { | |||||||||||
| | ENCODING STRING { | ||||||||||||
| $$ = new ImportExportOptions{}; | ||||||||||||
| $$->encoding = $2; | ||||||||||||
| }; | ||||||||||||
| } | ||||||||||||
| | import_export_options ',' csv_option { | ||||||||||||
|
Bouncner marked this conversation as resolved.
|
||||||||||||
| if ($1->format != kImportAuto && $1->format != kImportCSV) { | ||||||||||||
| delete $1; | ||||||||||||
| free($3->second); | ||||||||||||
| delete $3; | ||||||||||||
|
Greenscreen23 marked this conversation as resolved.
|
||||||||||||
| yyerror(&yyloc, result, scanner, "CSV options (DELIMITER, NULL, QUOTE) are only allowed for CSV files."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($1->csv_options == nullptr) { | ||||||||||||
| $1->csv_options = new CsvOptions{}; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| bool freed_ptr = false; | ||||||||||||
| auto free_if_necessary = [&](char* ptr) { | ||||||||||||
| if (ptr != nullptr) { | ||||||||||||
|
Bouncner marked this conversation as resolved.
Outdated
|
||||||||||||
| free(ptr); | ||||||||||||
| freed_ptr = true; | ||||||||||||
| } | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| switch ($3->first) { | ||||||||||||
| case CsvOptionType::Delimiter: | ||||||||||||
| free_if_necessary($1->csv_options->delimiter); | ||||||||||||
| $1->csv_options->delimiter = $3->second; | ||||||||||||
| break; | ||||||||||||
| case CsvOptionType::Null: | ||||||||||||
| free_if_necessary($1->csv_options->null); | ||||||||||||
| $1->csv_options->null = $3->second; | ||||||||||||
| break; | ||||||||||||
| case CsvOptionType::Quote: | ||||||||||||
| free_if_necessary($1->csv_options->quote); | ||||||||||||
| $1->csv_options->quote = $3->second; | ||||||||||||
| break; | ||||||||||||
| default: | ||||||||||||
| free($3->second); | ||||||||||||
| delete $3; | ||||||||||||
| delete $1; | ||||||||||||
| yyerror(&yyloc, result, scanner, "Unknown CSV option."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
| delete $3; | ||||||||||||
|
|
||||||||||||
| if (freed_ptr) { | ||||||||||||
| delete $1; | ||||||||||||
| yyerror(&yyloc, result, scanner, "CSV options (DELIMITER, NULL, QUOTE) cannot be provided more than once."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $$ = $1; | ||||||||||||
| } | ||||||||||||
| | csv_option { | ||||||||||||
| $$ = new ImportExportOptions{}; | ||||||||||||
| $$->csv_options = new CsvOptions{}; | ||||||||||||
|
|
||||||||||||
| switch ($1->first) { | ||||||||||||
| case CsvOptionType::Delimiter: | ||||||||||||
| $$->csv_options->delimiter = $1->second; | ||||||||||||
| break; | ||||||||||||
| case CsvOptionType::Null: | ||||||||||||
| $$->csv_options->null = $1->second; | ||||||||||||
| break; | ||||||||||||
| case CsvOptionType::Quote: | ||||||||||||
| $$->csv_options->quote = $1->second; | ||||||||||||
| break; | ||||||||||||
| default: | ||||||||||||
| free($1->second); | ||||||||||||
| delete $1; | ||||||||||||
| delete $$; | ||||||||||||
| yyerror(&yyloc, result, scanner, "Unknown CSV option."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| delete $1; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| csv_option : IDENTIFIER STRING { | ||||||||||||
| if (strcasecmp($1, "DELIMITER") == 0) { | ||||||||||||
| $$ = new std::pair<CsvOptionType, char*>(CsvOptionType::Delimiter, $2); | ||||||||||||
| } else if (strcasecmp($1, "QUOTE") == 0) { | ||||||||||||
| $$ = new std::pair<CsvOptionType, char*>(CsvOptionType::Quote, $2); | ||||||||||||
| } else { | ||||||||||||
| free($1); | ||||||||||||
| free($2); | ||||||||||||
| yyerror(&yyloc, result, scanner, "Unknown CSV option."); | ||||||||||||
| YYERROR; | ||||||||||||
| } | ||||||||||||
| free($1); | ||||||||||||
| } | ||||||||||||
| | NULL STRING { $$ = new std::pair<CsvOptionType, char*>(CsvOptionType::Null, $2); } | ||||||||||||
|
|
||||||||||||
| /****************************** | ||||||||||||
| * Export Statement | ||||||||||||
|
|
@@ -533,6 +635,10 @@ export_statement : COPY table_name TO file_path opt_import_export_options { | |||||||||||
| $$->encoding = $5->encoding; | ||||||||||||
| $5->encoding = nullptr; | ||||||||||||
| } | ||||||||||||
| if ($5->csv_options) { | ||||||||||||
| $$->csv_options = $5->csv_options; | ||||||||||||
| $5->csv_options = nullptr; | ||||||||||||
| } | ||||||||||||
| delete $5; | ||||||||||||
| } | ||||||||||||
| | COPY select_with_paren TO file_path opt_import_export_options { | ||||||||||||
|
|
@@ -543,6 +649,10 @@ export_statement : COPY table_name TO file_path opt_import_export_options { | |||||||||||
| $$->encoding = $5->encoding; | ||||||||||||
| $5->encoding = nullptr; | ||||||||||||
| } | ||||||||||||
| if ($5->csv_options) { | ||||||||||||
| $$->csv_options = $5->csv_options; | ||||||||||||
| $5->csv_options = nullptr; | ||||||||||||
| } | ||||||||||||
| delete $5; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.