some TODO items squezed
This commit is contained in:
3
debug.h
3
debug.h
@@ -32,6 +32,7 @@ std::vector<std::string> k_debug_sql_commands {
|
|||||||
"update a set i = 5 where i = 2",
|
"update a set i = 5 where i = 2",
|
||||||
"select * from a where i = 5",
|
"select * from a where i = 5",
|
||||||
// "select max(i) from a where s = 'two'"
|
// "select max(i) from a where s = 'two'"
|
||||||
"select min(i), max(i), count(i) from a"
|
"select min(i), max(i), count(i) from a",
|
||||||
|
"select i + 1000 from a"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
11
table.cpp
11
table.cpp
@@ -261,7 +261,6 @@ bool Table::drop_index(const std::string &index_name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Table::index_row(Index &index, const ColDefNode &col_def, const Row &row, const size_t rowid) {
|
void Table::index_row(Index &index, const ColDefNode &col_def, const Row &row, const size_t rowid) {
|
||||||
index.insert(reinterpret_cast<ColValue *>(&row[col_def.order]), rowid);
|
index.insert(reinterpret_cast<ColValue *>(&row[col_def.order]), rowid);
|
||||||
}
|
}
|
||||||
@@ -275,7 +274,6 @@ void Table::reindex_row(Index &index, const ColDefNode &col_def, const Row &old_
|
|||||||
index_row(index, col_def, new_row, rowid);
|
index_row(index, col_def, new_row, rowid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Table::index_row(const Row &row) {
|
void Table::index_row(const Row &row) {
|
||||||
if (!m_indexes.empty()) {
|
if (!m_indexes.empty()) {
|
||||||
const size_t rowid = get_rowid(row);
|
const size_t rowid = get_rowid(row);
|
||||||
@@ -306,7 +304,6 @@ void Table::reindex_row(const Row &old_row, const Row &new_row) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Table::index_rows(const std::string &index_name) {
|
void Table::index_rows(const std::string &index_name) {
|
||||||
auto index = get_index(index_name);
|
auto index = get_index(index_name);
|
||||||
|
|
||||||
@@ -318,7 +315,6 @@ 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) {
|
||||||
@@ -337,6 +333,13 @@ Index * Table::get_index_for_column(const std::string &col_name) {
|
|||||||
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
return (it != m_indexes.end()) ? &(*it) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Table::empty() {
|
||||||
|
if (m_rows.empty()) return true;
|
||||||
|
for (const auto & r : m_rows)
|
||||||
|
if (r.is_visible()) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Row *Table::rows_scanner::next() {
|
Row *Table::rows_scanner::next() {
|
||||||
if (m_use_rowids) {
|
if (m_use_rowids) {
|
||||||
|
|||||||
1
table.h
1
table.h
@@ -59,6 +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();
|
||||||
|
|
||||||
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()) {}
|
||||||
|
|||||||
30
usql.cpp
30
usql.cpp
@@ -174,9 +174,9 @@ std::unique_ptr<ValueNode> USql::eval_function_value_node(Table *table, Row &row
|
|||||||
}
|
}
|
||||||
|
|
||||||
// at this moment no functions without parameter(s) or first param can be null
|
// at this moment no functions without parameter(s) or first param can be null
|
||||||
// TODO exception here or better parsing
|
|
||||||
if (evaluatedPars.empty() || evaluatedPars[0]->isNull())
|
if (evaluatedPars.empty() || evaluatedPars[0]->isNull())
|
||||||
return std::make_unique<NullValueNode>();
|
throw Exception("eval_function_value_node, no function parameter or first is null, function: " + fnc->function);
|
||||||
|
// return std::make_unique<NullValueNode>();
|
||||||
|
|
||||||
// TODO use some enum
|
// TODO use some enum
|
||||||
if (fnc->function == "lower") return lower_function(evaluatedPars);
|
if (fnc->function == "lower") return lower_function(evaluatedPars);
|
||||||
@@ -216,8 +216,8 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
|
|||||||
return std::make_unique<NullValueNode>();
|
return std::make_unique<NullValueNode>();
|
||||||
|
|
||||||
if (outType == ColumnType::float_type) {
|
if (outType == ColumnType::float_type) {
|
||||||
double l = left->getDoubleValue();
|
auto l = left->getDoubleValue();
|
||||||
double r = right->getDoubleValue();
|
auto r = right->getDoubleValue();
|
||||||
switch (node.op) {
|
switch (node.op) {
|
||||||
case ArithmeticalOperatorType::plus_operator:
|
case ArithmeticalOperatorType::plus_operator:
|
||||||
return std::make_unique<DoubleValueNode>(l + r);
|
return std::make_unique<DoubleValueNode>(l + r);
|
||||||
@@ -232,8 +232,8 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (outType == ColumnType::integer_type) {
|
} else if (outType == ColumnType::integer_type) {
|
||||||
long l = left->getIntegerValue();
|
auto l = left->getIntegerValue();
|
||||||
long r = right->getIntegerValue();
|
auto r = right->getIntegerValue();
|
||||||
switch (node.op) {
|
switch (node.op) {
|
||||||
case ArithmeticalOperatorType::plus_operator:
|
case ArithmeticalOperatorType::plus_operator:
|
||||||
return std::make_unique<IntValueNode>(l + r);
|
return std::make_unique<IntValueNode>(l + r);
|
||||||
@@ -248,17 +248,27 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (outType == ColumnType::varchar_type) {
|
} else if (outType == ColumnType::varchar_type) {
|
||||||
std::string l = left->getStringValue();
|
auto l = left->getStringValue();
|
||||||
std::string r = right->getStringValue();
|
auto r = right->getStringValue();
|
||||||
switch (node.op) {
|
switch (node.op) {
|
||||||
case ArithmeticalOperatorType::plus_operator:
|
case ArithmeticalOperatorType::plus_operator:
|
||||||
return std::make_unique<StringValueNode>(l + r);
|
return std::make_unique<StringValueNode>(l + r);
|
||||||
default:
|
default:
|
||||||
throw Exception("eval_arithmetic_operator, varchar type implement me!!");
|
throw Exception("eval_arithmetic_operator, varchar type implement me!!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// TODO date node should support addition and subtraction
|
|
||||||
|
|
||||||
|
} else if (outType == ColumnType::date_type) {
|
||||||
|
auto l = left->getDateValue();
|
||||||
|
auto r = right->getDateValue();
|
||||||
|
switch (node.op) {
|
||||||
|
case ArithmeticalOperatorType::plus_operator:
|
||||||
|
return std::make_unique<IntValueNode>(l + r);
|
||||||
|
case ArithmeticalOperatorType::minus_operator:
|
||||||
|
return std::make_unique<IntValueNode>(l - r);
|
||||||
|
default:
|
||||||
|
throw Exception("eval_arithmetic_operator, date_type type implement me!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
throw Exception("eval_arithmetic_operator, implement me!!");
|
throw Exception("eval_arithmetic_operator, implement me!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ void USql::select_row(SelectFromTableNode &where_node,
|
|||||||
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
|
||||||
// TODO add function to get rows count
|
if (is_aggregated && !rslt_table->empty())
|
||||||
if (is_aggregated && !rslt_table->m_rows.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();
|
||||||
@@ -265,7 +264,7 @@ std::tuple<int, ColDefNode> USql::get_node_definition(Table *table, Node * node,
|
|||||||
auto [left_col_index, left_tbl_col_def] = get_node_definition(table, ari_node->left.get(), col_name, col_order );
|
auto [left_col_index, left_tbl_col_def] = get_node_definition(table, ari_node->left.get(), col_name, col_order );
|
||||||
auto [right_col_index, right_tbl_col_def] = get_node_definition(table, ari_node->right.get(), col_name, col_order );
|
auto [right_col_index, right_tbl_col_def] = get_node_definition(table, ari_node->right.get(), col_name, col_order );
|
||||||
|
|
||||||
ColumnType col_type; // TODO handle varchar and it len
|
ColumnType col_type; // TODO handle varchar and its len
|
||||||
if (left_tbl_col_def.type==ColumnType::float_type || right_tbl_col_def.type==ColumnType::float_type)
|
if (left_tbl_col_def.type==ColumnType::float_type || right_tbl_col_def.type==ColumnType::float_type)
|
||||||
col_type = ColumnType::float_type;
|
col_type = ColumnType::float_type;
|
||||||
else
|
else
|
||||||
@@ -357,7 +356,7 @@ std::unique_ptr<Table> USql::execute_update(const UpdateTableNode &node) {
|
|||||||
|
|
||||||
int col_idx = 0;
|
int col_idx = 0;
|
||||||
for (const auto& col : node.cols_names) {
|
for (const auto& col : node.cols_names) {
|
||||||
// TODO cache it like in select
|
// PERF cache it like in select
|
||||||
ColDefNode col_def = table->get_column_def(col.col_name);
|
ColDefNode col_def = table->get_column_def(col.col_name);
|
||||||
std::unique_ptr<ValueNode> new_val = eval_arithmetic_operator(col_def.type,
|
std::unique_ptr<ValueNode> new_val = eval_arithmetic_operator(col_def.type,
|
||||||
static_cast<ArithmeticalOperatorNode &>(*node.values[col_idx]), table, *row);
|
static_cast<ArithmeticalOperatorNode &>(*node.values[col_idx]), table, *row);
|
||||||
|
|||||||
Reference in New Issue
Block a user