|
|
@ -5,12 +5,13 @@ use crate::env::{Env, LayeredEnv, StructuredEnvItem};
|
|
|
|
use crate::error::Result;
|
|
|
|
use crate::error::Result;
|
|
|
|
use crate::error::CozoError::*;
|
|
|
|
use crate::error::CozoError::*;
|
|
|
|
use crate::eval::Evaluator;
|
|
|
|
use crate::eval::Evaluator;
|
|
|
|
use crate::storage::Storage;
|
|
|
|
use crate::storage::{RocksStorage, Storage};
|
|
|
|
use crate::typing::{Col, Columns, Edge, Index, Node, Structured, TableId, Typing};
|
|
|
|
use crate::typing::{Col, Columns, Edge, Index, Node, StorageStatus, Structured, TableId, Typing};
|
|
|
|
use crate::typing::StorageStatus::{Planned, Stored};
|
|
|
|
use crate::typing::StorageStatus::{Planned, Stored};
|
|
|
|
use crate::value::{ByteArrayBuilder, Value};
|
|
|
|
use crate::value::{ByteArrayBuilder, ByteArrayParser, Value};
|
|
|
|
use crate::parser::{Parser, Rule};
|
|
|
|
use crate::parser::{Parser, Rule};
|
|
|
|
use pest::Parser as PestParser;
|
|
|
|
use pest::Parser as PestParser;
|
|
|
|
|
|
|
|
use cozo_rocks::*;
|
|
|
|
// use rocksdb::IteratorMode;
|
|
|
|
// use rocksdb::IteratorMode;
|
|
|
|
|
|
|
|
|
|
|
|
fn parse_ident(pair: Pair<Rule>) -> String {
|
|
|
|
fn parse_ident(pair: Pair<Rule>) -> String {
|
|
|
@ -290,110 +291,115 @@ pub enum TableKind {
|
|
|
|
Index = 4,
|
|
|
|
Index = 4,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Storage {
|
|
|
|
impl RocksStorage {
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
fn all_metadata(&self, env: &StructuredEnvItem) -> Result<Vec<Structured>> {
|
|
|
|
fn all_metadata(&self, env: &StructuredEnvItem) -> Result<Vec<Structured>> {
|
|
|
|
todo!()
|
|
|
|
let default_cf = self.db.get_cf_handle("default")?;
|
|
|
|
// let it = self.db.as_ref().ok_or(DatabaseClosed)?.full_iterator(IteratorMode::Start);
|
|
|
|
let it = self.db.iterator(&default_cf, None);
|
|
|
|
//
|
|
|
|
let mut ret = vec![];
|
|
|
|
// let mut ret = vec![];
|
|
|
|
|
|
|
|
// for (k, v) in it {
|
|
|
|
while it.is_valid() {
|
|
|
|
// let mut key_parser = ByteArrayParser::new(&k);
|
|
|
|
let k = it.key();
|
|
|
|
// let table_name = key_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
let v = it.value();
|
|
|
|
//
|
|
|
|
let mut key_parser = ByteArrayParser::new(&k);
|
|
|
|
// let mut data_parser = ByteArrayParser::new(&v);
|
|
|
|
let mut data_parser = ByteArrayParser::new(&v);
|
|
|
|
// let table_kind = data_parser.parse_value().unwrap();
|
|
|
|
|
|
|
|
// let table_id = TableId { name: table_name, global: true };
|
|
|
|
let table_name = key_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
// match table_kind {
|
|
|
|
let table_kind = data_parser.parse_value().unwrap();
|
|
|
|
// Value::UInt(i) if i == TableKind::Node as u64 => {
|
|
|
|
let table_id = TableId { name: table_name, global: true };
|
|
|
|
// let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
|
|
|
|
// .into_iter().map(|v| {
|
|
|
|
match table_kind {
|
|
|
|
// let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
Value::UInt(i) if i == TableKind::Node as u64 => {
|
|
|
|
// let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
// let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
.into_iter().map(|v| {
|
|
|
|
// let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
// let default = vs.next().unwrap().into_owned();
|
|
|
|
let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// Col {
|
|
|
|
let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// name,
|
|
|
|
let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
// typ,
|
|
|
|
let default = vs.next().unwrap().into_owned();
|
|
|
|
// default,
|
|
|
|
Col {
|
|
|
|
// }
|
|
|
|
name,
|
|
|
|
// }).collect();
|
|
|
|
typ,
|
|
|
|
// let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
default,
|
|
|
|
// .into_iter().map(|v| {
|
|
|
|
}
|
|
|
|
// let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
}).collect();
|
|
|
|
// let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
// let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
.into_iter().map(|v| {
|
|
|
|
// let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
// let default = vs.next().unwrap().into_owned();
|
|
|
|
let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// Col {
|
|
|
|
let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// name,
|
|
|
|
let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
// typ,
|
|
|
|
let default = vs.next().unwrap().into_owned();
|
|
|
|
// default,
|
|
|
|
Col {
|
|
|
|
// }
|
|
|
|
name,
|
|
|
|
// }).collect();
|
|
|
|
typ,
|
|
|
|
// let node = Node {
|
|
|
|
default,
|
|
|
|
// status: StorageStatus::Stored,
|
|
|
|
}
|
|
|
|
// id: table_id,
|
|
|
|
}).collect();
|
|
|
|
// keys,
|
|
|
|
let node = Node {
|
|
|
|
// cols,
|
|
|
|
status: StorageStatus::Stored,
|
|
|
|
// out_e: vec![], // TODO fix these
|
|
|
|
id: table_id,
|
|
|
|
// in_e: vec![],
|
|
|
|
keys,
|
|
|
|
// attached: vec![],
|
|
|
|
cols,
|
|
|
|
// };
|
|
|
|
out_e: vec![], // TODO fix these
|
|
|
|
// ret.push(Structured::Node(node));
|
|
|
|
in_e: vec![],
|
|
|
|
// }
|
|
|
|
attached: vec![],
|
|
|
|
// Value::UInt(i) if i == TableKind::Edge as u64 => {
|
|
|
|
};
|
|
|
|
// let src_name = data_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
ret.push(Structured::Node(node));
|
|
|
|
// let dst_name = data_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
}
|
|
|
|
// let src_id = TableId { name: src_name, global: true };
|
|
|
|
Value::UInt(i) if i == TableKind::Edge as u64 => {
|
|
|
|
// let dst_id = TableId { name: dst_name, global: true };
|
|
|
|
let src_name = data_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
// let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
let dst_name = data_parser.parse_value().unwrap().get_string().unwrap();
|
|
|
|
// .into_iter().map(|v| {
|
|
|
|
let src_id = TableId { name: src_name, global: true };
|
|
|
|
// let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
let dst_id = TableId { name: dst_name, global: true };
|
|
|
|
// let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
// let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
.into_iter().map(|v| {
|
|
|
|
// let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
// let default = vs.next().unwrap().into_owned();
|
|
|
|
let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// Col {
|
|
|
|
let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// name,
|
|
|
|
let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
// typ,
|
|
|
|
let default = vs.next().unwrap().into_owned();
|
|
|
|
// default,
|
|
|
|
Col {
|
|
|
|
// }
|
|
|
|
name,
|
|
|
|
// }).collect();
|
|
|
|
typ,
|
|
|
|
// let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
default,
|
|
|
|
// .into_iter().map(|v| {
|
|
|
|
}
|
|
|
|
// let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
}).collect();
|
|
|
|
// let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
|
|
|
// let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
.into_iter().map(|v| {
|
|
|
|
// let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
let mut vs = v.get_list().unwrap().into_iter();
|
|
|
|
// let default = vs.next().unwrap().into_owned();
|
|
|
|
let name = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// Col {
|
|
|
|
let typ = vs.next().unwrap().get_string().unwrap();
|
|
|
|
// name,
|
|
|
|
let typ = env.build_type_from_str(&typ).unwrap();
|
|
|
|
// typ,
|
|
|
|
let default = vs.next().unwrap().into_owned();
|
|
|
|
// default,
|
|
|
|
Col {
|
|
|
|
// }
|
|
|
|
name,
|
|
|
|
// }).collect();
|
|
|
|
typ,
|
|
|
|
// let edge = Edge {
|
|
|
|
default,
|
|
|
|
// status: StorageStatus::Stored,
|
|
|
|
}
|
|
|
|
// src: src_id,
|
|
|
|
}).collect();
|
|
|
|
// dst: dst_id,
|
|
|
|
let edge = Edge {
|
|
|
|
// id: table_id,
|
|
|
|
status: StorageStatus::Stored,
|
|
|
|
// keys,
|
|
|
|
src: src_id,
|
|
|
|
// cols,
|
|
|
|
dst: dst_id,
|
|
|
|
// };
|
|
|
|
id: table_id,
|
|
|
|
// ret.push(Structured::Edge(edge));
|
|
|
|
keys,
|
|
|
|
// }
|
|
|
|
cols,
|
|
|
|
// Value::UInt(i) if i == TableKind::Columns as u64 => {
|
|
|
|
};
|
|
|
|
// todo!()
|
|
|
|
ret.push(Structured::Edge(edge));
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// Value::UInt(i) if i == TableKind::Index as u64 => {
|
|
|
|
Value::UInt(i) if i == TableKind::Columns as u64 => {
|
|
|
|
// todo!()
|
|
|
|
todo!()
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// _ => unreachable!()
|
|
|
|
Value::UInt(i) if i == TableKind::Index as u64 => {
|
|
|
|
// }
|
|
|
|
todo!()
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// Ok(ret)
|
|
|
|
_ => unreachable!()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it.next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn persist_node(&mut self, node: &mut Node) -> Result<()> {
|
|
|
|
fn persist_node(&mut self, node: &mut Node) -> Result<()> {
|
|
|
@ -450,7 +456,7 @@ impl Storage {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Evaluator {
|
|
|
|
impl Evaluator<RocksStorage> {
|
|
|
|
pub fn restore_metadata(&mut self) -> Result<()> {
|
|
|
|
pub fn restore_metadata(&mut self) -> Result<()> {
|
|
|
|
let mds = self.storage.all_metadata(self.s_envs.root())?;
|
|
|
|
let mds = self.storage.all_metadata(self.s_envs.root())?;
|
|
|
|
for md in &mds {
|
|
|
|
for md in &mds {
|
|
|
@ -535,6 +541,7 @@ impl Evaluator {
|
|
|
|
mod tests {
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
|
use pest::Parser as PestParser;
|
|
|
|
use pest::Parser as PestParser;
|
|
|
|
|
|
|
|
use crate::eval::EvaluatorWithStorage;
|
|
|
|
use crate::parser::Parser;
|
|
|
|
use crate::parser::Parser;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -552,7 +559,7 @@ mod tests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
"#;
|
|
|
|
let parsed = Parser::parse(Rule::file, s).unwrap();
|
|
|
|
let parsed = Parser::parse(Rule::file, s).unwrap();
|
|
|
|
let mut eval = Evaluator::new("_path_for_rocksdb_storagex".to_string()).unwrap();
|
|
|
|
let mut eval = EvaluatorWithStorage::new("_path_for_rocksdb_storagex".to_string()).unwrap();
|
|
|
|
eval.build_table(parsed).unwrap();
|
|
|
|
eval.build_table(parsed).unwrap();
|
|
|
|
eval.restore_metadata().unwrap();
|
|
|
|
eval.restore_metadata().unwrap();
|
|
|
|
eval.storage.delete().unwrap();
|
|
|
|
eval.storage.delete().unwrap();
|
|
|
|