Add COPY for import and export (#139)
This commit is contained in:
parent
907b668151
commit
e3cfc80975
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
/* A Bison parser, made by GNU Bison 3.3.2. */
|
/* A Bison parser, made by GNU Bison 3.4.1. */
|
||||||
|
|
||||||
/* Bison interface for Yacc-like parsers in C
|
/* Bison interface for Yacc-like parsers in C
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
extern int hsql_debug;
|
extern int hsql_debug;
|
||||||
#endif
|
#endif
|
||||||
/* "%code requires" blocks. */
|
/* "%code requires" blocks. */
|
||||||
#line 35 "bison_parser.y" /* yacc.c:1927 */
|
#line 35 "bison_parser.y"
|
||||||
|
|
||||||
// %code requires block
|
// %code requires block
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ extern int hsql_debug;
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 80 "bison_parser.h" /* yacc.c:1927 */
|
#line 80 "bison_parser.h"
|
||||||
|
|
||||||
/* Token type. */
|
/* Token type. */
|
||||||
#ifndef HSQL_TOKENTYPE
|
#ifndef HSQL_TOKENTYPE
|
||||||
|
@ -123,80 +123,80 @@ extern int hsql_debug;
|
||||||
SQL_EXCEPT = 295,
|
SQL_EXCEPT = 295,
|
||||||
SQL_EXISTS = 296,
|
SQL_EXISTS = 296,
|
||||||
SQL_EXTRACT = 297,
|
SQL_EXTRACT = 297,
|
||||||
SQL_GLOBAL = 298,
|
SQL_FORMAT = 298,
|
||||||
SQL_HAVING = 299,
|
SQL_GLOBAL = 299,
|
||||||
SQL_IMPORT = 300,
|
SQL_HAVING = 300,
|
||||||
SQL_INSERT = 301,
|
SQL_IMPORT = 301,
|
||||||
SQL_ISNULL = 302,
|
SQL_INSERT = 302,
|
||||||
SQL_OFFSET = 303,
|
SQL_ISNULL = 303,
|
||||||
SQL_RENAME = 304,
|
SQL_OFFSET = 304,
|
||||||
SQL_SCHEMA = 305,
|
SQL_RENAME = 305,
|
||||||
SQL_SELECT = 306,
|
SQL_SCHEMA = 306,
|
||||||
SQL_SORTED = 307,
|
SQL_SELECT = 307,
|
||||||
SQL_TABLES = 308,
|
SQL_SORTED = 308,
|
||||||
SQL_UNIQUE = 309,
|
SQL_TABLES = 309,
|
||||||
SQL_UNLOAD = 310,
|
SQL_UNIQUE = 310,
|
||||||
SQL_UPDATE = 311,
|
SQL_UNLOAD = 311,
|
||||||
SQL_VALUES = 312,
|
SQL_UPDATE = 312,
|
||||||
SQL_AFTER = 313,
|
SQL_VALUES = 313,
|
||||||
SQL_ALTER = 314,
|
SQL_AFTER = 314,
|
||||||
SQL_CROSS = 315,
|
SQL_ALTER = 315,
|
||||||
SQL_DELTA = 316,
|
SQL_CROSS = 316,
|
||||||
SQL_FLOAT = 317,
|
SQL_DELTA = 317,
|
||||||
SQL_GROUP = 318,
|
SQL_FLOAT = 318,
|
||||||
SQL_INDEX = 319,
|
SQL_GROUP = 319,
|
||||||
SQL_INNER = 320,
|
SQL_INDEX = 320,
|
||||||
SQL_LIMIT = 321,
|
SQL_INNER = 321,
|
||||||
SQL_LOCAL = 322,
|
SQL_LIMIT = 322,
|
||||||
SQL_MERGE = 323,
|
SQL_LOCAL = 323,
|
||||||
SQL_MINUS = 324,
|
SQL_MERGE = 324,
|
||||||
SQL_ORDER = 325,
|
SQL_MINUS = 325,
|
||||||
SQL_OUTER = 326,
|
SQL_ORDER = 326,
|
||||||
SQL_RIGHT = 327,
|
SQL_OUTER = 327,
|
||||||
SQL_TABLE = 328,
|
SQL_RIGHT = 328,
|
||||||
SQL_UNION = 329,
|
SQL_TABLE = 329,
|
||||||
SQL_USING = 330,
|
SQL_UNION = 330,
|
||||||
SQL_WHERE = 331,
|
SQL_USING = 331,
|
||||||
SQL_CALL = 332,
|
SQL_WHERE = 332,
|
||||||
SQL_CASE = 333,
|
SQL_CALL = 333,
|
||||||
SQL_CHAR = 334,
|
SQL_CASE = 334,
|
||||||
SQL_DATE = 335,
|
SQL_CHAR = 335,
|
||||||
SQL_DESC = 336,
|
SQL_COPY = 336,
|
||||||
SQL_DROP = 337,
|
SQL_DATE = 337,
|
||||||
SQL_ELSE = 338,
|
SQL_DESC = 338,
|
||||||
SQL_FILE = 339,
|
SQL_DROP = 339,
|
||||||
SQL_FROM = 340,
|
SQL_ELSE = 340,
|
||||||
SQL_FULL = 341,
|
SQL_FILE = 341,
|
||||||
SQL_HASH = 342,
|
SQL_FROM = 342,
|
||||||
SQL_HINT = 343,
|
SQL_FULL = 343,
|
||||||
SQL_INTO = 344,
|
SQL_HASH = 344,
|
||||||
SQL_JOIN = 345,
|
SQL_HINT = 345,
|
||||||
SQL_LEFT = 346,
|
SQL_INTO = 346,
|
||||||
SQL_LIKE = 347,
|
SQL_JOIN = 347,
|
||||||
SQL_LOAD = 348,
|
SQL_LEFT = 348,
|
||||||
SQL_LONG = 349,
|
SQL_LIKE = 349,
|
||||||
SQL_NULL = 350,
|
SQL_LOAD = 350,
|
||||||
SQL_PLAN = 351,
|
SQL_LONG = 351,
|
||||||
SQL_SHOW = 352,
|
SQL_NULL = 352,
|
||||||
SQL_TEXT = 353,
|
SQL_PLAN = 353,
|
||||||
SQL_THEN = 354,
|
SQL_SHOW = 354,
|
||||||
SQL_TIME = 355,
|
SQL_TEXT = 355,
|
||||||
SQL_VIEW = 356,
|
SQL_THEN = 356,
|
||||||
SQL_WHEN = 357,
|
SQL_TIME = 357,
|
||||||
SQL_WITH = 358,
|
SQL_VIEW = 358,
|
||||||
SQL_ADD = 359,
|
SQL_WHEN = 359,
|
||||||
SQL_ALL = 360,
|
SQL_WITH = 360,
|
||||||
SQL_AND = 361,
|
SQL_ADD = 361,
|
||||||
SQL_ASC = 362,
|
SQL_ALL = 362,
|
||||||
SQL_CSV = 363,
|
SQL_AND = 363,
|
||||||
SQL_END = 364,
|
SQL_ASC = 364,
|
||||||
SQL_FOR = 365,
|
SQL_END = 365,
|
||||||
SQL_INT = 366,
|
SQL_FOR = 366,
|
||||||
SQL_KEY = 367,
|
SQL_INT = 367,
|
||||||
SQL_NOT = 368,
|
SQL_KEY = 368,
|
||||||
SQL_OFF = 369,
|
SQL_NOT = 369,
|
||||||
SQL_SET = 370,
|
SQL_OFF = 370,
|
||||||
SQL_TBL = 371,
|
SQL_SET = 371,
|
||||||
SQL_TOP = 372,
|
SQL_TOP = 372,
|
||||||
SQL_AS = 373,
|
SQL_AS = 373,
|
||||||
SQL_BY = 374,
|
SQL_BY = 374,
|
||||||
|
@ -231,10 +231,9 @@ extern int hsql_debug;
|
||||||
|
|
||||||
/* Value type. */
|
/* Value type. */
|
||||||
#if ! defined HSQL_STYPE && ! defined HSQL_STYPE_IS_DECLARED
|
#if ! defined HSQL_STYPE && ! defined HSQL_STYPE_IS_DECLARED
|
||||||
|
|
||||||
union HSQL_STYPE
|
union HSQL_STYPE
|
||||||
{
|
{
|
||||||
#line 95 "bison_parser.y" /* yacc.c:1927 */
|
#line 95 "bison_parser.y"
|
||||||
|
|
||||||
double fval;
|
double fval;
|
||||||
int64_t ival;
|
int64_t ival;
|
||||||
|
@ -245,6 +244,7 @@ union HSQL_STYPE
|
||||||
hsql::SQLStatement* statement;
|
hsql::SQLStatement* statement;
|
||||||
hsql::SelectStatement* select_stmt;
|
hsql::SelectStatement* select_stmt;
|
||||||
hsql::ImportStatement* import_stmt;
|
hsql::ImportStatement* import_stmt;
|
||||||
|
hsql::ExportStatement* export_stmt;
|
||||||
hsql::CreateStatement* create_stmt;
|
hsql::CreateStatement* create_stmt;
|
||||||
hsql::InsertStatement* insert_stmt;
|
hsql::InsertStatement* insert_stmt;
|
||||||
hsql::DeleteStatement* delete_stmt;
|
hsql::DeleteStatement* delete_stmt;
|
||||||
|
@ -264,6 +264,7 @@ union HSQL_STYPE
|
||||||
hsql::LimitDescription* limit;
|
hsql::LimitDescription* limit;
|
||||||
hsql::ColumnDefinition* column_t;
|
hsql::ColumnDefinition* column_t;
|
||||||
hsql::ColumnType column_type_t;
|
hsql::ColumnType column_type_t;
|
||||||
|
hsql::ImportType import_type_t;
|
||||||
hsql::GroupByDescription* group_t;
|
hsql::GroupByDescription* group_t;
|
||||||
hsql::UpdateClause* update_t;
|
hsql::UpdateClause* update_t;
|
||||||
hsql::Alias* alias_t;
|
hsql::Alias* alias_t;
|
||||||
|
@ -278,9 +279,9 @@ union HSQL_STYPE
|
||||||
std::vector<hsql::OrderDescription*>* order_vec;
|
std::vector<hsql::OrderDescription*>* order_vec;
|
||||||
std::vector<hsql::WithDescription*>* with_description_vec;
|
std::vector<hsql::WithDescription*>* with_description_vec;
|
||||||
|
|
||||||
#line 282 "bison_parser.h" /* yacc.c:1927 */
|
#line 283 "bison_parser.h"
|
||||||
};
|
|
||||||
|
|
||||||
|
};
|
||||||
typedef union HSQL_STYPE HSQL_STYPE;
|
typedef union HSQL_STYPE HSQL_STYPE;
|
||||||
# define HSQL_STYPE_IS_TRIVIAL 1
|
# define HSQL_STYPE_IS_TRIVIAL 1
|
||||||
# define HSQL_STYPE_IS_DECLARED 1
|
# define HSQL_STYPE_IS_DECLARED 1
|
||||||
|
|
|
@ -102,6 +102,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
hsql::SQLStatement* statement;
|
hsql::SQLStatement* statement;
|
||||||
hsql::SelectStatement* select_stmt;
|
hsql::SelectStatement* select_stmt;
|
||||||
hsql::ImportStatement* import_stmt;
|
hsql::ImportStatement* import_stmt;
|
||||||
|
hsql::ExportStatement* export_stmt;
|
||||||
hsql::CreateStatement* create_stmt;
|
hsql::CreateStatement* create_stmt;
|
||||||
hsql::InsertStatement* insert_stmt;
|
hsql::InsertStatement* insert_stmt;
|
||||||
hsql::DeleteStatement* delete_stmt;
|
hsql::DeleteStatement* delete_stmt;
|
||||||
|
@ -121,6 +122,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
hsql::LimitDescription* limit;
|
hsql::LimitDescription* limit;
|
||||||
hsql::ColumnDefinition* column_t;
|
hsql::ColumnDefinition* column_t;
|
||||||
hsql::ColumnType column_type_t;
|
hsql::ColumnType column_type_t;
|
||||||
|
hsql::ImportType import_type_t;
|
||||||
hsql::GroupByDescription* group_t;
|
hsql::GroupByDescription* group_t;
|
||||||
hsql::UpdateClause* update_t;
|
hsql::UpdateClause* update_t;
|
||||||
hsql::Alias* alias_t;
|
hsql::Alias* alias_t;
|
||||||
|
@ -140,7 +142,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
/*********************************
|
/*********************************
|
||||||
** Destructor symbols
|
** Destructor symbols
|
||||||
*********************************/
|
*********************************/
|
||||||
%destructor { } <fval> <ival> <uval> <bval> <order_type> <datetime_field> <column_type_t>
|
%destructor { } <fval> <ival> <uval> <bval> <order_type> <datetime_field> <column_type_t> <import_type_t>
|
||||||
%destructor { free( ($$.name) ); free( ($$.schema) ); } <table_name>
|
%destructor { free( ($$.name) ); free( ($$.schema) ); } <table_name>
|
||||||
%destructor { free( ($$) ); } <sval>
|
%destructor { free( ($$) ); } <sval>
|
||||||
%destructor {
|
%destructor {
|
||||||
|
@ -167,15 +169,15 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
%token CASCADE COLUMNS CONTROL DEFAULT EXECUTE EXPLAIN
|
%token CASCADE COLUMNS CONTROL DEFAULT EXECUTE EXPLAIN
|
||||||
%token INTEGER NATURAL PREPARE PRIMARY SCHEMAS
|
%token INTEGER NATURAL PREPARE PRIMARY SCHEMAS
|
||||||
%token SPATIAL VARCHAR VIRTUAL DESCRIBE BEFORE COLUMN CREATE DELETE DIRECT
|
%token SPATIAL VARCHAR VIRTUAL DESCRIBE BEFORE COLUMN CREATE DELETE DIRECT
|
||||||
%token DOUBLE ESCAPE EXCEPT EXISTS EXTRACT GLOBAL HAVING IMPORT
|
%token DOUBLE ESCAPE EXCEPT EXISTS EXTRACT FORMAT GLOBAL HAVING IMPORT
|
||||||
%token INSERT ISNULL OFFSET RENAME SCHEMA SELECT SORTED
|
%token INSERT ISNULL OFFSET RENAME SCHEMA SELECT SORTED
|
||||||
%token TABLES UNIQUE UNLOAD UPDATE VALUES AFTER ALTER CROSS
|
%token TABLES UNIQUE UNLOAD UPDATE VALUES AFTER ALTER CROSS
|
||||||
%token DELTA FLOAT GROUP INDEX INNER LIMIT LOCAL MERGE MINUS ORDER
|
%token DELTA FLOAT GROUP INDEX INNER LIMIT LOCAL MERGE MINUS ORDER
|
||||||
%token OUTER RIGHT TABLE UNION USING WHERE CALL CASE CHAR DATE
|
%token OUTER RIGHT TABLE UNION USING WHERE CALL CASE CHAR COPY DATE
|
||||||
%token DESC DROP ELSE FILE FROM FULL HASH HINT INTO JOIN
|
%token DESC DROP ELSE FILE FROM FULL HASH HINT INTO JOIN
|
||||||
%token LEFT LIKE LOAD LONG NULL PLAN SHOW TEXT THEN TIME
|
%token LEFT LIKE LOAD LONG NULL PLAN SHOW TEXT THEN TIME
|
||||||
%token VIEW WHEN WITH ADD ALL AND ASC CSV END FOR INT KEY
|
%token VIEW WHEN WITH ADD ALL AND ASC END FOR INT KEY
|
||||||
%token NOT OFF SET TBL TOP AS BY IF IN IS OF ON OR TO
|
%token NOT OFF SET TOP AS BY IF IN IS OF ON OR TO
|
||||||
%token ARRAY CONCAT ILIKE SECOND MINUTE HOUR DAY MONTH YEAR
|
%token ARRAY CONCAT ILIKE SECOND MINUTE HOUR DAY MONTH YEAR
|
||||||
%token TRUE FALSE
|
%token TRUE FALSE
|
||||||
|
|
||||||
|
@ -188,6 +190,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
%type <prep_stmt> prepare_statement
|
%type <prep_stmt> prepare_statement
|
||||||
%type <select_stmt> select_statement select_with_paren select_no_paren select_clause select_paren_or_clause
|
%type <select_stmt> select_statement select_with_paren select_no_paren select_clause select_paren_or_clause
|
||||||
%type <import_stmt> import_statement
|
%type <import_stmt> import_statement
|
||||||
|
%type <export_stmt> export_statement
|
||||||
%type <create_stmt> create_statement
|
%type <create_stmt> create_statement
|
||||||
%type <insert_stmt> insert_statement
|
%type <insert_stmt> insert_statement
|
||||||
%type <delete_stmt> delete_statement truncate_statement
|
%type <delete_stmt> delete_statement truncate_statement
|
||||||
|
@ -197,7 +200,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
%type <table_name> table_name
|
%type <table_name> table_name
|
||||||
%type <sval> file_path prepare_target_query
|
%type <sval> file_path prepare_target_query
|
||||||
%type <bval> opt_not_exists opt_exists opt_distinct opt_column_nullable
|
%type <bval> opt_not_exists opt_exists opt_distinct opt_column_nullable
|
||||||
%type <uval> import_file_type opt_join_type
|
%type <uval> opt_join_type
|
||||||
%type <table> opt_from_clause from_clause table_ref table_ref_atomic table_ref_name nonjoin_table_ref_atomic
|
%type <table> opt_from_clause from_clause table_ref table_ref_atomic table_ref_name nonjoin_table_ref_atomic
|
||||||
%type <table> join_clause table_ref_name_no_alias
|
%type <table> join_clause table_ref_name_no_alias
|
||||||
%type <expr> expr operand scalar_expr unary_expr binary_expr logic_expr exists_expr extract_expr
|
%type <expr> expr operand scalar_expr unary_expr binary_expr logic_expr exists_expr extract_expr
|
||||||
|
@ -216,6 +219,9 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
|
||||||
%type <alias_t> opt_table_alias table_alias opt_alias alias
|
%type <alias_t> opt_table_alias table_alias opt_alias alias
|
||||||
%type <with_description_t> with_description
|
%type <with_description_t> with_description
|
||||||
|
|
||||||
|
// ImportType is used for compatibility reasons
|
||||||
|
%type <import_type_t> opt_file_type file_type
|
||||||
|
|
||||||
%type <str_vec> ident_commalist opt_column_list
|
%type <str_vec> ident_commalist opt_column_list
|
||||||
%type <expr_vec> expr_list select_list opt_literal_list literal_list hint_list opt_hints
|
%type <expr_vec> expr_list select_list opt_literal_list literal_list hint_list opt_hints
|
||||||
%type <table_vec> table_ref_commalist
|
%type <table_vec> table_ref_commalist
|
||||||
|
@ -302,12 +308,17 @@ statement:
|
||||||
| show_statement {
|
| show_statement {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
| import_statement {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| export_statement {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
preparable_statement:
|
preparable_statement:
|
||||||
select_statement { $$ = $1; }
|
select_statement { $$ = $1; }
|
||||||
| import_statement { $$ = $1; }
|
|
||||||
| create_statement { $$ = $1; }
|
| create_statement { $$ = $1; }
|
||||||
| insert_statement { $$ = $1; }
|
| insert_statement { $$ = $1; }
|
||||||
| delete_statement { $$ = $1; }
|
| delete_statement { $$ = $1; }
|
||||||
|
@ -374,24 +385,65 @@ execute_statement:
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* Import Statement
|
* Import Statement
|
||||||
|
* IMPORT FROM TBL FILE 'test/students.tbl' INTO students
|
||||||
|
* COPY students FROM 'test/students.tbl' [WITH FORMAT TBL]
|
||||||
******************************/
|
******************************/
|
||||||
import_statement:
|
import_statement:
|
||||||
IMPORT FROM import_file_type FILE file_path INTO table_name {
|
IMPORT FROM file_type FILE file_path INTO table_name {
|
||||||
$$ = new ImportStatement((ImportType) $3);
|
$$ = new ImportStatement($3);
|
||||||
$$->filePath = $5;
|
$$->filePath = $5;
|
||||||
$$->schema = $7.schema;
|
$$->schema = $7.schema;
|
||||||
$$->tableName = $7.name;
|
$$->tableName = $7.name;
|
||||||
}
|
}
|
||||||
|
| COPY table_name FROM file_path opt_file_type {
|
||||||
|
$$ = new ImportStatement($5);
|
||||||
|
$$->filePath = $4;
|
||||||
|
$$->schema = $2.schema;
|
||||||
|
$$->tableName = $2.name;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
import_file_type:
|
file_type:
|
||||||
CSV { $$ = kImportCSV; }
|
IDENTIFIER {
|
||||||
|
if (strcasecmp($1, "csv") == 0) {
|
||||||
|
$$ = kImportCSV;
|
||||||
|
} else if (strcasecmp($1, "tbl") == 0) {
|
||||||
|
$$ = kImportTbl;
|
||||||
|
} else if (strcasecmp($1, "binary") == 0 || strcasecmp($1, "bin") == 0) {
|
||||||
|
$$ = kImportBinary;
|
||||||
|
} else {
|
||||||
|
free($1);
|
||||||
|
yyerror(&yyloc, result, scanner, "File type is unknown.");
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
|
free($1);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
file_path:
|
file_path:
|
||||||
string_literal { $$ = strdup($1->name); delete $1; }
|
string_literal { $$ = strdup($1->name); delete $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
opt_file_type:
|
||||||
|
WITH FORMAT file_type {
|
||||||
|
$$ = $3;
|
||||||
|
}
|
||||||
|
| /* empty */ { $$ = kImportAuto; }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* Export Statement
|
||||||
|
* COPY students TO 'test/students.tbl' (WITH FORMAT TBL)
|
||||||
|
******************************/
|
||||||
|
export_statement:
|
||||||
|
COPY table_name TO file_path opt_file_type {
|
||||||
|
$$ = new ExportStatement($5);
|
||||||
|
$$->filePath = $4;
|
||||||
|
$$->schema = $2.schema;
|
||||||
|
$$->tableName = $2.name;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* Show Statement
|
* Show Statement
|
||||||
|
@ -421,11 +473,17 @@ show_statement:
|
||||||
* CREATE TABLE students FROM TBL FILE 'test/students.tbl'
|
* CREATE TABLE students FROM TBL FILE 'test/students.tbl'
|
||||||
******************************/
|
******************************/
|
||||||
create_statement:
|
create_statement:
|
||||||
CREATE TABLE opt_not_exists table_name FROM TBL FILE file_path {
|
CREATE TABLE opt_not_exists table_name FROM IDENTIFIER FILE file_path {
|
||||||
$$ = new CreateStatement(kCreateTableFromTbl);
|
$$ = new CreateStatement(kCreateTableFromTbl);
|
||||||
$$->ifNotExists = $3;
|
$$->ifNotExists = $3;
|
||||||
$$->schema = $4.schema;
|
$$->schema = $4.schema;
|
||||||
$$->tableName = $4.name;
|
$$->tableName = $4.name;
|
||||||
|
if (strcasecmp($6, "tbl") != 0) {
|
||||||
|
free($6);
|
||||||
|
yyerror(&yyloc, result, scanner, "File type is unknown.");
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
|
free($6);
|
||||||
$$->filePath = $8;
|
$$->filePath = $8;
|
||||||
}
|
}
|
||||||
| CREATE TABLE opt_not_exists table_name '(' column_def_commalist ')' {
|
| CREATE TABLE opt_not_exists table_name '(' column_def_commalist ')' {
|
||||||
|
@ -700,6 +758,7 @@ select_list:
|
||||||
opt_from_clause:
|
opt_from_clause:
|
||||||
from_clause { $$ = $1; }
|
from_clause { $$ = $1; }
|
||||||
| /* empty */ { $$ = nullptr; }
|
| /* empty */ { $$ = nullptr; }
|
||||||
|
;
|
||||||
|
|
||||||
from_clause:
|
from_clause:
|
||||||
FROM table_ref { $$ = $2; }
|
FROM table_ref { $$ = $2; }
|
||||||
|
@ -723,6 +782,7 @@ opt_group:
|
||||||
opt_having:
|
opt_having:
|
||||||
HAVING expr { $$ = $2; }
|
HAVING expr { $$ = $2; }
|
||||||
| /* empty */ { $$ = nullptr; }
|
| /* empty */ { $$ = nullptr; }
|
||||||
|
;
|
||||||
|
|
||||||
opt_order:
|
opt_order:
|
||||||
ORDER BY order_list { $$ = $3; }
|
ORDER BY order_list { $$ = $3; }
|
||||||
|
@ -893,6 +953,7 @@ datetime_field:
|
||||||
| DAY { $$ = kDatetimeDay; }
|
| DAY { $$ = kDatetimeDay; }
|
||||||
| MONTH { $$ = kDatetimeMonth; }
|
| MONTH { $$ = kDatetimeMonth; }
|
||||||
| YEAR { $$ = kDatetimeYear; }
|
| YEAR { $$ = kDatetimeYear; }
|
||||||
|
;
|
||||||
|
|
||||||
array_expr:
|
array_expr:
|
||||||
ARRAY '[' expr_list ']' { $$ = Expr::makeArray($3); }
|
ARRAY '[' expr_list ']' { $$ = Expr::makeArray($3); }
|
||||||
|
@ -1022,6 +1083,7 @@ table_alias:
|
||||||
opt_table_alias:
|
opt_table_alias:
|
||||||
table_alias
|
table_alias
|
||||||
| /* empty */ { $$ = nullptr; }
|
| /* empty */ { $$ = nullptr; }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
alias:
|
alias:
|
||||||
|
@ -1033,6 +1095,7 @@ alias:
|
||||||
opt_alias:
|
opt_alias:
|
||||||
alias
|
alias
|
||||||
| /* empty */ { $$ = nullptr; }
|
| /* empty */ { $$ = nullptr; }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,9 +2,9 @@
|
||||||
#define hsql_HEADER_H 1
|
#define hsql_HEADER_H 1
|
||||||
#define hsql_IN_HEADER 1
|
#define hsql_IN_HEADER 1
|
||||||
|
|
||||||
#line 5 "flex_lexer.h"
|
#line 6 "flex_lexer.h"
|
||||||
|
|
||||||
#line 7 "flex_lexer.h"
|
#line 8 "flex_lexer.h"
|
||||||
|
|
||||||
#define YY_INT_ALIGNED short int
|
#define YY_INT_ALIGNED short int
|
||||||
|
|
||||||
|
@ -733,6 +733,6 @@ extern int yylex \
|
||||||
#line 236 "flex_lexer.l"
|
#line 236 "flex_lexer.l"
|
||||||
|
|
||||||
|
|
||||||
#line 736 "flex_lexer.h"
|
#line 737 "flex_lexer.h"
|
||||||
#undef hsql_IN_HEADER
|
#undef hsql_IN_HEADER
|
||||||
#endif /* hsql_HEADER_H */
|
#endif /* hsql_HEADER_H */
|
||||||
|
|
|
@ -97,6 +97,7 @@ ESCAPE TOKEN(ESCAPE)
|
||||||
EXCEPT TOKEN(EXCEPT)
|
EXCEPT TOKEN(EXCEPT)
|
||||||
EXISTS TOKEN(EXISTS)
|
EXISTS TOKEN(EXISTS)
|
||||||
EXTRACT TOKEN(EXTRACT)
|
EXTRACT TOKEN(EXTRACT)
|
||||||
|
FORMAT TOKEN(FORMAT)
|
||||||
GLOBAL TOKEN(GLOBAL)
|
GLOBAL TOKEN(GLOBAL)
|
||||||
HAVING TOKEN(HAVING)
|
HAVING TOKEN(HAVING)
|
||||||
IMPORT TOKEN(IMPORT)
|
IMPORT TOKEN(IMPORT)
|
||||||
|
@ -135,6 +136,7 @@ WHERE TOKEN(WHERE)
|
||||||
CALL TOKEN(CALL)
|
CALL TOKEN(CALL)
|
||||||
CASE TOKEN(CASE)
|
CASE TOKEN(CASE)
|
||||||
CHAR TOKEN(CHAR)
|
CHAR TOKEN(CHAR)
|
||||||
|
COPY TOKEN(COPY)
|
||||||
DATE TOKEN(DATE)
|
DATE TOKEN(DATE)
|
||||||
DESC TOKEN(DESC)
|
DESC TOKEN(DESC)
|
||||||
DROP TOKEN(DROP)
|
DROP TOKEN(DROP)
|
||||||
|
@ -164,7 +166,6 @@ ADD TOKEN(ADD)
|
||||||
ALL TOKEN(ALL)
|
ALL TOKEN(ALL)
|
||||||
AND TOKEN(AND)
|
AND TOKEN(AND)
|
||||||
ASC TOKEN(ASC)
|
ASC TOKEN(ASC)
|
||||||
CSV TOKEN(CSV)
|
|
||||||
END TOKEN(END)
|
END TOKEN(END)
|
||||||
FOR TOKEN(FOR)
|
FOR TOKEN(FOR)
|
||||||
INT TOKEN(INT)
|
INT TOKEN(INT)
|
||||||
|
@ -172,7 +173,6 @@ KEY TOKEN(KEY)
|
||||||
NOT TOKEN(NOT)
|
NOT TOKEN(NOT)
|
||||||
OFF TOKEN(OFF)
|
OFF TOKEN(OFF)
|
||||||
SET TOKEN(SET)
|
SET TOKEN(SET)
|
||||||
TBL TOKEN(TBL)
|
|
||||||
TOP TOKEN(TOP)
|
TOP TOKEN(TOP)
|
||||||
AS TOKEN(AS)
|
AS TOKEN(AS)
|
||||||
BY TOKEN(BY)
|
BY TOKEN(BY)
|
||||||
|
|
|
@ -76,10 +76,11 @@ VALUES
|
||||||
DIRECT
|
DIRECT
|
||||||
SORTED
|
SORTED
|
||||||
|
|
||||||
|
COPY
|
||||||
|
FORMAT
|
||||||
|
|
||||||
IMPORT
|
IMPORT
|
||||||
CSV
|
|
||||||
FILE
|
FILE
|
||||||
TBL
|
|
||||||
CONTROL
|
CONTROL
|
||||||
|
|
||||||
UPDATE
|
UPDATE
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef SQLPARSER_EXPORT_STATEMENT_H
|
||||||
|
#define SQLPARSER_EXPORT_STATEMENT_H
|
||||||
|
|
||||||
|
#include "ImportStatement.h"
|
||||||
|
#include "SQLStatement.h"
|
||||||
|
|
||||||
|
namespace hsql {
|
||||||
|
// Represents SQL Export statements.
|
||||||
|
struct ExportStatement : SQLStatement {
|
||||||
|
ExportStatement(ImportType type);
|
||||||
|
virtual ~ExportStatement();
|
||||||
|
|
||||||
|
// ImportType is used for compatibility reasons
|
||||||
|
ImportType type;
|
||||||
|
char* filePath;
|
||||||
|
char* schema;
|
||||||
|
char* tableName;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace hsql
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,6 +7,8 @@ namespace hsql {
|
||||||
enum ImportType {
|
enum ImportType {
|
||||||
kImportCSV,
|
kImportCSV,
|
||||||
kImportTbl, // Hyrise file format
|
kImportTbl, // Hyrise file format
|
||||||
|
kImportBinary,
|
||||||
|
kImportAuto
|
||||||
};
|
};
|
||||||
|
|
||||||
// Represents SQL Import statements.
|
// Represents SQL Import statements.
|
||||||
|
|
|
@ -134,6 +134,20 @@ namespace hsql {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExportStatement
|
||||||
|
ExportStatement::ExportStatement(ImportType type) :
|
||||||
|
SQLStatement(kStmtExport),
|
||||||
|
type(type),
|
||||||
|
filePath(nullptr),
|
||||||
|
schema(nullptr),
|
||||||
|
tableName(nullptr) {};
|
||||||
|
|
||||||
|
ExportStatement::~ExportStatement() {
|
||||||
|
free(filePath);
|
||||||
|
free(schema);
|
||||||
|
free(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
// ImportStatement
|
// ImportStatement
|
||||||
ImportStatement::ImportStatement(ImportType type) :
|
ImportStatement::ImportStatement(ImportType type) :
|
||||||
SQLStatement(kStmtImport),
|
SQLStatement(kStmtImport),
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
#include "PrepareStatement.h"
|
#include "PrepareStatement.h"
|
||||||
#include "ExecuteStatement.h"
|
#include "ExecuteStatement.h"
|
||||||
#include "ShowStatement.h"
|
#include "ShowStatement.h"
|
||||||
|
#include "ExportStatement.h"
|
||||||
|
|
||||||
#endif // SQLPARSER_STATEMENTS_H
|
#endif // SQLPARSER_STATEMENTS_H
|
||||||
|
|
|
@ -196,6 +196,40 @@ namespace hsql {
|
||||||
void printImportStatementInfo(const ImportStatement* stmt, uintmax_t numIndent) {
|
void printImportStatementInfo(const ImportStatement* stmt, uintmax_t numIndent) {
|
||||||
inprint("ImportStatement", numIndent);
|
inprint("ImportStatement", numIndent);
|
||||||
inprint(stmt->filePath, numIndent + 1);
|
inprint(stmt->filePath, numIndent + 1);
|
||||||
|
switch (stmt->type) {
|
||||||
|
case ImportType::kImportCSV:
|
||||||
|
inprint("CSV", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportTbl:
|
||||||
|
inprint("TBL", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportBinary:
|
||||||
|
inprint("BINARY", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportAuto:
|
||||||
|
inprint("AUTO", numIndent + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
inprint(stmt->tableName, numIndent + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printExportStatementInfo(const ExportStatement* stmt, uintmax_t numIndent) {
|
||||||
|
inprint("ExportStatement", numIndent);
|
||||||
|
inprint(stmt->filePath, numIndent + 1);
|
||||||
|
switch (stmt->type) {
|
||||||
|
case ImportType::kImportCSV:
|
||||||
|
inprint("CSV", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportTbl:
|
||||||
|
inprint("TBL", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportBinary:
|
||||||
|
inprint("BINARY", numIndent + 1);
|
||||||
|
break;
|
||||||
|
case ImportType::kImportAuto:
|
||||||
|
inprint("AUTO", numIndent + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
inprint(stmt->tableName, numIndent + 1);
|
inprint(stmt->tableName, numIndent + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +275,9 @@ namespace hsql {
|
||||||
case kStmtImport:
|
case kStmtImport:
|
||||||
printImportStatementInfo((const ImportStatement*) stmt, 0);
|
printImportStatementInfo((const ImportStatement*) stmt, 0);
|
||||||
break;
|
break;
|
||||||
|
case kStmtExport:
|
||||||
|
printExportStatementInfo((const ExportStatement*) stmt, 0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ namespace hsql {
|
||||||
// Prints a summary of the given ImportStatement with the given indentation.
|
// Prints a summary of the given ImportStatement with the given indentation.
|
||||||
void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent);
|
void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent);
|
||||||
|
|
||||||
|
// Prints a summary of the given CopyStatement with the given indentation.
|
||||||
|
void printExportStatementInfo(const ExportStatement* stmt, uintmax_t num_indent);
|
||||||
|
|
||||||
// Prints a summary of the given InsertStatement with the given indentation.
|
// Prints a summary of the given InsertStatement with the given indentation.
|
||||||
void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent);
|
void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
!SELECT * FROM t WHERE a = ? AND b = ?;gibberish;
|
!SELECT * FROM t WHERE a = ? AND b = ?;gibberish;
|
||||||
!SHOW COLUMNS;
|
!SHOW COLUMNS;
|
||||||
!DESCRIBE;
|
!DESCRIBE;
|
||||||
|
!COPY;
|
||||||
|
!COPY students;
|
||||||
|
!COPY students FROM 'students_file' WITH FORMAT XYZ;
|
||||||
|
!COPY students TO 'students_file' WITH FORMAT XYZ;
|
||||||
!select a + 2 as b(spam, eggs) from B;
|
!select a + 2 as b(spam, eggs) from B;
|
||||||
!WITH a AS SELECT 1 SELECT 1;
|
!WITH a AS SELECT 1 SELECT 1;
|
||||||
!WITH a AS (SELECT ) SELECT 1;
|
!WITH a AS (SELECT ) SELECT 1;
|
||||||
|
|
|
@ -54,6 +54,17 @@ PREPARE prep2 FROM 'INSERT INTO test VALUES (?, 0, 0); INSERT INTO test VALUES (
|
||||||
EXECUTE prep_inst(1, 2, 3);
|
EXECUTE prep_inst(1, 2, 3);
|
||||||
EXECUTE prep;
|
EXECUTE prep;
|
||||||
DEALLOCATE PREPARE prep;
|
DEALLOCATE PREPARE prep;
|
||||||
|
# COPY
|
||||||
|
COPY students FROM 'student.tbl';
|
||||||
|
COPY students FROM 'file_path' WITH FORMAT TBL;
|
||||||
|
COPY students FROM 'file_path' WITH FORMAT CSV;
|
||||||
|
COPY students FROM 'file_path' WITH FORMAT BIN;
|
||||||
|
COPY students FROM 'file_path' WITH FORMAT BINARY;
|
||||||
|
COPY students TO 'student.tbl';
|
||||||
|
COPY students TO 'file_path' WITH FORMAT TBL;
|
||||||
|
COPY students TO 'file_path' WITH FORMAT CSV;
|
||||||
|
COPY students TO 'file_path' WITH FORMAT BIN;
|
||||||
|
COPY students TO 'file_path' WITH FORMAT BINARY;
|
||||||
# HINTS
|
# HINTS
|
||||||
SELECT * FROM test WITH HINT(NO_CACHE);
|
SELECT * FROM test WITH HINT(NO_CACHE);
|
||||||
SELECT * FROM test WITH HINT(NO_CACHE, NO_SAMPLING);
|
SELECT * FROM test WITH HINT(NO_CACHE, NO_SAMPLING);
|
||||||
|
|
|
@ -205,6 +205,45 @@ TEST(DescribeStatementTest) {
|
||||||
ASSERT_STREQ(stmt->name, "students");
|
ASSERT_STREQ(stmt->name, "students");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ImportStatementTest) {
|
||||||
|
TEST_PARSE_SINGLE_SQL(
|
||||||
|
"IMPORT FROM TBL FILE 'students_file' INTO students;",
|
||||||
|
kStmtImport,
|
||||||
|
ImportStatement,
|
||||||
|
result,
|
||||||
|
stmt);
|
||||||
|
|
||||||
|
ASSERT_EQ(stmt->type, kImportTbl);
|
||||||
|
ASSERT_NOTNULL(stmt->tableName);
|
||||||
|
ASSERT_STREQ(stmt->tableName, "students");
|
||||||
|
ASSERT_STREQ(stmt->filePath, "students_file");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CopyStatementTest) {
|
||||||
|
TEST_PARSE_SINGLE_SQL(
|
||||||
|
"COPY students FROM 'students_file' ;",
|
||||||
|
kStmtImport,
|
||||||
|
ImportStatement,
|
||||||
|
import_result,
|
||||||
|
import_stmt);
|
||||||
|
|
||||||
|
ASSERT_EQ(import_stmt->type, kImportAuto);
|
||||||
|
ASSERT_NOTNULL(import_stmt->tableName);
|
||||||
|
ASSERT_STREQ(import_stmt->tableName, "students");
|
||||||
|
ASSERT_STREQ(import_stmt->filePath, "students_file");
|
||||||
|
|
||||||
|
TEST_PARSE_SINGLE_SQL(
|
||||||
|
"COPY students TO 'students_file';",
|
||||||
|
kStmtExport,
|
||||||
|
ExportStatement,
|
||||||
|
export_result,
|
||||||
|
export_stmt);
|
||||||
|
|
||||||
|
ASSERT_EQ(export_stmt->type, kImportAuto);
|
||||||
|
ASSERT_NOTNULL(export_stmt->tableName);
|
||||||
|
ASSERT_STREQ(export_stmt->tableName, "students");
|
||||||
|
ASSERT_STREQ(export_stmt->filePath, "students_file");
|
||||||
|
}
|
||||||
|
|
||||||
SQLParserResult parse_and_move(std::string query) {
|
SQLParserResult parse_and_move(std::string query) {
|
||||||
hsql::SQLParserResult result;
|
hsql::SQLParserResult result;
|
||||||
|
|
|
@ -46,7 +46,7 @@ fi
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# Checking if the grammar is conflict free.
|
# Checking if the grammar is conflict free.
|
||||||
printf "\n${GREEN}Checking for conflicts in the grammer...${NC}\n"
|
printf "\n${GREEN}Checking for conflicts in the grammar...${NC}\n"
|
||||||
printf "${RED}"
|
printf "${RED}"
|
||||||
make -C src/parser/ test >>/dev/null
|
make -C src/parser/ test >>/dev/null
|
||||||
CONFLICT_RET=$?
|
CONFLICT_RET=$?
|
||||||
|
|
Loading…
Reference in New Issue