Skip to content

Commit

Permalink
[DYOD] Data Definition Language Project (#177)
Browse files Browse the repository at this point in the history
This pull request sums up all the work for project 1 of this term "Develop your Own Database" seminar. The project's high-level goal is to make the schema SQL of hyrise executable.
Specifically, this pull request - once finished - will include the extension of the parser to support CREATE INDEX and DROP INDEX statements, column and table key constraints, a subset of ALTER TABLE statements, and extended type parsing within column definitions.

Co-authored-by: Moritz Spranger <[email protected]>
Co-authored-by: Jostafarr <[email protected]>
Co-authored-by: mweisgut <[email protected]>
Co-authored-by: Marcel Weisgut <[email protected]>
  • Loading branch information
5 people authored Oct 12, 2021
1 parent f1afb9a commit 0de1890
Show file tree
Hide file tree
Showing 15 changed files with 4,297 additions and 3,536 deletions.
3,733 changes: 2,015 additions & 1,718 deletions src/parser/bison_parser.cpp

Large diffs are not rendered by default.

359 changes: 187 additions & 172 deletions src/parser/bison_parser.h

Large diffs are not rendered by default.

325 changes: 212 additions & 113 deletions src/parser/bison_parser.y

Large diffs are not rendered by default.

2,790 changes: 1,427 additions & 1,363 deletions src/parser/flex_lexer.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/parser/flex_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define hsql_HEADER_H 1
#define hsql_IN_HEADER 1

#line 6 "flex_lexer.h"
#line 5 "flex_lexer.h"

#line 8 "flex_lexer.h"
#line 7 "flex_lexer.h"

#define YY_INT_ALIGNED short int

Expand Down Expand Up @@ -730,9 +730,9 @@ extern int yylex \
#undef yyTABLES_NAME
#endif

#line 265 "flex_lexer.l"
#line 270 "flex_lexer.l"


#line 737 "flex_lexer.h"
#line 736 "flex_lexer.h"
#undef hsql_IN_HEADER
#endif /* hsql_HEADER_H */
313 changes: 159 additions & 154 deletions src/parser/flex_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -56,165 +56,170 @@ static thread_local std::stringstream strbuf;
***************************/
%%

-- BEGIN(COMMENT);
<COMMENT>[^\n]* /* skipping comment content until a end of line is read */;
<COMMENT>\n BEGIN(INITIAL);
-- BEGIN(COMMENT);
<COMMENT>[^\n]* /* skipping comment content until a end of line is read */;
<COMMENT>\n BEGIN(INITIAL);

[ \t\n]+ /* skip whitespace */;
[ \t\n]+ /* skip whitespace */;

DEALLOCATE TOKEN(DEALLOCATE)
PARAMETERS TOKEN(PARAMETERS)
INTERSECT TOKEN(INTERSECT)
TEMPORARY TOKEN(TEMPORARY)
TIMESTAMP TOKEN(TIMESTAMP)
DESCRIBE TOKEN(DESCRIBE)
DISTINCT TOKEN(DISTINCT)
NVARCHAR TOKEN(NVARCHAR)
RESTRICT TOKEN(RESTRICT)
TRUNCATE TOKEN(TRUNCATE)
ANALYZE TOKEN(ANALYZE)
BETWEEN TOKEN(BETWEEN)
CASCADE TOKEN(CASCADE)
COLUMNS TOKEN(COLUMNS)
CONTROL TOKEN(CONTROL)
DEFAULT TOKEN(DEFAULT)
EXECUTE TOKEN(EXECUTE)
EXPLAIN TOKEN(EXPLAIN)
INTEGER TOKEN(INTEGER)
NATURAL TOKEN(NATURAL)
PREPARE TOKEN(PREPARE)
PRIMARY TOKEN(PRIMARY)
SCHEMAS TOKEN(SCHEMAS)
SPATIAL TOKEN(SPATIAL)
VARCHAR TOKEN(VARCHAR)
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)
EXTRACT TOKEN(EXTRACT)
CAST TOKEN(CAST)
FORMAT TOKEN(FORMAT)
GLOBAL TOKEN(GLOBAL)
HAVING TOKEN(HAVING)
IMPORT TOKEN(IMPORT)
INSERT TOKEN(INSERT)
ISNULL TOKEN(ISNULL)
OFFSET TOKEN(OFFSET)
RENAME TOKEN(RENAME)
SCHEMA TOKEN(SCHEMA)
SELECT TOKEN(SELECT)
SORTED TOKEN(SORTED)
TABLES TOKEN(TABLES)
UNIQUE TOKEN(UNIQUE)
UNLOAD TOKEN(UNLOAD)
UPDATE TOKEN(UPDATE)
VALUES TOKEN(VALUES)
AFTER TOKEN(AFTER)
ALTER TOKEN(ALTER)
ARRAY TOKEN(ARRAY)
CROSS TOKEN(CROSS)
DELTA TOKEN(DELTA)
FLOAT TOKEN(FLOAT)
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)
RIGHT TOKEN(RIGHT)
TABLE TOKEN(TABLE)
UNION TOKEN(UNION)
USING TOKEN(USING)
WHERE TOKEN(WHERE)
CALL TOKEN(CALL)
CASE TOKEN(CASE)
CHAR TOKEN(CHAR)
COPY TOKEN(COPY)
DATE TOKEN(DATE)
DATETIME TOKEN(DATETIME)
DESC TOKEN(DESC)
DROP TOKEN(DROP)
ELSE TOKEN(ELSE)
FILE TOKEN(FILE)
FROM TOKEN(FROM)
FULL TOKEN(FULL)
HASH TOKEN(HASH)
HINT TOKEN(HINT)
INTO TOKEN(INTO)
JOIN TOKEN(JOIN)
LEFT TOKEN(LEFT)
LIKE TOKEN(LIKE)
ILIKE TOKEN(ILIKE)
LOAD TOKEN(LOAD)
LONG TOKEN(LONG)
NULL TOKEN(NULL)
PLAN TOKEN(PLAN)
SHOW TOKEN(SHOW)
TEXT TOKEN(TEXT)
THEN TOKEN(THEN)
TIME TOKEN(TIME)
VIEW TOKEN(VIEW)
WHEN TOKEN(WHEN)
WITH TOKEN(WITH)
ADD TOKEN(ADD)
ALL TOKEN(ALL)
AND TOKEN(AND)
ASC TOKEN(ASC)
END TOKEN(END)
FOR TOKEN(FOR)
INT TOKEN(INT)
KEY TOKEN(KEY)
NOT TOKEN(NOT)
OFF TOKEN(OFF)
SET TOKEN(SET)
TOP TOKEN(TOP)
AS TOKEN(AS)
BY TOKEN(BY)
IF TOKEN(IF)
IN TOKEN(IN)
IS TOKEN(IS)
OF TOKEN(OF)
ON TOKEN(ON)
OR TOKEN(OR)
TO TOKEN(TO)
SECOND TOKEN(SECOND)
MINUTE TOKEN(MINUTE)
HOUR TOKEN(HOUR)
DAY TOKEN(DAY)
MONTH TOKEN(MONTH)
YEAR TOKEN(YEAR)
SECONDS TOKEN(SECONDS)
MINUTES TOKEN(MINUTES)
HOURS TOKEN(HOURS)
DAYS TOKEN(DAYS)
MONTHS TOKEN(MONTHS)
YEARS TOKEN(YEARS)
TRUE TOKEN(TRUE)
FALSE TOKEN(FALSE)
DEALLOCATE TOKEN(DEALLOCATE)
PARAMETERS TOKEN(PARAMETERS)
INTERSECT TOKEN(INTERSECT)
TEMPORARY TOKEN(TEMPORARY)
TIMESTAMP TOKEN(TIMESTAMP)
DESCRIBE TOKEN(DESCRIBE)
DISTINCT TOKEN(DISTINCT)
NVARCHAR TOKEN(NVARCHAR)
RESTRICT TOKEN(RESTRICT)
TRUNCATE TOKEN(TRUNCATE)
ANALYZE TOKEN(ANALYZE)
BETWEEN TOKEN(BETWEEN)
CASCADE TOKEN(CASCADE)
COLUMNS TOKEN(COLUMNS)
CONTROL TOKEN(CONTROL)
DEFAULT TOKEN(DEFAULT)
EXECUTE TOKEN(EXECUTE)
EXPLAIN TOKEN(EXPLAIN)
INTEGER TOKEN(INTEGER)
NATURAL TOKEN(NATURAL)
PREPARE TOKEN(PREPARE)
PRIMARY TOKEN(PRIMARY)
SCHEMAS TOKEN(SCHEMAS)
SPATIAL TOKEN(SPATIAL)
VARCHAR TOKEN(VARCHAR)
CHARACTER TOKEN(CHARACTER)
VARYING TOKEN(VARYING)
TIME TOKEN(TIME)
DECIMAL TOKEN(DECIMAL)
REAL TOKEN(REAL)
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)
EXTRACT TOKEN(EXTRACT)
CAST TOKEN(CAST)
FORMAT TOKEN(FORMAT)
GLOBAL TOKEN(GLOBAL)
HAVING TOKEN(HAVING)
IMPORT TOKEN(IMPORT)
INSERT TOKEN(INSERT)
ISNULL TOKEN(ISNULL)
OFFSET TOKEN(OFFSET)
RENAME TOKEN(RENAME)
SCHEMA TOKEN(SCHEMA)
SELECT TOKEN(SELECT)
SORTED TOKEN(SORTED)
TABLES TOKEN(TABLES)
UNIQUE TOKEN(UNIQUE)
UNLOAD TOKEN(UNLOAD)
UPDATE TOKEN(UPDATE)
VALUES TOKEN(VALUES)
AFTER TOKEN(AFTER)
ALTER TOKEN(ALTER)
ARRAY TOKEN(ARRAY)
CROSS TOKEN(CROSS)
DELTA TOKEN(DELTA)
FLOAT TOKEN(FLOAT)
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)
RIGHT TOKEN(RIGHT)
TABLE TOKEN(TABLE)
UNION TOKEN(UNION)
USING TOKEN(USING)
WHERE TOKEN(WHERE)
CALL TOKEN(CALL)
CASE TOKEN(CASE)
CHAR TOKEN(CHAR)
COPY TOKEN(COPY)
DATE TOKEN(DATE)
DATETIME TOKEN(DATETIME)
DESC TOKEN(DESC)
DROP TOKEN(DROP)
ELSE TOKEN(ELSE)
FILE TOKEN(FILE)
FROM TOKEN(FROM)
FULL TOKEN(FULL)
HASH TOKEN(HASH)
HINT TOKEN(HINT)
INTO TOKEN(INTO)
JOIN TOKEN(JOIN)
LEFT TOKEN(LEFT)
LIKE TOKEN(LIKE)
ILIKE TOKEN(ILIKE)
LOAD TOKEN(LOAD)
LONG TOKEN(LONG)
NULL TOKEN(NULL)
PLAN TOKEN(PLAN)
SHOW TOKEN(SHOW)
TEXT TOKEN(TEXT)
THEN TOKEN(THEN)
TIME TOKEN(TIME)
VIEW TOKEN(VIEW)
WHEN TOKEN(WHEN)
WITH TOKEN(WITH)
ADD TOKEN(ADD)
ALL TOKEN(ALL)
AND TOKEN(AND)
ASC TOKEN(ASC)
END TOKEN(END)
FOR TOKEN(FOR)
INT TOKEN(INT)
KEY TOKEN(KEY)
NOT TOKEN(NOT)
OFF TOKEN(OFF)
SET TOKEN(SET)
TOP TOKEN(TOP)
AS TOKEN(AS)
BY TOKEN(BY)
IF TOKEN(IF)
IN TOKEN(IN)
IS TOKEN(IS)
OF TOKEN(OF)
ON TOKEN(ON)
OR TOKEN(OR)
TO TOKEN(TO)
SECOND TOKEN(SECOND)
MINUTE TOKEN(MINUTE)
HOUR TOKEN(HOUR)
DAY TOKEN(DAY)
MONTH TOKEN(MONTH)
YEAR TOKEN(YEAR)
SECONDS TOKEN(SECONDS)
MINUTES TOKEN(MINUTES)
HOURS TOKEN(HOURS)
DAYS TOKEN(DAYS)
MONTHS TOKEN(MONTHS)
YEARS TOKEN(YEARS)
TRUE TOKEN(TRUE)
FALSE TOKEN(FALSE)
TRANSACTION TOKEN(TRANSACTION)
BEGIN TOKEN(BEGIN)
ROLLBACK TOKEN(ROLLBACK)
COMMIT TOKEN(COMMIT)
INTERVAL TOKEN(INTERVAL)
BEGIN TOKEN(BEGIN)
ROLLBACK TOKEN(ROLLBACK)
COMMIT TOKEN(COMMIT)
INTERVAL TOKEN(INTERVAL)

