remove few TODOs
This commit is contained in:
41
usql_dml.cpp
41
usql_dml.cpp
@@ -88,7 +88,7 @@ void USql::select_row(SelectFromTableNode &where_node,
|
||||
|
||||
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())
|
||||
rslt_row = &rslt_table->m_rows[0];
|
||||
else
|
||||
@@ -108,24 +108,21 @@ void USql::select_row(SelectFromTableNode &where_node,
|
||||
rslt_row->setColumnValue((ColDefNode *) &rslt_tbl_col_defs[idx], col_value);
|
||||
}
|
||||
}
|
||||
|
||||
// for aggregate is validated more than needed
|
||||
rslt_table->commit_row(*rslt_row);
|
||||
// for aggregate is validated more than needed
|
||||
rslt_table->commit_row(*rslt_row);
|
||||
}
|
||||
|
||||
bool USql::check_for_aggregate_only_functions(SelectFromTableNode &node, size_t result_cols_cnt) {
|
||||
size_t aggregate_funcs = 0;
|
||||
|
||||
for (size_t i = 0; i < node.cols_names->size(); i++) {
|
||||
SelectColNode * col_node = &node.cols_names->operator[](i);
|
||||
if (col_node->value->node_type == NodeType::function) {
|
||||
auto func_node = static_cast<FunctionNode *>(col_node->value.get());
|
||||
if (func_node->function == "count" || func_node->function == "min" || func_node->function == "max")
|
||||
aggregate_funcs++;
|
||||
}
|
||||
if (col_node->value->node_type == NodeType::function && ((FunctionNode *)col_node->value.get())->is_agg_function())
|
||||
aggregate_funcs++;
|
||||
}
|
||||
// check whether aggregates are not present or all columns are aggregates
|
||||
if (aggregate_funcs > 0 && aggregate_funcs != result_cols_cnt) {
|
||||
throw Exception("aggregate functions with no aggregates");
|
||||
throw Exception("aggregate functions mixed with no aggregate functions in select clause");
|
||||
}
|
||||
|
||||
return aggregate_funcs > 0;
|
||||
@@ -229,20 +226,20 @@ std::tuple<int, ColDefNode> USql::get_node_definition(Table *table, Node * node,
|
||||
} else if (node->node_type == NodeType::function) {
|
||||
auto func_node = static_cast<FunctionNode *>(node);
|
||||
|
||||
if (func_node->function == "to_string") {
|
||||
if (func_node->function == FunctionNode::Type::to_string) {
|
||||
ColDefNode col_def = ColDefNode{col_name, ColumnType::varchar_type, col_order, 32, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
} else if (func_node->function == "to_date") {
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
} else if (func_node->function == FunctionNode::Type::to_date) {
|
||||
ColDefNode col_def = ColDefNode{col_name, ColumnType::integer_type, col_order, 1, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
} else if (func_node->function == "pp") {
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
} else if (func_node->function == FunctionNode::Type::pp) {
|
||||
ColDefNode col_def = ColDefNode{col_name, ColumnType::varchar_type, col_order, 10, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
} else if (func_node->function == "lower" || func_node->function == "upper") {
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
} else if (func_node->function == FunctionNode::Type::lower || func_node->function == FunctionNode::Type::upper) {
|
||||
// TODO get length, use get_db_column_definition
|
||||
ColDefNode col_def = ColDefNode{col_name, ColumnType::varchar_type, col_order, 256, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
} else if (func_node->function == "min" || func_node->function == "max") {
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
} else if (func_node->function == FunctionNode::Type::min || func_node->function == FunctionNode::Type::max) {
|
||||
auto col_type= ColumnType::float_type;
|
||||
size_t col_len = 1;
|
||||
auto & v = func_node->params[0];
|
||||
@@ -252,10 +249,10 @@ std::tuple<int, ColDefNode> USql::get_node_definition(Table *table, Node * node,
|
||||
col_len = src_col_def.length;
|
||||
}
|
||||
ColDefNode col_def = ColDefNode{col_name, col_type, col_order, col_len, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
} else if (func_node->function == "count") {
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
} else if (func_node->function == FunctionNode::Type::count) {
|
||||
ColDefNode col_def = ColDefNode{col_name, ColumnType::integer_type, col_order, 1, true};
|
||||
return std::make_tuple(-1, col_def);
|
||||
return std::make_tuple(FUNCTION_CALL, col_def);
|
||||
}
|
||||
throw Exception("Unsupported function");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user