Merge branch 'deal_with_todos' into 'main'

Deal with todos in minisql crate

See merge request x433485/minisql!27
This commit is contained in:
Yuriy Dupyn 2024-02-01 14:28:28 +01:00
commit 999e9e6d5b
4 changed files with 28 additions and 24 deletions

View file

@ -12,8 +12,7 @@ use crate::type_system::{IndexableValue, Uuid, Value};
#[derive(Debug, Serialize, Deserialize)]
pub struct Table {
schema: TableSchema,
rows: Rows, // TODO: Consider wrapping this in a lock. Also consider if we need to have the
// same lock for both rows and indexes
rows: Rows,
indexes: HashMap<Column, ColumnIndex>,
}

View file

@ -35,10 +35,9 @@ impl std::fmt::Debug for Response<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
use Response::*;
match self {
Selected(_schema, _columns, _rows) =>
// TODO: How can we iterate through the rows without having to take ownership of
// them?
{
Selected(_schema, _columns, _rows) => {
// It seems that Rust requires ownership of rows to format them here.
// This is why we output the string below
f.write_str("Some rows... trust me")
}
Inserted => f.write_str("Inserted"),
@ -89,7 +88,6 @@ impl State {
}
pub fn interpret<'a>(&'a mut self, operation: Operation) -> DbResult<Response<'a>> {
// TODO: lock stuff
use Operation::*;
match operation {
@ -575,8 +573,6 @@ pub fn example() {
{
{
// TODO: Why do I have to write these braces explicitely? Why doesn't Rust compiler
// "infer" them?
let _delete_response: Response = state
.interpret(Delete(users_position, Some(Eq(id_column, id0.clone()))))
.unwrap();

View file

@ -13,14 +13,23 @@ pub enum DbType {
// ==============Values================
pub type Uuid = u64;
// TODO: What about nulls? I would rather not have that in SQL, it sucks.
// I would rather have non-nullable values by default,
// and something like an explicit Option type for nulls.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub enum Value {
Number(f64), // TODO: Can't put floats as keys in maps, since they don't implement Eq. What to
// do?
// Note that it doesn't really make sense to compare floats on equality without specifying
// precision. You can ofcourse convert a float to string or to a bytevector and then compare
// equality of those, but that's not the right equality. And ofcourse Rust designers are aware
// of this, so floats don't implement the Eq trait.
// This ofcourse complicates indexing of Number columns.
//
// Either we'd have to design a specific key-value map data-structure where keys are floats,
// s.t. to index with a given float K you also specify a tolerance error so that the resulting
// value set will contain all values whose keys are close to K within that tolerence. This
// seems highly non-trivial.
//
// So we choose to make a distinction between indexable and non-indexable types, and Number is
// not indexable.
Number(f64),
Indexable(IndexableValue),
}
@ -30,7 +39,6 @@ pub enum IndexableValue {
String(String),
Int(u64),
Uuid(Uuid),
// TODO: what about null?
}
impl DbType {