From 789a4a5b9b2ac9864ded8776ebe278bcadbd21da Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 26 Nov 2014 12:19:33 +0100 Subject: [PATCH] added class and keywords for updates --- frontend-hyrise/sample-queries.sql | 4 ++- src/lib/Statement.h | 1 + src/lib/UpdateStatement.h | 30 +++++++++++++++++++++++ src/lib/sqllib.h | 4 ++- src/parser/bison_parser.y | 24 +++++++++--------- src/parser/flex_lexer.l | 16 ++++++++++++ src/parser/keywordlist_generator.py | 2 -- src/parser/sql_keywords.txt | 38 +++++++++++++++++++++++------ 8 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 src/lib/UpdateStatement.h diff --git a/frontend-hyrise/sample-queries.sql b/frontend-hyrise/sample-queries.sql index 06a7a5b..9242b7e 100644 --- a/frontend-hyrise/sample-queries.sql +++ b/frontend-hyrise/sample-queries.sql @@ -12,4 +12,6 @@ SELECT city, AVG(grade) AS average|, MIN(grade) AS best, MAX(grade) AS worst FRO # UNION SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7; # JOIN -SELECT * FROM companies JOIN employees ON company_id = employee_company_id; \ No newline at end of file +SELECT * FROM companies JOIN employees ON company_id = employee_company_id; +# INSERT +INSERT INTO students VALUES ('Max', 10101, 'Musterhausen', 3.3); \ No newline at end of file diff --git a/src/lib/Statement.h b/src/lib/Statement.h index fbeddbe..53494ad 100644 --- a/src/lib/Statement.h +++ b/src/lib/Statement.h @@ -15,6 +15,7 @@ typedef enum { kStmtSelect, kStmtImport, kStmtInsert, + kStmtUpdate, // Following types are planned but not supported yet kStmtDelete, kStmtCreate, diff --git a/src/lib/UpdateStatement.h b/src/lib/UpdateStatement.h new file mode 100644 index 0000000..3430610 --- /dev/null +++ b/src/lib/UpdateStatement.h @@ -0,0 +1,30 @@ +#ifndef __UPDATE_STATEMENT_H__ +#define __UPDATE_STATEMENT_H__ + +#include "Statement.h" + +namespace hsql { + +struct UpdateClause { + char* column; + Expr* value; +}; + +struct UpdateStatement : Statement { + UpdateStatement() : + Statement(kStmtUpdate), + table(NULL), + updates(NULL), + where(NULL) {} + + virtual ~UpdateStatement(); // defined in destructors.cpp + + TableRef* table; + List updates; + Expr* where; +}; + + + +} // namsepace hsql +#endif \ No newline at end of file diff --git a/src/lib/sqllib.h b/src/lib/sqllib.h index 631f5d1..6a9d716 100644 --- a/src/lib/sqllib.h +++ b/src/lib/sqllib.h @@ -1,10 +1,12 @@ - #ifndef __SQLLIB_H__ #define __SQLLIB_H__ + #include "SelectStatement.h" #include "ImportStatement.h" #include "CreateStatement.h" #include "InsertStatement.h" +#include "UpdateStatement.h" + #endif \ No newline at end of file diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 5eca96b..8a966e0 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -107,17 +107,19 @@ typedef void* yyscan_t; %token NOTEQUALS LESSEQ GREATEREQ /* SQL Keywords */ -%token INTERSECT TEMPORARY DISTINCT RESTRICT TRUNCATE -%token ANALYZE BETWEEN CASCADE COLUMNS CONTROL DEFAULT -%token EXPLAIN HISTORY NATURAL PRIMARY SCHEMAS SPATIAL -%token BEFORE COLUMN CREATE DELETE DIRECT ESCAPE EXCEPT -%token EXISTS GLOBAL HAVING IMPORT INSERT ISNULL OFFSET -%token RENAME SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD -%token UPDATE VALUES AFTER ALTER CROSS GROUP INDEX INNER -%token LIMIT LOCAL MINUS ORDER OUTER RIGHT TABLE UNION USING -%token WHERE CALL DESC DROP FILE FROM FULL HASH INTO JOIN -%token LEFT LIKE LOAD NULL PLAN SHOW WITH ADD ALL AND ASC -%token CSV FOR KEY NOT SET TBL TOP AS BY IF IN IS ON OR TO +%token PARAMETERS INTERSECT TEMPORARY TIMESTAMP DISTINCT +%token NVARCHAR RESTRICT TRUNCATE ANALYZE BETWEEN CASCADE +%token COLUMNS CONTROL DEFAULT EXPLAIN HISTORY INTEGER +%token NATURAL PRIMARY SCHEMAS SPATIAL VIRTUAL BEFORE COLUMN +%token CREATE DELETE DIRECT DOUBLE ESCAPE EXCEPT EXISTS +%token GLOBAL HAVING IMPORT INSERT ISNULL OFFSET RENAME +%token SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD UPDATE +%token VALUES AFTER ALTER CROSS DELTA GROUP INDEX INNER +%token LIMIT LOCAL MERGE MINUS ORDER OUTER RIGHT TABLE UNION +%token USING WHERE CALL DATE DESC DROP FILE FROM FULL HASH +%token INTO JOIN LEFT LIKE LOAD NULL PART PLAN SHOW TEXT +%token TIME VIEW WITH ADD ALL AND ASC CSV FOR KEY NOT OFF +%token SET TBL TOP AS BY IF IN IS OF ON OR TO /********************************* diff --git a/src/parser/flex_lexer.l b/src/parser/flex_lexer.l index f29dcd5..d35ae94 100644 --- a/src/parser/flex_lexer.l +++ b/src/parser/flex_lexer.l @@ -57,9 +57,13 @@ [ \t\n]+ /* skip whitespace */; + +PARAMETERS TOKEN(PARAMETERS) INTERSECT TOKEN(INTERSECT) TEMPORARY TOKEN(TEMPORARY) +TIMESTAMP TOKEN(TIMESTAMP) DISTINCT TOKEN(DISTINCT) +NVARCHAR TOKEN(NVARCHAR) RESTRICT TOKEN(RESTRICT) TRUNCATE TOKEN(TRUNCATE) ANALYZE TOKEN(ANALYZE) @@ -70,15 +74,18 @@ CONTROL TOKEN(CONTROL) DEFAULT TOKEN(DEFAULT) EXPLAIN TOKEN(EXPLAIN) HISTORY TOKEN(HISTORY) +INTEGER TOKEN(INTEGER) NATURAL TOKEN(NATURAL) PRIMARY TOKEN(PRIMARY) SCHEMAS TOKEN(SCHEMAS) SPATIAL TOKEN(SPATIAL) +VIRTUAL TOKEN(VIRTUAL) BEFORE TOKEN(BEFORE) COLUMN TOKEN(COLUMN) CREATE TOKEN(CREATE) DELETE TOKEN(DELETE) DIRECT TOKEN(DIRECT) +DOUBLE TOKEN(DOUBLE) ESCAPE TOKEN(ESCAPE) EXCEPT TOKEN(EXCEPT) EXISTS TOKEN(EXISTS) @@ -100,11 +107,13 @@ VALUES TOKEN(VALUES) AFTER TOKEN(AFTER) ALTER TOKEN(ALTER) CROSS TOKEN(CROSS) +DELTA TOKEN(DELTA) GROUP TOKEN(GROUP) INDEX TOKEN(INDEX) INNER TOKEN(INNER) LIMIT TOKEN(LIMIT) LOCAL TOKEN(LOCAL) +MERGE TOKEN(MERGE) MINUS TOKEN(MINUS) ORDER TOKEN(ORDER) OUTER TOKEN(OUTER) @@ -114,6 +123,7 @@ UNION TOKEN(UNION) USING TOKEN(USING) WHERE TOKEN(WHERE) CALL TOKEN(CALL) +DATE TOKEN(DATE) DESC TOKEN(DESC) DROP TOKEN(DROP) FILE TOKEN(FILE) @@ -126,8 +136,12 @@ LEFT TOKEN(LEFT) LIKE TOKEN(LIKE) LOAD TOKEN(LOAD) NULL TOKEN(NULL) +PART TOKEN(PART) PLAN TOKEN(PLAN) SHOW TOKEN(SHOW) +TEXT TOKEN(TEXT) +TIME TOKEN(TIME) +VIEW TOKEN(VIEW) WITH TOKEN(WITH) ADD TOKEN(ADD) ALL TOKEN(ALL) @@ -137,6 +151,7 @@ CSV TOKEN(CSV) FOR TOKEN(FOR) KEY TOKEN(KEY) NOT TOKEN(NOT) +OFF TOKEN(OFF) SET TOKEN(SET) TBL TOKEN(TBL) TOP TOKEN(TOP) @@ -145,6 +160,7 @@ BY TOKEN(BY) IF TOKEN(IF) IN TOKEN(IN) IS TOKEN(IS) +OF TOKEN(OF) ON TOKEN(ON) OR TOKEN(OR) TO TOKEN(TO) diff --git a/src/parser/keywordlist_generator.py b/src/parser/keywordlist_generator.py index 19ce253..ae4c0f0 100644 --- a/src/parser/keywordlist_generator.py +++ b/src/parser/keywordlist_generator.py @@ -29,8 +29,6 @@ with open("sql_keywords.txt", 'r') as fh: ################# # Bison - - line = "%token" max_len = 60 diff --git a/src/parser/sql_keywords.txt b/src/parser/sql_keywords.txt index dc059df..81481e5 100644 --- a/src/parser/sql_keywords.txt +++ b/src/parser/sql_keywords.txt @@ -39,14 +39,15 @@ CREATE TABLE SCHEMA INDEX +VIEW IF NOT EXISTS GLOBAL LOCAL TEMPORARY -WITH UNIQUE +VIRTUAL INDEX UNIQUE @@ -72,7 +73,6 @@ AFTER // Data Manipulation INSERT VALUES -SET DIRECT SORTED @@ -83,22 +83,30 @@ TBL CONTROL UPDATE +SET DELETE HISTORY TRUNCATE +MERGE +HISTORY +DELTA +OF +PART +LOAD +UNLOAD + +DELETE + +/////////////////////////////// // other statements RENAME -TO -DELETE EXPLAIN PLAN ANALYZE -LOAD -UNLOAD SHOW SCHEMAS @@ -113,6 +121,7 @@ SET DEFAULT CALL FOR +TO // Expressions @@ -125,4 +134,19 @@ IN IS ISNULL BETWEEN -ESCAPE \ No newline at end of file +ESCAPE + +// With +WITH +PARAMETERS +ON +OFF + +// Data types +DATE +TIME +TIMESTAMP +INTEGER +DOUBLE +NVARCHAR +TEXT