/* Allow =/== see https://sqlite.org/lang_expr.html#collateop */
"==" TOKEN(EQUALS)
"!=" TOKEN(NOTEQUALS)
"<>" TOKEN(NOTEQUALS)
"<=" TOKEN(LESSEQ)
">=" TOKEN(GREATEREQ)
"||" TOKEN(CONCAT)
/* Allow =/== see https://sqlite.org/lang_expr.html#collateop */
"==" TOKEN(EQUALS)
"!=" TOKEN(NOTEQUALS)
"<>" TOKEN(NOTEQUALS)
"<=" TOKEN(LESSEQ)
">=" TOKEN(GREATEREQ)
"||" TOKEN(CONCAT)

[-+*/(){},.;<>=^%:?[\]|] { return yytext[0]; }
[-+*/(){},.;<>=^%:?[\]|] { return yytext[0]; }

[0-9]+"."[0-9]* |
"."[0-9]* {
Expand Down
41 changes: 41 additions & 0 deletions src/sql/AlterStatement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef SQLPARSER_ALTER_STATEMENT_H
#define SQLPARSER_ALTER_STATEMENT_H

#include "SQLStatement.h"

// Note: Implementations of constructors and destructors can be found in statements.cpp.
namespace hsql {

enum ActionType {
DropColumn,
};

struct AlterAction {
AlterAction(ActionType type);
ActionType type;
virtual ~AlterAction();
};

struct DropColumnAction : AlterAction {
DropColumnAction(char* column_name);
char* columnName;
bool ifExists;

~DropColumnAction() override;
};

// Represents SQL Alter Table statements.
// Example "ALTER TABLE students DROP COLUMN name;"
struct AlterStatement : SQLStatement {

AlterStatement(char* name, AlterAction* action);
~AlterStatement() override;

char* schema;
bool ifTableExists;
char* name;
AlterAction* action;
};
} // namespace hsql

#endif
Loading

0 comments on commit 0de1890

Please sign in to comment.