168168 hsql::RowLockWaitPolicy lock_wait_policy_t ;
169169
170170 hsql::ImportExportOptions* import_export_option_t ;
171+ hsql::CsvImportExportOptions* csv_import_export_option_t ;
171172
172173 // clang-format off
173174}
230231%token NOWAIT SKIP LOCKED SHARE
231232%token RANGE ROWS GROUPS UNBOUNDED FOLLOWING PRECEDING CURRENT_ROW
232233%token UNIQUE PRIMARY FOREIGN KEY REFERENCES
233- %token DELIMITER QUOTE
234234
235235/* ********************************
236236 ** Non-Terminal types (http://www.gnu.org/software/bison/manual/html_node/Type-Decl.html)
293293// ImportType is used for compatibility reasons
294294%type <import_type_t> file_type
295295%type <import_export_option_t> opt_import_export_options import_export_options
296+ %type <csv_import_export_option_t> csv_import_export_options
296297
297298%type <str_vec> ident_commalist opt_column_list
298299%type <expr_vec> expr_list select_list opt_extended_literal_list extended_literal_list hint_list opt_hints opt_partition
@@ -468,17 +469,9 @@ import_statement : IMPORT FROM file_type FILE file_path INTO table_name {
468469 $$ ->encoding = $5 ->encoding;
469470 $5 ->encoding = nullptr ;
470471 }
471- if ($5 ->delimiter) {
472- $$ ->delimiter = $5 ->delimiter;
473- $5 ->delimiter = nullptr ;
474- }
475- if ($5 ->null) {
476- $$ ->null = $5 ->null;
477- $5 ->null = nullptr ;
478- }
479- if ($5 ->quote) {
480- $$ ->quote = $5 ->quote;
481- $5 ->quote = nullptr ;
472+ if ($5 ->csv_options) {
473+ $$ ->csv_options = $5 ->csv_options;
474+ $5 ->csv_options = nullptr ;
482475 }
483476 delete $5 ;
484477};
@@ -510,6 +503,11 @@ import_export_options : import_export_options ',' FORMAT file_type {
510503 yyerror (&yyloc, result, scanner, " File type must only be provided once." );
511504 YYERROR ;
512505 }
506+ if ($1 ->csv_options && $4 != kImportCSV && $4 != kImportAuto ) {
507+ delete $1 ;
508+ yyerror (&yyloc, result, scanner, " Cannot have CSV options (DELIMITER, NULL, QUOTE) without CSV import type." );
509+ YYERROR ;
510+ }
513511 $1 ->format = $4 ;
514512 $$ = $1 ;
515513}
@@ -531,48 +529,78 @@ import_export_options : import_export_options ',' FORMAT file_type {
531529 $$ = new ImportExportOptions{};
532530 $$ ->encoding = $2 ;
533531}
534- | import_export_options ' ,' DELIMITER STRING {
535- if ($1 ->delimiter ) {
532+ | import_export_options ' ,' csv_import_export_options {
533+ if ($1 ->format != kImportAuto && $1 ->format != kImportCSV ) {
536534 delete $1 ;
537- free ($ 4 ) ;
538- yyerror (&yyloc, result, scanner, " Delimiter must only be provided once ." );
535+ delete $3 ;
536+ yyerror (&yyloc, result, scanner, " Cannot have CSV options (DELIMITER, NULL, QUOTE) without CSV import type ." );
539537 YYERROR ;
540538 }
541- $1 ->delimiter = $4 ;
539+
540+ if ($1 ->csv_options) {
541+ if ($1 ->csv_options->delimiter && $3 ->delimiter) {
542+ delete $1 ;
543+ delete $3 ;
544+ yyerror (&yyloc, result, scanner, " Delimiter must only be provided once." );
545+ YYERROR ;
546+ }
547+ if ($1 ->csv_options->null && $3 ->null) {
548+ delete $1 ;
549+ delete $3 ;
550+ yyerror (&yyloc, result, scanner, " Null string must only be provided once." );
551+ YYERROR ;
552+ }
553+ if ($1 ->csv_options->quote && $3 ->quote) {
554+ delete $1 ;
555+ delete $3 ;
556+ yyerror (&yyloc, result, scanner, " Quote must only be provided once." );
557+ YYERROR ;
558+ }
559+
560+ if ($3 ->delimiter) {
561+ $1 ->csv_options->delimiter = $3 ->delimiter;
562+ $3 ->delimiter = nullptr ;
563+ }
564+ if ($3 ->null) {
565+ $1 ->csv_options->null = $3 ->null;
566+ $3 ->null = nullptr ;
567+
568+ }
569+ if ($3 ->quote) {
570+ $1 ->csv_options->quote = $3 ->quote;
571+ $3 ->quote = nullptr ;
572+ }
573+ delete $3 ;
574+ } else {
575+ $1 ->csv_options = $3 ;
576+ }
577+
542578 $$ = $1 ;
543579}
544- | DELIMITER STRING {
580+ | csv_import_export_options {
545581 $$ = new ImportExportOptions{};
546- $$ ->delimiter = $2 ;
582+ $$ ->csv_options = $1 ;
547583}
548- | import_export_options ' ,' NULL STRING {
549- if ($1 ->null) {
550- delete $1 ;
551- free ($4 );
552- yyerror (&yyloc, result, scanner, " Null string must only be provided once." );
584+
585+ csv_import_export_options : IDENTIFIER STRING {
586+ $$ = new CsvImportExportOptions{};
587+ if (strcasecmp($1 , " DELIMITER" ) == 0 ) {
588+ $$ ->delimiter = $2 ;
589+ } else if (strcasecmp($1 , " QUOTE" ) == 0 ) {
590+ $$ ->quote = $2 ;
591+ } else {
592+ delete $$ ;
593+ free ($1 );
594+ free ($2 );
595+ yyerror (&yyloc, result, scanner, " Unknown identifier when parsing CSV options." );
553596 YYERROR ;
554597 }
555- $1 ->null = $4 ;
556- $$ = $1 ;
598+ free ($1 );
557599}
558600| NULL STRING {
559- $$ = new ImportExportOptions {};
601+ $$ = new CsvImportExportOptions {};
560602 $$ ->null = $2 ;
561603}
562- | import_export_options ' ,' QUOTE STRING {
563- if ($1 ->quote) {
564- delete $1 ;
565- free ($4 );
566- yyerror (&yyloc, result, scanner, " Quote string must only be provided once." );
567- YYERROR ;
568- }
569- $1 ->quote = $4 ;
570- $$ = $1 ;
571- }
572- | QUOTE STRING {
573- $$ = new ImportExportOptions{};
574- $$ ->quote = $2 ;
575- };
576604
577605/* *****************************
578606 * Export Statement
@@ -588,17 +616,9 @@ export_statement : COPY table_name TO file_path opt_import_export_options {
588616 $$ ->encoding = $5 ->encoding;
589617 $5 ->encoding = nullptr ;
590618 }
591- if ($5 ->delimiter) {
592- $$ ->delimiter = $5 ->delimiter;
593- $5 ->delimiter = nullptr ;
594- }
595- if ($5 ->null) {
596- $$ ->null = $5 ->null;
597- $5 ->null = nullptr ;
598- }
599- if ($5 ->quote) {
600- $$ ->quote = $5 ->quote;
601- $5 ->quote = nullptr ;
619+ if ($5 ->csv_options) {
620+ $$ ->csv_options = $5 ->csv_options;
621+ $5 ->csv_options = nullptr ;
602622 }
603623 delete $5 ;
604624}
@@ -610,17 +630,9 @@ export_statement : COPY table_name TO file_path opt_import_export_options {
610630 $$ ->encoding = $5 ->encoding;
611631 $5 ->encoding = nullptr ;
612632 }
613- if ($5 ->delimiter) {
614- $$ ->delimiter = $5 ->delimiter;
615- $5 ->delimiter = nullptr ;
616- }
617- if ($5 ->null) {
618- $$ ->null = $5 ->null;
619- $5 ->null = nullptr ;
620- }
621- if ($5 ->quote) {
622- $$ ->quote = $5 ->quote;
623- $5 ->quote = nullptr ;
633+ if ($5 ->csv_options) {
634+ $$ ->csv_options = $5 ->csv_options;
635+ $5 ->csv_options = nullptr ;
624636 }
625637 delete $5 ;
626638};
0 commit comments