some TODOs removed..

This commit is contained in:
2021-08-14 11:33:02 +02:00
parent 6921421a65
commit 4665705c3d
10 changed files with 113 additions and 78 deletions

View File

@@ -236,7 +236,8 @@ void USql::execute_order_by(SelectFromTableNode &node, Table *table, Table *resu
auto compare_rows = [&node, &result](const Row &a, const Row &b) {
for(const auto& order_by_col_def : node.order_by) {
ColDefNode col_def = result->get_column_def(order_by_col_def.col_index - 1); // TODO validate index
// TODO validate index
ColDefNode col_def = result->get_column_def(order_by_col_def.col_index - 1);
ColValue *a_val = a.ith_column(col_def.order);
ColValue *b_val = b.ith_column(col_def.order);
@@ -282,6 +283,7 @@ std::tuple<int, ColDefNode> USql::get_column_definition(Table *table, SelectColN
} else if (select_col_node->value->node_type == NodeType::arithmetical_operator) {
// TODO return correct type
// hierarchicaly go throuhg and deduce right type
ColDefNode cdef = ColDefNode{new_col_name, ColumnType::float_type, col_order, 1, true};
return std::make_tuple(-1, cdef);
}
@@ -289,6 +291,7 @@ std::tuple<int, ColDefNode> USql::get_column_definition(Table *table, SelectColN
}
std::unique_ptr<Table> USql::execute_delete(DeleteFromTableNode &node) {
// find source table
Table *table = find_table(node.table_name);
@@ -318,7 +321,8 @@ std::unique_ptr<Table> USql::execute_update(UpdateTableNode &node) {
if (eval_where(node.where.get(), table, *row)) {
int i = 0;
for (const auto& col : node.cols_names) {
ColDefNode col_def = table->get_column_def(col.col_name); // TODO cache it like in select
// TODO cache it like in select
ColDefNode col_def = table->get_column_def(col.col_name);
std::unique_ptr<ValueNode> new_val = eval_arithmetic_operator(col_def.type,
static_cast<ArithmeticalOperatorNode &>(*node.values[i]),
table, *row);
@@ -372,7 +376,7 @@ bool USql::eval_relational_operator(const RelationalOperatorNode &filter, Table
comparator = bl == br ? 0 : 1; // TODO define it
// TODO handle dates
} else {
// TODO throw exception
throw Exception("Undefined combination of types");
}
switch (filter.op) {
@@ -416,6 +420,9 @@ std::unique_ptr<ValueNode> USql::eval_database_value_node(Table *table, Row &row
ColDefNode col_def = table->get_column_def( dvl->col_name); // TODO optimize it to just get this def once
auto db_value = row.ith_column(col_def.order);
if (db_value->isNull())
return std::make_unique<NullValueNode>();
if (col_def.type == ColumnType::integer_type)
return std::make_unique<IntValueNode>(db_value->getIntValue());
if (col_def.type == ColumnType::float_type)
@@ -513,6 +520,9 @@ std::unique_ptr<ValueNode> USql::eval_arithmetic_operator(ColumnType outType, Ar
std::unique_ptr<ValueNode> left = eval_value_node(table, row, node.left.get());
std::unique_ptr<ValueNode> right = eval_value_node(table, row, node.right.get());
if (left->isNull() || right->isNull())
return std::make_unique<NullValueNode>();
if (outType == ColumnType::float_type) {
double l = ((ValueNode *) left.get())->getDoubleValue();
double r = ((ValueNode *) right.get())->getDoubleValue();