refactorings
This commit is contained in:
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@@ -10,13 +10,12 @@
|
|||||||
},
|
},
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**",
|
"${workspaceFolder}/**",
|
||||||
"${workspaceFolder}/stdlib",
|
|
||||||
"/usr/local/opt/openssl/include",
|
"/usr/local/opt/openssl/include",
|
||||||
"${workspaceFolder}"
|
"${workspaceFolder}"
|
||||||
],
|
],
|
||||||
"defines": [],
|
"defines": [],
|
||||||
"macFrameworkPath": [
|
"macFrameworkPath": [
|
||||||
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
|
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
|
||||||
],
|
],
|
||||||
"compilerPath": "/usr/bin/clang",
|
"compilerPath": "/usr/bin/clang",
|
||||||
"cStandard": "c11",
|
"cStandard": "c11",
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
### WIP
|
||||||
|
compare in row.cpp shoud take into account m_visible
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
- create local_install.sh
|
- create local_install.sh
|
||||||
|
|
||||||
@@ -14,7 +17,6 @@
|
|||||||
- add drop m_index
|
- add drop m_index
|
||||||
- support for joining
|
- support for joining
|
||||||
|
|
||||||
- use string_to_double and string_to_long (from Table) everywhere
|
|
||||||
- add const wherever should be
|
- add const wherever should be
|
||||||
- use static methods where posible
|
- use static methods where posible
|
||||||
- use references where pointer cannot be nullptr
|
- use references where pointer cannot be nullptr
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -117,7 +117,7 @@ void repl() {
|
|||||||
result->print();
|
result->print();
|
||||||
|
|
||||||
code += input + "\n";
|
code += input + "\n";
|
||||||
} catch (std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ std::vector<std::pair<std::string, std::string>> Settings::m_settings =
|
|||||||
long Settings::string_to_long(const std::string &intstr) {
|
long Settings::string_to_long(const std::string &intstr) {
|
||||||
try {
|
try {
|
||||||
return std::stol(intstr);
|
return std::stol(intstr);
|
||||||
} catch (std::invalid_argument &e) {
|
} catch (const std::invalid_argument &e) {
|
||||||
throw Exception("error parsing as integer: " + intstr);
|
throw Exception("error parsing as integer: " + intstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
table.cpp
23
table.cpp
@@ -183,7 +183,7 @@ void Table::commit_row(Row &row) {
|
|||||||
try {
|
try {
|
||||||
validate_row(row);
|
validate_row(row);
|
||||||
index_row(row);
|
index_row(row);
|
||||||
} catch (Exception &e) {
|
} catch (const Exception &e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,9 +250,9 @@ void Table::create_index(const Index& index) {
|
|||||||
|
|
||||||
bool Table::drop_index(const std::string &index_name) {
|
bool Table::drop_index(const std::string &index_name) {
|
||||||
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
||||||
[&index_name](const Index &idx) {
|
[&index_name](const Index &idx) {
|
||||||
return idx.get_index_name() == index_name;
|
return idx.get_index_name() == index_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it != m_indexes.end()) {
|
if (it != m_indexes.end()) {
|
||||||
m_indexes.erase(it);
|
m_indexes.erase(it);
|
||||||
@@ -317,24 +317,25 @@ void Table::index_rows(const std::string &index_name) {
|
|||||||
|
|
||||||
Index * Table::get_index(const std::string &index_name) {
|
Index * Table::get_index(const std::string &index_name) {
|
||||||
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
||||||
[&index_name](const Index &idx) {
|
[&index_name](const Index &idx) {
|
||||||
return idx.get_index_name() == index_name;
|
return idx.get_index_name() == index_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Index * Table::get_index_for_column(const std::string &col_name) {
|
Index * Table::get_index_for_column(const std::string &col_name) {
|
||||||
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
auto it = std::find_if(m_indexes.begin(), m_indexes.end(),
|
||||||
[&col_name](const Index &idx) {
|
[&col_name](const Index &idx) {
|
||||||
return idx.get_column_name() == col_name;
|
return idx.get_column_name() == col_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Table::empty() {
|
bool Table::empty() const {
|
||||||
if (m_rows.empty()) return true;
|
if (m_rows.empty()) return true;
|
||||||
|
|
||||||
for (const auto & r : m_rows)
|
for (const auto & r : m_rows)
|
||||||
if (r.is_visible()) return false;
|
if (r.is_visible()) return false;
|
||||||
|
|
||||||
|
|||||||
8
table.h
8
table.h
@@ -36,8 +36,8 @@ struct Table {
|
|||||||
|
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::vector<ColDefNode> m_col_defs;
|
std::vector<ColDefNode> m_col_defs;
|
||||||
std::vector<Row> m_rows;
|
std::vector<Row> m_rows;
|
||||||
std::vector<Index> m_indexes;
|
std::vector<Index> m_indexes;
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ struct Table {
|
|||||||
Index * get_index(const std::string &index_name);
|
Index * get_index(const std::string &index_name);
|
||||||
Index * get_index_for_column(const std::string &col_name);
|
Index * get_index_for_column(const std::string &col_name);
|
||||||
|
|
||||||
bool empty();
|
bool empty() const;
|
||||||
|
|
||||||
struct rows_scanner {
|
struct rows_scanner {
|
||||||
explicit rows_scanner(Table *tbl) : m_use_rowids(false), m_table(tbl), m_fscan_itr(tbl->m_rows.begin()) {}
|
explicit rows_scanner(Table *tbl) : m_use_rowids(false), m_table(tbl), m_fscan_itr(tbl->m_rows.begin()) {}
|
||||||
@@ -72,7 +72,7 @@ struct Table {
|
|||||||
Table * m_table;
|
Table * m_table;
|
||||||
std::vector<Row>::iterator m_fscan_itr;
|
std::vector<Row>::iterator m_fscan_itr;
|
||||||
std::vector<rowid_t> m_rowids;
|
std::vector<rowid_t> m_rowids;
|
||||||
size_t m_rowids_idx{};
|
size_t m_rowids_idx{};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
2
usql.cpp
2
usql.cpp
@@ -11,7 +11,7 @@ std::unique_ptr<Table> USql::execute(const std::string &command) {
|
|||||||
std::unique_ptr<Node> node = m_parser.parse(command);
|
std::unique_ptr<Node> node = m_parser.parse(command);
|
||||||
return execute(*node);
|
return execute(*node);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return create_stmt_result_table(-1, e.what(), 0);
|
return create_stmt_result_table(-1, e.what(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
usql.h
8
usql.h
@@ -84,10 +84,10 @@ private:
|
|||||||
static std::unique_ptr<ValueNode> count_function(ColValue *agg_func_value, const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
|
static std::unique_ptr<ValueNode> count_function(ColValue *agg_func_value, const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
|
||||||
|
|
||||||
static void select_row(SelectFromTableNode &where_node,
|
static void select_row(SelectFromTableNode &where_node,
|
||||||
Table *src_table, Row *src_row,
|
Table *src_table, Row *src_row,
|
||||||
Table *rslt_table,
|
Table *rslt_table,
|
||||||
const std::vector<ColDefNode> &rslt_tbl_col_defs, const std::vector<int> &src_table_col_index,
|
const std::vector<ColDefNode> &rslt_tbl_col_defs, const std::vector<int> &src_table_col_index,
|
||||||
bool is_aggregated) ;
|
bool is_aggregated);
|
||||||
|
|
||||||
std::pair<bool, std::vector<rowid_t>> probe_index_scan(const Node *where, Table *table) const;
|
std::pair<bool, std::vector<rowid_t>> probe_index_scan(const Node *where, Table *table) const;
|
||||||
std::pair<bool, std::vector<rowid_t>> look_for_usable_index(const Node *where, Table *table) const;
|
std::pair<bool, std::vector<rowid_t>> look_for_usable_index(const Node *where, Table *table) const;
|
||||||
|
|||||||
35
usql_dml.cpp
35
usql_dml.cpp
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace usql {
|
|
||||||
|
|
||||||
|
namespace usql {
|
||||||
|
|
||||||
|
|
||||||
std::pair<bool, std::vector<rowid_t>> USql::probe_index_scan(const Node *where, Table *table) const {
|
std::pair<bool, std::vector<rowid_t>> USql::probe_index_scan(const Node *where, Table *table) const {
|
||||||
bool indexscan_possible = normalize_where(where);
|
bool indexscan_possible = normalize_where(where);
|
||||||
@@ -85,28 +86,28 @@ void USql::select_row(SelectFromTableNode &where_node,
|
|||||||
const std::vector<int> &src_table_col_index,
|
const std::vector<int> &src_table_col_index,
|
||||||
bool is_aggregated) {
|
bool is_aggregated) {
|
||||||
|
|
||||||
Row *rslt_row = nullptr;
|
Row *rslt_row = nullptr;
|
||||||
|
|
||||||
// when aggregate functions in rslt_table only one row exists
|
// when aggregate functions in rslt_table only one row exists
|
||||||
if (is_aggregated && !rslt_table->empty())
|
if (is_aggregated && !rslt_table->empty())
|
||||||
rslt_row = &rslt_table->m_rows[0];
|
rslt_row = &rslt_table->m_rows[0];
|
||||||
else
|
else
|
||||||
rslt_row = &rslt_table->create_empty_row();
|
rslt_row = &rslt_table->create_empty_row();
|
||||||
|
|
||||||
for (auto idx = 0; idx < rslt_table->columns_count(); idx++) {
|
for (auto idx = 0; idx < rslt_table->columns_count(); idx++) {
|
||||||
auto src_table_col_idx = src_table_col_index[idx];
|
auto src_table_col_idx = src_table_col_index[idx];
|
||||||
|
|
||||||
if (src_table_col_idx == FUNCTION_CALL) {
|
if (src_table_col_idx == FUNCTION_CALL) {
|
||||||
auto evaluated_value = eval_value_node(src_table, *src_row, where_node.cols_names->operator[](idx).value.get(),
|
auto evaluated_value = eval_value_node(src_table, *src_row, where_node.cols_names->operator[](idx).value.get(),
|
||||||
const_cast<ColDefNode *>(&rslt_tbl_col_defs[idx]), &rslt_row->operator[](idx));
|
const_cast<ColDefNode *>(&rslt_tbl_col_defs[idx]), &rslt_row->operator[](idx));
|
||||||
ValueNode *col_value = evaluated_value.get();
|
ValueNode *col_value = evaluated_value.get();
|
||||||
|
|
||||||
rslt_row->setColumnValue((ColDefNode *) &rslt_tbl_col_defs[idx], col_value);
|
rslt_row->setColumnValue((ColDefNode *) &rslt_tbl_col_defs[idx], col_value);
|
||||||
} else {
|
} else {
|
||||||
ColValue &col_value = src_row->operator[](src_table_col_idx);
|
ColValue &col_value = src_row->operator[](src_table_col_idx);
|
||||||
rslt_row->setColumnValue((ColDefNode *) &rslt_tbl_col_defs[idx], col_value);
|
rslt_row->setColumnValue((ColDefNode *) &rslt_tbl_col_defs[idx], col_value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// for aggregate is validated more than needed
|
// for aggregate is validated more than needed
|
||||||
rslt_table->commit_row(*rslt_row);
|
rslt_table->commit_row(*rslt_row);
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ std::unique_ptr<ValueNode> USql::pp_function(const std::vector<std::unique_ptr<V
|
|||||||
return std::make_unique<StringValueNode>(parsed_value->getStringValue());
|
return std::make_unique<StringValueNode>(parsed_value->getStringValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ValueNode>
|
std::unique_ptr<ValueNode> USql::max_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value) {
|
||||||
USql::max_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value) {
|
|
||||||
if (col_def_node->type == ColumnType::integer_type || col_def_node->type == ColumnType::date_type) {
|
if (col_def_node->type == ColumnType::integer_type || col_def_node->type == ColumnType::date_type) {
|
||||||
if (!evaluatedPars[0]->isNull()) {
|
if (!evaluatedPars[0]->isNull()) {
|
||||||
auto val = evaluatedPars[0]->getIntegerValue();
|
auto val = evaluatedPars[0]->getIntegerValue();
|
||||||
|
|||||||
Reference in New Issue
Block a user