Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions repl-tests/order.noise
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# order expressions.

drop target/tests/querytestorder;
create target/tests/querytestorder;

add {"_id":"1", "bar": false};
"1"
add {"_id":"2", "bar": true};
"2"
add {"_id":"3", "bar": "string"};
"3"
add {"_id":"4"};
"4"

find {}
order .bar asc
return .bar;
[
null,
false,
true,
"string"
]

find {}
order .bar default=1 asc
return .bar default=1;
[
false,
true,
1,
"string"
]

find {}
order .bar default=1 asc
return .bar;
[
false,
true,
null,
"string"
]


find {}
order .bar asc
return ._id;
[
"4",
"1",
"2",
"3"
]

find {}
order .bar default=1 asc
return ._id;
[
"1",
"2",
"4",
"3"
]

find {}
order .bar asc
return .bar default=1;
[
1,
false,
true,
"string"
]
14 changes: 13 additions & 1 deletion src/returnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,19 @@ impl Returnable for RetValue {
}

fn take_order_for_matching_fields(&mut self, map: &mut HashMap<String, OrderInfo>) {
self.order_info = map.remove(&self.rp.to_key());
// Compare the default values of the to be removed order info with the default value for
// the return value. If they are equal, the order can be safely removed, as the ordering
// of the result will be the same.
// If they are not equal, then we need to keep the order else the final result would be
// sorted by the values of the result and not of the orde clause.
let keypath = &self.rp.to_key();
let remove_order = match map.get(keypath) {
Some(order_info) => order_info.default == self.default,
None => false,
};
if remove_order {
self.order_info = map.remove(keypath);
}
}

fn get_ordering(&mut self, orders: &mut Vec<Option<OrderInfo>>) {
Expand Down