hyrise/sql-parser

What would I need to do in order to add a DATE DataType?

mgonnav opened this issue · 4 comments

I've already seen that the data types are declared in an enum inside CreateStatement.h. However, I'm not entirely sure what would I need to change in order to add a DATE DataType. I guess I have to add this new data_type to the enum in CreateStatement.h, modify statements.cpp and recompile the library. Is there anything else I have to do that I would need to know?

I just noticed that issue #140 talks about this.

Mostly, it is a question of adding the appropriate keywords to the lexer (flex_lexer.l) and then adding them as column_types to the CREATE TABLE statement.

In any case, if there is any more info that could help me implement this, please let me know. Thanks!

mrks commented

This might even be sufficient (but still lacks the other types as well as tests):

diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y
index b502c8a..c67b45e 100755
--- a/src/parser/bison_parser.y
+++ b/src/parser/bison_parser.y
@@ -561,6 +561,7 @@ column_type:
        |       VARCHAR '(' INTVAL ')' { $$ = ColumnType{DataType::VARCHAR, $3}; }
        |       CHAR '(' INTVAL ')' { $$ = ColumnType{DataType::CHAR, $3}; }
        |       TEXT { $$ = ColumnType{DataType::TEXT}; }
+       |       DATE { $$ = ColumnType{DataType::DATE}; }
        ;

 opt_column_nullable:
diff --git a/src/sql/CreateStatement.h b/src/sql/CreateStatement.h
index 01a98d0..258a96f 100755
--- a/src/sql/CreateStatement.h
+++ b/src/sql/CreateStatement.h
@@ -17,7 +17,8 @@ namespace hsql {
     DOUBLE,
     CHAR,
     VARCHAR,
-    TEXT
+    TEXT,
+    DATE
   };

   // Represents the type of a column, e.g., FLOAT or VARCHAR(10)
diff --git a/src/sql/statements.cpp b/src/sql/statements.cpp
index 104a4d1..08eb97a 100755
--- a/src/sql/statements.cpp
+++ b/src/sql/statements.cpp
@@ -54,6 +54,9 @@ namespace hsql {
       case DataType::TEXT:
         stream << "TEXT";
         break;
+      case DataType::DATE:
+        stream << "DATE";
+        break;
     }
     return stream;
   }

Thank you! It was actually that simple! I'll take a look on the tests then.
Is there any documentation on how your tests should be structured or shall I guide myself by the already written tests?

mrks commented

Glad I could help.

Unfortunately we don't have any documentation on the test structure. The easiest would be to create something like TEST(CreateStatementTest), just with date/time/datetime types.