Implement RAND() ordering in ORDER BY clauses
This commit is contained in:
parent
e6fe7e675b
commit
4bc3b299aa
1 changed files with 12 additions and 3 deletions
|
@ -20,6 +20,7 @@ use crate::sql::statements::update::UpdateStatement;
|
||||||
use crate::sql::table::Table;
|
use crate::sql::table::Table;
|
||||||
use crate::sql::thing::Thing;
|
use crate::sql::thing::Thing;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
use rand::Rng;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -288,10 +289,18 @@ impl Iterator {
|
||||||
// Loop over each order clause
|
// Loop over each order clause
|
||||||
for order in orders.iter() {
|
for order in orders.iter() {
|
||||||
// Reverse the ordering if DESC
|
// Reverse the ordering if DESC
|
||||||
let o = match order.direction {
|
let o = match order.random {
|
||||||
true => a.compare(b, &order.order),
|
true => {
|
||||||
false => b.compare(a, &order.order),
|
let a = rand::random::<f64>();
|
||||||
|
let b = rand::random::<f64>();
|
||||||
|
a.partial_cmp(&b)
|
||||||
|
}
|
||||||
|
false => match order.direction {
|
||||||
|
true => a.compare(b, &order.order),
|
||||||
|
false => b.compare(a, &order.order),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
//
|
||||||
match o {
|
match o {
|
||||||
Some(Ordering::Greater) => return Ordering::Greater,
|
Some(Ordering::Greater) => return Ordering::Greater,
|
||||||
Some(Ordering::Equal) => continue,
|
Some(Ordering::Equal) => continue,
|
||||||
|
|
Loading…
Reference in a new issue