indexes WIP
This commit is contained in:
16
usql.cpp
16
usql.cpp
@@ -4,7 +4,6 @@
|
||||
#include "ml_string.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
namespace usql {
|
||||
|
||||
@@ -24,6 +23,8 @@ std::unique_ptr<Table> USql::execute(Node &node) {
|
||||
switch (node.node_type) {
|
||||
case NodeType::create_table:
|
||||
return execute_create_table(static_cast<CreateTableNode &>(node));
|
||||
case NodeType::create_index:
|
||||
return execute_create_index(static_cast<CreateIndexNode &>(node));
|
||||
case NodeType::create_table_as_select:
|
||||
return execute_create_table_as_table(static_cast<CreateTableAsSelectNode &>(node));
|
||||
case NodeType::drop_table:
|
||||
@@ -108,7 +109,7 @@ std::unique_ptr<ValueNode> USql::eval_value_node(Table *table, Row &row, Node *n
|
||||
if (node->node_type == NodeType::database_value) {
|
||||
return eval_database_value_node(table, row, node);
|
||||
} else if (node->node_type == NodeType::int_value || node->node_type == NodeType::float_value || node->node_type == NodeType::string_value || node->node_type == NodeType::bool_value) {
|
||||
return eval_literal_value_node(table, row, node);
|
||||
return eval_literal_value_node(row, node);
|
||||
} else if (node->node_type == NodeType::function) {
|
||||
return eval_function_value_node(table, row, node, col_def_node, agg_func_value);
|
||||
} else if (node->node_type == NodeType::null_value) {
|
||||
@@ -143,7 +144,7 @@ std::unique_ptr<ValueNode> USql::eval_database_value_node(Table *table, Row &row
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<ValueNode> USql::eval_literal_value_node(Table *table, Row &row, Node *node) {
|
||||
std::unique_ptr<ValueNode> USql::eval_literal_value_node(Row &row, Node *node) {
|
||||
if (node->node_type == NodeType::int_value) {
|
||||
auto *ivl = static_cast<IntValueNode *>(node);
|
||||
return std::make_unique<IntValueNode>(ivl->value);
|
||||
@@ -344,7 +345,7 @@ std::unique_ptr<ValueNode> USql::pp_function(const std::vector<std::unique_ptr<V
|
||||
return std::make_unique<StringValueNode>(parsed_value->getStringValue().substr(0, 10));
|
||||
// TODO introduce constant for 10
|
||||
std::string s {buf};
|
||||
return std::make_unique<StringValueNode>(string_padd(s.erase(s.find_last_not_of(" ")+1), 10, ' ', false));
|
||||
return std::make_unique<StringValueNode>(string_padd(s.erase(s.find_last_not_of(' ')+1), 10, ' ', false));
|
||||
}
|
||||
return std::make_unique<StringValueNode>(parsed_value->getStringValue());
|
||||
}
|
||||
@@ -411,17 +412,17 @@ USql::min_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars,
|
||||
throw Exception("unsupported data type for min function");
|
||||
}
|
||||
|
||||
Table *USql::find_table(const std::string &name) {
|
||||
Table *USql::find_table(const std::string &name) const {
|
||||
auto name_cmp = [name](const Table& t) { return t.m_name == name; };
|
||||
auto table_def = std::find_if(begin(m_tables), end(m_tables), name_cmp);
|
||||
if (table_def != std::end(m_tables)) {
|
||||
return table_def.operator->();
|
||||
return const_cast<Table *>(table_def.operator->());
|
||||
} else {
|
||||
throw Exception("table not found (" + name + ")");
|
||||
}
|
||||
}
|
||||
|
||||
void USql::check_table_not_exists(const std::string &name) {
|
||||
void USql::check_table_not_exists(const std::string &name) const {
|
||||
auto name_cmp = [name](const Table& t) { return t.m_name == name; };
|
||||
auto table_def = std::find_if(begin(m_tables), end(m_tables), name_cmp);
|
||||
if (table_def != std::end(m_tables)) {
|
||||
@@ -429,5 +430,4 @@ void USql::check_table_not_exists(const std::string &name) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user