mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
ORDER BY: support nullable sorting columns and qualified identifiers
This commit is contained in:
@@ -674,11 +674,29 @@ pub fn resolve_ident_qualified(
|
||||
.columns
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, col)| col.name == *ident);
|
||||
.find(|(_, col)| col.name == *ident)
|
||||
.map(|(idx, col)| (idx, col.ty, col.primary_key));
|
||||
let mut idx;
|
||||
let mut col_type;
|
||||
let mut is_primary_key;
|
||||
if res.is_some() {
|
||||
let (idx, col) = res.unwrap();
|
||||
(idx, col_type, is_primary_key) = res.unwrap();
|
||||
// overwrite if cursor hint is provided
|
||||
if let Some(cursor_hint) = cursor_hint {
|
||||
let cols = &program.cursor_ref[cursor_hint].1;
|
||||
if let Some(res) = cols.as_ref().and_then(|res| {
|
||||
res.columns()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|x| x.1.name == format!("{}.{}", table_name, ident))
|
||||
}) {
|
||||
idx = res.0;
|
||||
col_type = res.1.ty;
|
||||
is_primary_key = res.1.primary_key;
|
||||
}
|
||||
}
|
||||
let cursor_id = program.resolve_cursor_id(&join.identifier, cursor_hint);
|
||||
return Ok((idx, col.ty, cursor_id, col.primary_key));
|
||||
return Ok((idx, col_type, cursor_id, is_primary_key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,8 +244,15 @@ fn translate_sorter(
|
||||
ty: crate::schema::Type::Null,
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
todo!();
|
||||
ast::Expr::Qualified(table_name, ident) => {
|
||||
pseudo_columns.push(Column {
|
||||
name: normalize_ident(format!("{}.{}", table_name.0, ident.0).as_str()),
|
||||
primary_key: false,
|
||||
ty: crate::schema::Type::Null,
|
||||
});
|
||||
}
|
||||
other => {
|
||||
todo!("translate_sorter: {:?}", other);
|
||||
}
|
||||
},
|
||||
ast::ResultColumn::Star => {}
|
||||
|
||||
@@ -88,6 +88,8 @@ impl std::cmp::PartialOrd<OwnedValue> for OwnedValue {
|
||||
blob_left.partial_cmp(blob_right)
|
||||
}
|
||||
(OwnedValue::Null, OwnedValue::Null) => Some(std::cmp::Ordering::Equal),
|
||||
(OwnedValue::Null, _) => Some(std::cmp::Ordering::Less),
|
||||
(_, OwnedValue::Null) => Some(std::cmp::Ordering::Greater),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user