simple distinct added

This commit is contained in:
2021-08-01 14:31:19 +02:00
parent 4a344d0e77
commit 50a7993a2e
9 changed files with 41 additions and 12 deletions

View File

@@ -190,15 +190,24 @@ std::unique_ptr<Table> USql::execute_select(SelectFromTableNode &node) {
}
}
// order by
execute_distinct(node, result.get());
execute_order_by(node, table, result.get());
// offset & limit
execute_offset_limit(node.offset_limit, result.get());
return std::move(result);
}
void USql::execute_distinct(SelectFromTableNode &node, Table *result) const {
if (!node.distinct) return;
auto compare_rows = [](const Row &a, const Row &b) { return a.compare(b) >= 0; };
std::sort(result->m_rows.begin(), result->m_rows.end(), compare_rows);
result->m_rows.erase(std::unique(result->m_rows.begin(), result->m_rows.end()), result->m_rows.end());
}
void USql::execute_order_by(SelectFromTableNode &node, Table *table, Table *result) const {
if (node.order_by.size() == 0) return;