Sketch select_eq
This commit is contained in:
parent
c7166bd12e
commit
f973df2ca2
2 changed files with 48 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ use bimap::BiMap;
|
||||||
use storage_engine::store::Store;
|
use storage_engine::store::Store;
|
||||||
use storage_engine::cursor::{ReadCursor, WriteCursor};
|
use storage_engine::cursor::{ReadCursor, WriteCursor};
|
||||||
use storage_engine::cursor_capabilities::traversal::CursorCanTraverse;
|
use storage_engine::cursor_capabilities::traversal::CursorCanTraverse;
|
||||||
|
use storage_engine::cursor_capabilities::index_access::CursorCanReadIndex;
|
||||||
|
|
||||||
// ==============Interpreter================
|
// ==============Interpreter================
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -84,6 +85,16 @@ impl State {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn select_eq<Writer: ResponseWriter>(table: &Table, mut cursor: ReadCursor<'_, Value>, response_writer: &mut Writer, column_selection: ColumnSelection, column: Column, value: Value) -> DbResult<()> {
|
||||||
|
let entries = cursor.select_entries_where_eq(column as storage_engine::store::Column, &value).await.map_err(|e| RuntimeError::StorageEngineError(table.schema.table_name().to_string(), e))?;
|
||||||
|
for entry in entries {
|
||||||
|
let row: Row = From::from(entry);
|
||||||
|
let restricted_row = row.restrict_columns(&column_selection);
|
||||||
|
response_writer.write_table_row(&restricted_row).await.map_err(|e| RuntimeError::AnyhowError(e))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn interpret<Writer: ResponseWriter>(&mut self, response_writer: &mut Writer, operation: Operation) -> DbResult<()> {
|
pub async fn interpret<Writer: ResponseWriter>(&mut self, response_writer: &mut Writer, operation: Operation) -> DbResult<()> {
|
||||||
use Operation::*;
|
use Operation::*;
|
||||||
|
|
||||||
|
|
@ -99,7 +110,7 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Condition::Eq(eq_column, value)) => {
|
Some(Condition::Eq(eq_column, value)) => {
|
||||||
todo!()
|
Self::select_eq(&table, cursor, response_writer, column_selection, eq_column, value).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,42 @@ impl Ord for IndexableValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Eq for Value {}
|
||||||
|
|
||||||
|
impl PartialOrd for Value {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Make column know about indexable types
|
||||||
|
impl Ord for Value {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
match (self, other) {
|
||||||
|
(Value::String(s0), Value::String(s1)) => s0.cmp(s1),
|
||||||
|
(Value::Int(n0), Value::Int(n1)) => n0.cmp(n1),
|
||||||
|
(Value::Uuid(id0), Value::Uuid(id1)) => id0.cmp(id1),
|
||||||
|
(Value::None(_), Value::None(_)) => Ordering::Equal,
|
||||||
|
(Value::None(_), Value::Some(_)) => Ordering::Less,
|
||||||
|
(Value::Some(_), Value::None(_)) => Ordering::Greater,
|
||||||
|
(Value::Some(v0), Value::Some(v1)) => v0.cmp(v1),
|
||||||
|
_ =>
|
||||||
|
// SAFETY:
|
||||||
|
// We are using indexable values as keys in key-value maps.
|
||||||
|
// When validation is done, it can't happen that we will be comparing two values
|
||||||
|
// of different types.
|
||||||
|
// Ofcourse another option is to artificialy order e.g.
|
||||||
|
// None < Some(...) < String < Int < Uuid
|
||||||
|
// where ... is again None < Some(...) < String < Int < Uuid
|
||||||
|
// where ...
|
||||||
|
// infinitely deep total order. But this is pointless for our usecase.
|
||||||
|
{
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// impl Encode for Value {
|
// impl Encode for Value {
|
||||||
// fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
|
// fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
|
||||||
// todo!()
|
// todo!()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue