changed import tbl to create tbl syntax
This commit is contained in:
parent
c6ae1c8427
commit
8d7d7b65ff
|
@ -15,15 +15,16 @@ echo "\n\n"
|
|||
./bin/grammar_test "(SELECT a FROM foo WHERE a > 12 OR b > 3 AND c NOT LIKE 's%' LIMIT 10);"
|
||||
./bin/grammar_test "SELECT t1.a, t1.b, t2.c FROM \"table\" AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5"
|
||||
|
||||
./bin/grammar_test "IMPORT FROM TBL FILE 'students.tbl' INTO \"table\""
|
||||
./bin/grammar_test "CREATE TABLE \"table\" FROM TBL FILE 'students.tbl'"
|
||||
|
||||
# Error: Where clause in between join statement
|
||||
./bin/grammar_test -f "SELECT * from \"table\" WHERE (b OR NOT a) AND a = 12.5 AS t1 JOIN table2 ON a = b"
|
||||
./bin/grammar_test -f "SELECT * \"table\" WHERE (b OR NOT a) AND a = 12.5 AS t1 JOIN table2 ON a = b"
|
||||
# ./bin/grammar_test -f "SELECT * from \"table\" WHERE (b OR NOT a) AND a = 12.5 AS t1 JOIN table2 ON a = b"
|
||||
# ./bin/grammar_test -f "SELECT * \"table\" WHERE (b OR NOT a) AND a = 12.5 AS t1 JOIN table2 ON a = b"
|
||||
|
||||
echo "\n\n"
|
||||
|
||||
./bin/analysis "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3"
|
||||
# ./bin/analysis "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3"
|
||||
# ./bin/analysis "SELECT \"AVG(grade)\" FROM (SELECT AVG(grade) FROM students GROUP BY city) t1"
|
||||
# ./bin/analysis "SELECT col1, col2, 'test' FROM tbl t1, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1 ORDER BY col2 DESC LIMIT 100;"
|
||||
# ./bin/analysis "SELECT * from tbl AS t1 JOIN table2 AS t2 ON t1.a = t2.b WHERE (b OR NOT a) AND a = 12.5"
|
||||
# ./bin/analysis "SELECT t1.a, t1.b, t2.c FROM tbl AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5"
|
||||
|
@ -33,5 +34,6 @@ echo "\n\n"
|
|||
# ./bin/analysis "
|
||||
# IMPORT FROM TBL FILE 'students.tbl' INTO tbl;
|
||||
# SELECT * FROM tbl;"
|
||||
./bin/analysis "CREATE TABLE \"table\" FROM TBL FILE 'students.tbl'"
|
||||
|
||||
echo "\n\n"
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef __CREATE_STATEMENT_H__
|
||||
#define __CREATE_STATEMENT_H__
|
||||
|
||||
#include "Statement.h"
|
||||
|
||||
namespace hsql {
|
||||
|
||||
|
||||
typedef enum {
|
||||
kTable,
|
||||
kTableFromTbl, // Hyrise file format
|
||||
// HANA supports a second file type CONTROL FILE
|
||||
// we don't need that so far, but we leave the option
|
||||
// to expand it here
|
||||
} CreateType;
|
||||
|
||||
|
||||
/**
|
||||
* @struct CreateStatement
|
||||
*/
|
||||
struct CreateStatement : Statement {
|
||||
CreateStatement() : Statement(kStmtCreate) {};
|
||||
virtual ~CreateStatement(); // defined in destructors.cpp
|
||||
|
||||
CreateType create_type;
|
||||
const char* file_path;
|
||||
const char* table_name;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace hsql
|
||||
|
||||
|
||||
#endif
|
|
@ -40,4 +40,9 @@ ImportStatement::~ImportStatement() {
|
|||
delete table_name;
|
||||
}
|
||||
|
||||
CreateStatement::~CreateStatement() {
|
||||
delete file_path;
|
||||
delete table_name;
|
||||
}
|
||||
|
||||
} // namespace hsql
|
|
@ -65,7 +65,7 @@ void printExpression(Expr* expr, uint num_indent) {
|
|||
case kExprLiteralFloat: inprint(expr->fval, num_indent); break;
|
||||
case kExprLiteralInt: inprint(expr->ival, num_indent); break;
|
||||
case kExprLiteralString: inprint(expr->name, num_indent); break;
|
||||
case kExprFunctionRef: /* todo */ break;
|
||||
case kExprFunctionRef: inprint(expr->name, num_indent); inprint(expr->expr->name, num_indent+1); break;
|
||||
case kExprOperator: printOperatorExpression(expr, num_indent); break;
|
||||
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); break;
|
||||
}
|
||||
|
@ -105,5 +105,11 @@ void printImportStatementInfo(ImportStatement* stmt, uint num_indent) {
|
|||
inprint(stmt->table_name, num_indent+1);
|
||||
}
|
||||
|
||||
void printCreateStatementInfo(CreateStatement* stmt, uint num_indent) {
|
||||
inprint("CreateStatment", num_indent);
|
||||
inprint(stmt->table_name, num_indent+1);
|
||||
inprint(stmt->file_path, num_indent+1);
|
||||
}
|
||||
|
||||
|
||||
} // namespace hsql
|
|
@ -9,6 +9,7 @@ namespace hsql {
|
|||
|
||||
void printSelectStatementInfo(SelectStatement* stmt, uint num_indent);
|
||||
void printImportStatementInfo(ImportStatement* stmt, uint num_indent);
|
||||
void printCreateStatementInfo(CreateStatement* stmt, uint num_indent);
|
||||
|
||||
} // namespace hsql
|
||||
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
|
||||
#include "SelectStatement.h"
|
||||
#include "ImportStatement.h"
|
||||
#include "CreateStatement.h"
|
||||
|
||||
#endif
|
|
@ -80,6 +80,7 @@ typedef void* yyscan_t;
|
|||
hsql::Statement* statement;
|
||||
hsql::SelectStatement* select_stmt;
|
||||
hsql::ImportStatement* import_stmt;
|
||||
hsql::CreateStatement* create_stmt;
|
||||
|
||||
hsql::TableRef* table;
|
||||
hsql::Expr* expr;
|
||||
|
@ -119,6 +120,7 @@ typedef void* yyscan_t;
|
|||
%type <statement> statement
|
||||
%type <select_stmt> select_statement
|
||||
%type <import_stmt> import_statement
|
||||
%type <create_stmt> create_statement
|
||||
%type <sval> table_name opt_alias alias file_path
|
||||
%type <table> from_clause table_ref table_ref_atomic table_ref_name
|
||||
%type <table> join_clause join_table
|
||||
|
@ -180,6 +182,7 @@ statement_list:
|
|||
statement:
|
||||
select_statement { $$ = $1; }
|
||||
| import_statement { $$ = $1; }
|
||||
| create_statement { $$ = $1; }
|
||||
;
|
||||
|
||||
|
||||
|
@ -198,7 +201,6 @@ import_statement:
|
|||
|
||||
import_file_type:
|
||||
CSV { $$ = kImportCSV; }
|
||||
| TBL { $$ = kImportTbl; }
|
||||
;
|
||||
|
||||
file_path:
|
||||
|
@ -206,6 +208,19 @@ file_path:
|
|||
;
|
||||
|
||||
|
||||
/******************************
|
||||
** Create Statement
|
||||
******************************/
|
||||
create_statement:
|
||||
CREATE TABLE table_name FROM TBL FILE file_path {
|
||||
$$ = new CreateStatement();
|
||||
$$->create_type = kTableFromTbl;
|
||||
$$->file_path = $7;
|
||||
$$->table_name = $3;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/******************************
|
||||
** Select Statement
|
||||
******************************/
|
||||
|
|
|
@ -128,7 +128,7 @@ IS TOKEN(IS)
|
|||
return SQL_INT;
|
||||
}
|
||||
|
||||
\"[A-Za-z][A-Za-z0-9_]*\" {
|
||||
\"[^\"\n]+\" {
|
||||
// Crop the leading and trailing quote char
|
||||
yylval->sval = hsql::substr(yytext, 1, strlen(yytext)-1);
|
||||
return SQL_NAME;
|
||||
|
|
|
@ -27,12 +27,9 @@ int main(int argc, char *argv[]) {
|
|||
for (Statement* stmt : stmt_list->vector()) {
|
||||
printf("Statement %d:\n", i++);
|
||||
switch (stmt->type) {
|
||||
case kStmtSelect:
|
||||
printSelectStatementInfo((SelectStatement*) stmt, 1);
|
||||
break;
|
||||
case kStmtImport:
|
||||
printImportStatementInfo((ImportStatement*) stmt, 1);
|
||||
break;
|
||||
case kStmtSelect: printSelectStatementInfo((SelectStatement*) stmt, 1); break;
|
||||
case kStmtImport: printImportStatementInfo((ImportStatement*) stmt, 1); break;
|
||||
case kStmtCreate: printCreateStatementInfo((CreateStatement*) stmt, 1); break;
|
||||
default:
|
||||
fprintf(stderr, "\tStatement Type %u. No detailed print method available.\n", stmt->type);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue