indexes WIP
This commit is contained in:
30
usql_ddl.cpp
30
usql_ddl.cpp
@@ -9,7 +9,7 @@ namespace usql {
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_table(CreateTableNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_create_table(const CreateTableNode &node) {
|
||||
check_table_not_exists(node.table_name);
|
||||
|
||||
Table table{node.table_name, node.cols_defs};
|
||||
@@ -19,21 +19,23 @@ std::unique_ptr<Table> USql::execute_create_table(CreateTableNode &node) {
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_index(CreateIndexNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_create_index(const CreateIndexNode &node) {
|
||||
Table *table_def = find_table(node.table_name); // throws exception if not found
|
||||
ColDefNode col_def = table_def->get_column_def(node.column_name); // throws exception if not found
|
||||
|
||||
if (table_def->get_index(node.index_name) != nullptr) throw Exception("index already exists");
|
||||
check_index_not_exists(node.index_name);
|
||||
if (col_def.null) throw Exception("index on not null supported only");
|
||||
if (table_def->get_index_for_column(node.column_name) != nullptr) throw Exception("column is already indexed");
|
||||
|
||||
IndexedDataType type;
|
||||
if (col_def.type == ColumnType::integer_type) type = IndexedDataType::integer;
|
||||
else if (col_def.type == ColumnType::varchar_type) type = IndexedDataType::string;
|
||||
else throw Exception("creating index on unsupported type");
|
||||
if (col_def.type == ColumnType::integer_type)
|
||||
type = IndexedDataType::integer;
|
||||
else if (col_def.type == ColumnType::varchar_type)
|
||||
type = IndexedDataType::string;
|
||||
else
|
||||
throw Exception("creating index on unsupported type");
|
||||
|
||||
Index<IndexValue> i{node.index_name, node.column_name, type};
|
||||
table_def->create_index(i);
|
||||
table_def->create_index({node.index_name, node.column_name, type});
|
||||
|
||||
table_def->index_rows(node.index_name);
|
||||
|
||||
@@ -41,7 +43,7 @@ std::unique_ptr<Table> USql::execute_create_index(CreateIndexNode &node) {
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_table_as_table(CreateTableAsSelectNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_create_table_as_table(const CreateTableAsSelectNode &node) {
|
||||
check_table_not_exists(node.table_name);
|
||||
|
||||
auto select = execute_select((SelectFromTableNode &) *node.select_table);
|
||||
@@ -64,7 +66,7 @@ std::unique_ptr<Table> USql::execute_create_table_as_table(CreateTableAsSelectNo
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_drop(DropTableNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_drop(const DropTableNode &node) {
|
||||
auto name_cmp = [node](const Table& t) { return t.m_name == node.table_name; };
|
||||
|
||||
auto table_def = std::find_if(begin(m_tables), end(m_tables), name_cmp);
|
||||
@@ -76,12 +78,12 @@ std::unique_ptr<Table> USql::execute_drop(DropTableNode &node) {
|
||||
throw Exception("table not found (" + node.table_name + ")");
|
||||
}
|
||||
|
||||
std::unique_ptr<Table> USql::execute_set(SetNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_set(const SetNode &node) {
|
||||
Settings::set_setting(node.name, node.value);
|
||||
return create_stmt_result_table(0, "set succeeded", 1);
|
||||
}
|
||||
|
||||
std::unique_ptr<Table> USql::execute_show(ShowNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_show(const ShowNode &node) {
|
||||
std::string value = Settings::get_setting(node.name);
|
||||
return create_stmt_result_table(0, "show succeeded: " + value, 1);
|
||||
}
|
||||
@@ -106,7 +108,7 @@ std::unique_ptr<Table> USql::create_stmt_result_table(long code, const std::stri
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_load(LoadIntoTableNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_load(const LoadIntoTableNode &node) {
|
||||
// find source table
|
||||
Table *table_def = find_table(node.table_name);
|
||||
|
||||
@@ -122,7 +124,7 @@ std::unique_ptr<Table> USql::execute_load(LoadIntoTableNode &node) {
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_save(SaveTableNode &node) {
|
||||
std::unique_ptr<Table> USql::execute_save(const SaveTableNode &node) {
|
||||
// find source table
|
||||
Table *table_def = find_table(node.table_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user