simple distinct added
This commit is contained in:
13
usql.cpp
13
usql.cpp
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user