Implement CREATE VIEW and DROP VIEW
This commit is contained in:
parent
96f8b04359
commit
39d0dbd9af
|
@ -343,6 +343,13 @@ create_statement:
|
||||||
$$->tableName = $4;
|
$$->tableName = $4;
|
||||||
$$->columns = $6;
|
$$->columns = $6;
|
||||||
}
|
}
|
||||||
|
| CREATE VIEW opt_not_exists table_name opt_column_list AS select_statement {
|
||||||
|
$$ = new CreateStatement(CreateStatement::kView);
|
||||||
|
$$->ifNotExists = $3;
|
||||||
|
$$->tableName = $4;
|
||||||
|
$$->viewColumns = $5;
|
||||||
|
$$->select = $7;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
opt_not_exists:
|
opt_not_exists:
|
||||||
|
@ -380,6 +387,10 @@ drop_statement:
|
||||||
$$ = new DropStatement(DropStatement::kTable);
|
$$ = new DropStatement(DropStatement::kTable);
|
||||||
$$->name = $3;
|
$$->name = $3;
|
||||||
}
|
}
|
||||||
|
| DROP VIEW table_name {
|
||||||
|
$$ = new DropStatement(DropStatement::kView);
|
||||||
|
$$->name = $3;
|
||||||
|
}
|
||||||
| DEALLOCATE PREPARE IDENTIFIER {
|
| DEALLOCATE PREPARE IDENTIFIER {
|
||||||
$$ = new DropStatement(DropStatement::kPreparedStatement);
|
$$ = new DropStatement(DropStatement::kPreparedStatement);
|
||||||
$$->name = $3;
|
$$->name = $3;
|
||||||
|
|
|
@ -5,9 +5,12 @@
|
||||||
|
|
||||||
// Note: Implementations of constructors and destructors can be found in statements.cpp.
|
// Note: Implementations of constructors and destructors can be found in statements.cpp.
|
||||||
namespace hsql {
|
namespace hsql {
|
||||||
|
struct SelectStatement;
|
||||||
|
|
||||||
// Represents definition of a table column
|
// Represents definition of a table column
|
||||||
struct ColumnDefinition {
|
struct ColumnDefinition {
|
||||||
enum DataType {
|
enum DataType {
|
||||||
|
UNKNOWN,
|
||||||
TEXT,
|
TEXT,
|
||||||
INT,
|
INT,
|
||||||
DOUBLE
|
DOUBLE
|
||||||
|
@ -26,7 +29,8 @@ namespace hsql {
|
||||||
struct CreateStatement : SQLStatement {
|
struct CreateStatement : SQLStatement {
|
||||||
enum CreateType {
|
enum CreateType {
|
||||||
kTable,
|
kTable,
|
||||||
kTableFromTbl // Hyrise file format
|
kTableFromTbl, // Hyrise file format
|
||||||
|
kView
|
||||||
};
|
};
|
||||||
|
|
||||||
CreateStatement(CreateType type);
|
CreateStatement(CreateType type);
|
||||||
|
@ -37,6 +41,8 @@ namespace hsql {
|
||||||
char* filePath; // default: NULL
|
char* filePath; // default: NULL
|
||||||
char* tableName; // default: NULL
|
char* tableName; // default: NULL
|
||||||
std::vector<ColumnDefinition*>* columns; // default: NULL
|
std::vector<ColumnDefinition*>* columns; // default: NULL
|
||||||
|
std::vector<char*>* viewColumns;
|
||||||
|
SelectStatement* select;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace hsql
|
} // namespace hsql
|
||||||
|
|
|
@ -29,11 +29,14 @@ namespace hsql {
|
||||||
ifNotExists(false),
|
ifNotExists(false),
|
||||||
filePath(NULL),
|
filePath(NULL),
|
||||||
tableName(NULL),
|
tableName(NULL),
|
||||||
columns(NULL) {};
|
columns(NULL),
|
||||||
|
viewColumns(NULL),
|
||||||
|
select(NULL) {};
|
||||||
|
|
||||||
CreateStatement::~CreateStatement() {
|
CreateStatement::~CreateStatement() {
|
||||||
free(filePath);
|
free(filePath);
|
||||||
free(tableName);
|
free(tableName);
|
||||||
|
delete select;
|
||||||
|
|
||||||
if (columns != NULL) {
|
if (columns != NULL) {
|
||||||
for (ColumnDefinition* def : *columns) {
|
for (ColumnDefinition* def : *columns) {
|
||||||
|
@ -41,6 +44,13 @@ namespace hsql {
|
||||||
}
|
}
|
||||||
delete columns;
|
delete columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (viewColumns != NULL) {
|
||||||
|
for (char* column : *viewColumns) {
|
||||||
|
free(column);
|
||||||
|
}
|
||||||
|
delete viewColumns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteStatement
|
// DeleteStatement
|
||||||
|
|
|
@ -42,10 +42,10 @@ WHERE L_PARTKEY = P_PARTKEY AND L_SHIPDATE >= '1995-09-01' AND L_SHIPDATE < date
|
||||||
|
|
||||||
|
|
||||||
-- TPC_H Query 15.1 - Create View for Top Supplier Query
|
-- TPC_H Query 15.1 - Create View for Top Supplier Query
|
||||||
-- CREATE VIEW REVENUE0 (SUPPLIER_NO, TOTAL_REVENUE) AS
|
CREATE VIEW REVENUE0 (SUPPLIER_NO, TOTAL_REVENUE) AS
|
||||||
-- SELECT L_SUPPKEY, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) FROM LINEITEM
|
SELECT L_SUPPKEY, SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) FROM LINEITEM
|
||||||
-- WHERE L_SHIPDATE >= '1996-01-01' AND L_SHIPDATE < dateadd(mm, 3, cast('1996-01-01' as datetime))
|
WHERE L_SHIPDATE >= '1996-01-01' AND L_SHIPDATE < dateadd(mm, 3, cast('1996-01-01' as datetime))
|
||||||
-- GROUP BY L_SUPPKEY;
|
GROUP BY L_SUPPKEY;
|
||||||
|
|
||||||
|
|
||||||
-- TPC_H Query 15.2 - Top Supplier
|
-- TPC_H Query 15.2 - Top Supplier
|
||||||
|
@ -55,5 +55,4 @@ WHERE S_SUPPKEY = SUPPLIER_NO AND TOTAL_REVENUE = (SELECT MAX(TOTAL_REVENUE) FRO
|
||||||
ORDER BY S_SUPPKEY;
|
ORDER BY S_SUPPKEY;
|
||||||
|
|
||||||
-- TPC_H Query 15.3 - Drop View
|
-- TPC_H Query 15.3 - Drop View
|
||||||
-- DROP VIEW REVENUE0;
|
DROP VIEW REVENUE0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue