use while let

main
Ziyang Hu 2 years ago
parent e8eef6855c
commit 921ce4d7ad

@ -284,8 +284,7 @@ impl<'s> Session<'s> {
let it = self.txn.iterator(true, &self.perm_cf);
it.seek(&prefix);
while it.is_valid() {
let val = it.key().ok_or_else(|| CozoError::LogicError("Failed to get tuple".to_string()))?;
while let Some(val) = it.key() {
let cur = Tuple::new(val);
if !cur.starts_with(&prefix) {
break;
@ -301,8 +300,7 @@ impl<'s> Session<'s> {
let it = self.txn.iterator(false, &self.temp_cf);
it.seek(&prefix);
while it.is_valid() {
let val = it.key().ok_or_else(|| CozoError::LogicError("Failed to get tuple".to_string()))?;
while let Some(val) = it.key() {
let cur = Tuple::new(val);
if !cur.starts_with(&prefix) {
break;

@ -241,8 +241,7 @@ mod tests {
}
let it = sess.txn.iterator(true, &sess.perm_cf);
it.to_first();
while it.is_valid() {
let (key, val) = it.pair().unwrap();
while let Some((key, val)) = it.pair() {
println!("a: {:?} {:?}", key.as_ref(), val.as_ref());
println!("v: {:?} {:?}", Tuple::new(key), Tuple::new(val));
it.next();

@ -101,8 +101,7 @@ impl<'s> Session<'s> {
let it = self.txn.iterator(false, &self.temp_cf);
it.seek(&prefix);
let mut to_delete = vec![];
while it.is_valid() {
let val = it.key().ok_or_else(|| CozoError::LogicError("Failed to get tuple".to_string()))?;
while let Some(val) = it.key() {
let cur = Tuple::new(val);
if cur.starts_with(&prefix) {
if let Some(name) = cur.get(1) {
@ -144,8 +143,7 @@ impl<'s> Session<'s> {
prefix.push_int(self.stack_depth as i64);
let it = self.txn.iterator(false, &self.temp_cf);
it.seek(&prefix);
while it.is_valid() {
let val = it.key().ok_or_else(|| CozoError::LogicError("Failed to get tuple".to_string()))?;
while let Some(val) = it.key() {
let cur = Tuple::new(val);
if cur.starts_with(&prefix) {
let mut ikey = Tuple::with_prefix(cur.get_prefix());

@ -156,7 +156,7 @@ impl<'s> Session<'s> {
Value::Uuid(_) |
Value::Text(_) |
Value::EndSentinel) => Ok((true, v)),
v@Value::TupleRef(_, _) => Ok((false, v)),
v @ Value::TupleRef(_, _) => Ok((false, v)),
Value::List(l) => {
let init_vec = Vec::with_capacity(l.len());
let res: Result<(bool, Vec<Value>)> = l.into_iter()
@ -1210,16 +1210,14 @@ mod tests {
let it = env.txn.iterator(false, &env.perm_cf);
it.to_first();
while it.is_valid() {
let (k, v) = it.pair().unwrap();
while let Some((k, v)) = it.pair() {
println!("{:?}, {:?}", Tuple::new(k), Tuple::new(v));
it.next();
}
let it = env.txn.iterator(false, &env.temp_cf);
it.to_first();
while it.is_valid() {
let (k, v) = it.pair().unwrap();
while let Some((k, v)) = it.pair() {
println!("{:?}, {:?}", Tuple::new(k), Tuple::new(v));
it.next();
}

@ -289,8 +289,7 @@ mod tests {
sess.rollback().unwrap();
let it = sess.txn.iterator(true, &sess.perm_cf);
it.to_first();
while it.is_valid() {
let (k, v) = it.pair().unwrap();
while let Some((k, v)) = it.pair() {
println!("K: {:?}, V: {:?}", Tuple::new(k), Tuple::new(v));
it.next();
}
@ -340,8 +339,7 @@ mod tests {
let it = sess.txn.iterator(true, &sess.perm_cf);
it.to_first();
while it.is_valid() {
let (k, v) = it.pair().unwrap();
while let Some((k, v)) = it.pair() {
println!("K: {:?}, V: {:?}", Tuple::new(k), Tuple::new(v));
it.next();
}

@ -1,12 +1,13 @@
use std::collections::BTreeMap;
use pest::iterators::Pair;
use cozorocks::{IteratorPtr, SlicePtr};
use crate::db::engine::Session;
use crate::db::query::{FromEl, Selection};
use crate::db::table::{ColId, TableId, TableInfo};
use crate::relation::value::{StaticValue, Value};
use crate::parser::Rule;
use crate::error::Result;
use crate::relation::tuple::OwnTuple;
use crate::relation::tuple::{OwnTuple, Tuple};
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum QueryPlan {
@ -132,7 +133,7 @@ impl<'a> Session<'a> {
Ok(QueryPlan::Projection { arg: Box::new(plan), projection: select_data })
}
pub fn iter_table(&self, tid: TableId) -> ! {
pub fn iter_table(&self, tid: TableId) -> TableRowIterator {
let it = if tid.in_root {
self.txn.iterator(true, &self.perm_cf)
} else {
@ -140,19 +141,34 @@ impl<'a> Session<'a> {
};
let prefix = OwnTuple::with_prefix(tid.id as u32);
it.seek(prefix);
// it.iter()
todo!()
TableRowIterator {
it,
started: false,
}
}
}
pub struct NodeRowIterator {
pub struct TableRowIterator<'a> {
it: IteratorPtr<'a>,
started: bool,
}
pub struct EdgeRowIterator {
impl<'a> Iterator for TableRowIterator<'a> {
type Item = (Tuple<SlicePtr>, Tuple<SlicePtr>);
fn next(&mut self) -> Option<Self::Item> {
if self.started {
self.next();
}
self.it.pair().map(|(k, v)| (Tuple::new(k), Tuple::new(v)))
}
}
pub struct NodeRowIterator {}
pub struct EdgeRowIterator {}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

Loading…
Cancel
Save