remove old files
parent
b188a5a559
commit
50f844f8e4
@ -1,598 +0,0 @@
|
||||
// use std::borrow::{Borrow, BorrowMut, Cow};
|
||||
// use std::collections::BTreeMap;
|
||||
// use std::sync::Arc;
|
||||
// use pest::iterators::{Pair, Pairs};
|
||||
// use crate::ast::parse_string;
|
||||
// use crate::env::{Env, LayeredEnv, Environment};
|
||||
// use crate::error::Result;
|
||||
// use crate::error::CozoError::*;
|
||||
// use crate::eval::Evaluator;
|
||||
// use crate::storage::{RocksStorage};
|
||||
// use crate::typing::{Col, Columns, Edge, Index, Node, StorageStatus, Structured, TableId, Typing};
|
||||
// use crate::typing::StorageStatus::{Planned, Stored};
|
||||
// use crate::value::{ByteArrayBuilder, ByteArrayParser, StaticValue, Value};
|
||||
// use crate::parser::{Parser, Rule};
|
||||
// use pest::Parser as PestParser;
|
||||
// use cozo_rocks::*;
|
||||
// // use rocksdb::IteratorMode;
|
||||
//
|
||||
// fn parse_ident(pair: Pair<Rule>) -> String {
|
||||
// pair.as_str().to_string()
|
||||
// }
|
||||
//
|
||||
// pub fn build_name_in_def(pair: Pair<Rule>, forbid_underscore: bool) -> Result<String> {
|
||||
// let inner = pair.into_inner().next().unwrap();
|
||||
// let name = match inner.as_rule() {
|
||||
// Rule::ident => parse_ident(inner),
|
||||
// Rule::raw_string | Rule::s_quoted_string | Rule::quoted_string => parse_string(inner)?,
|
||||
// _ => unreachable!()
|
||||
// };
|
||||
// if forbid_underscore && name.starts_with('_') {
|
||||
// Err(ReservedIdent)
|
||||
// } else {
|
||||
// Ok(name)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn parse_col_name(pair: Pair<Rule>) -> Result<(String, bool)> {
|
||||
// let mut pairs = pair.into_inner();
|
||||
// let mut is_key = false;
|
||||
// let mut nxt_pair = pairs.next().unwrap();
|
||||
// if nxt_pair.as_rule() == Rule::key_marker {
|
||||
// is_key = true;
|
||||
// nxt_pair = pairs.next().unwrap();
|
||||
// }
|
||||
//
|
||||
// Ok((build_name_in_def(nxt_pair, true)?, is_key))
|
||||
// }
|
||||
//
|
||||
//
|
||||
// impl Environment {
|
||||
// pub fn build_edge_def(&mut self, pair: Pair<Rule>, local_id: usize) -> Result<String> {
|
||||
// let mut inner = pair.into_inner();
|
||||
// let src_name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let src = self.resolve(&src_name).ok_or(UndefinedType)?;
|
||||
// let src = src.borrow();
|
||||
// let src_id = if let Structured::Node(n) = src {
|
||||
// n.id.clone()
|
||||
// } else {
|
||||
// return Err(WrongType);
|
||||
// };
|
||||
// let name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let dst_name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let dst = self.resolve(&dst_name).ok_or(UndefinedType)?;
|
||||
// let dst = dst.borrow();
|
||||
// let dst_id = if let Structured::Node(n) = dst {
|
||||
// n.id.clone()
|
||||
// } else {
|
||||
// return Err(WrongType);
|
||||
// };
|
||||
// if local_id == 0 && (!src_id.is_global() || !dst_id.is_global()) {
|
||||
// return Err(IncompatibleEdge);
|
||||
// }
|
||||
// let (keys, cols) = if let Some(p) = inner.next() {
|
||||
// self.build_col_defs(p)?
|
||||
// } else {
|
||||
// (vec![], vec![])
|
||||
// };
|
||||
// let table_id = TableId { name: name.clone(), local_id };
|
||||
// let edge = Edge {
|
||||
// status: Planned,
|
||||
// src: src_id,
|
||||
// dst: dst_id,
|
||||
// id: table_id.clone(),
|
||||
// keys,
|
||||
// cols,
|
||||
// col_map: BTreeMap::new(),
|
||||
// };
|
||||
// if self.define_new(name.clone(), Structured::Edge(edge)) {
|
||||
// if let Some(Structured::Node(src)) = self.resolve_mut(&src_name) {
|
||||
// src.out_e.push(table_id.clone());
|
||||
// } else {
|
||||
// unreachable!()
|
||||
// }
|
||||
//
|
||||
// if let Some(Structured::Node(dst)) = self.resolve_mut(&dst_name) {
|
||||
// dst.in_e.push(table_id);
|
||||
// } else {
|
||||
// unreachable!()
|
||||
// }
|
||||
// Ok(name)
|
||||
// } else {
|
||||
// Err(NameConflict)
|
||||
// }
|
||||
// }
|
||||
// pub fn build_node_def(&mut self, pair: Pair<Rule>, local_id: usize) -> Result<String> {
|
||||
// let mut inner = pair.into_inner();
|
||||
// let name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let (keys, cols) = self.build_col_defs(inner.next().unwrap())?;
|
||||
// let table_id = TableId { name: name.clone(), local_id };
|
||||
// let node = Node {
|
||||
// status: Planned,
|
||||
// id: table_id,
|
||||
// keys,
|
||||
// cols,
|
||||
// out_e: vec![],
|
||||
// in_e: vec![],
|
||||
// attached: vec![],
|
||||
// col_map: BTreeMap::new(),
|
||||
// };
|
||||
// if self.define_new(name.clone(), Structured::Node(node)) {
|
||||
// Ok(name)
|
||||
// } else {
|
||||
// Err(NameConflict)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn build_col_list(&mut self, pair: Pair<Rule>) -> Result<Vec<String>> {
|
||||
// let mut ret = vec![];
|
||||
// for p in pair.into_inner() {
|
||||
// ret.push(build_name_in_def(p, true)?);
|
||||
// }
|
||||
// Ok(ret)
|
||||
// }
|
||||
// fn build_columns_def(&mut self, pair: Pair<Rule>, local_id: usize) -> Result<String> {
|
||||
// let mut inner = pair.into_inner();
|
||||
// let name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let node_name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let node = self.resolve(&node_name).ok_or(UndefinedType)?;
|
||||
// let node = node.borrow();
|
||||
// let node_id = if let Structured::Node(n) = node {
|
||||
// n.id.clone()
|
||||
// } else if let Structured::Edge(n) = node {
|
||||
// n.id.clone()
|
||||
// } else {
|
||||
// return Err(WrongType);
|
||||
// };
|
||||
// let (keys, cols) = self.build_col_defs(inner.next().unwrap())?;
|
||||
// if !keys.is_empty() {
|
||||
// return Err(UnexpectedIndexColumns);
|
||||
// }
|
||||
// let table_id = TableId { name: name.clone(), local_id };
|
||||
// if table_id.is_global() && !node_id.is_global() {
|
||||
// return Err(IncompatibleEdge);
|
||||
// }
|
||||
//
|
||||
// if self.define_new(name.clone(), Structured::Columns(Columns {
|
||||
// status: Planned,
|
||||
// id: table_id,
|
||||
// attached: node_id,
|
||||
// cols,
|
||||
// })) {
|
||||
// Ok(name)
|
||||
// } else {
|
||||
// Err(NameConflict)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn build_index_def(&mut self, pair: Pair<Rule>, local_id: usize) -> Result<String> {
|
||||
// let mut inner = pair.into_inner();
|
||||
// let mut name = build_name_in_def(inner.next().unwrap(), true)?;
|
||||
// let node_name;
|
||||
// let nxt = inner.next().unwrap();
|
||||
//
|
||||
// let col_list = match nxt.as_rule() {
|
||||
// Rule::col_list => {
|
||||
// node_name = name;
|
||||
// name = "_".to_string() + &node_name;
|
||||
// let cols = self.build_col_list(nxt)?;
|
||||
// name.push('_');
|
||||
// for col in &cols {
|
||||
// name.push('_');
|
||||
// name += col;
|
||||
// }
|
||||
// cols
|
||||
// }
|
||||
// _ => {
|
||||
// node_name = build_name_in_def(nxt, true)?;
|
||||
// self.build_col_list(inner.next().unwrap())?
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// let node = self.resolve(&node_name).ok_or(UndefinedType)?;
|
||||
// let node = node.borrow();
|
||||
// let node_id = if let Structured::Node(n) = node {
|
||||
// n.id.clone()
|
||||
// } else {
|
||||
// return Err(WrongType);
|
||||
// };
|
||||
// let table_id = TableId { name: name.clone(), local_id };
|
||||
//
|
||||
// if table_id.is_global() && !node_id.is_global() {
|
||||
// return Err(IncompatibleEdge);
|
||||
// }
|
||||
//
|
||||
// // TODO: make sure cols make sense
|
||||
//
|
||||
// if self.define_new(name.clone(), Structured::Index(Index {
|
||||
// status: Planned,
|
||||
// id: table_id,
|
||||
// attached: node_id,
|
||||
// cols: col_list,
|
||||
// })) {
|
||||
// Ok(name)
|
||||
// } else {
|
||||
// Err(NameConflict)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub fn build_type_from_str(&self, src: &str) -> Result<Typing> {
|
||||
// let ast = Parser::parse(Rule::typing, src)?.next().unwrap();
|
||||
// self.build_type(ast)
|
||||
// }
|
||||
//
|
||||
// fn build_type(&self, pair: Pair<Rule>) -> Result<Typing> {
|
||||
// let mut pairs = pair.into_inner();
|
||||
// let mut inner = pairs.next().unwrap();
|
||||
// let nullable = if Rule::nullable_marker == inner.as_rule() {
|
||||
// inner = pairs.next().unwrap();
|
||||
// true
|
||||
// } else {
|
||||
// false
|
||||
// };
|
||||
// let t = match inner.as_rule() {
|
||||
// Rule::simple_type => {
|
||||
// let name = parse_ident(inner.into_inner().next().unwrap());
|
||||
// let typ = self.resolve(&name).ok_or(UndefinedType)?;
|
||||
// let typ = typ.borrow();
|
||||
// if let Structured::Typing(t) = typ {
|
||||
// t.clone()
|
||||
// } else {
|
||||
// return Err(UndefinedType);
|
||||
// }
|
||||
// }
|
||||
// Rule::list_type => {
|
||||
// let inner_t = self.build_type(inner.into_inner().next().unwrap())?;
|
||||
// Typing::HList(Box::new(inner_t))
|
||||
// }
|
||||
// // Rule::tuple_type => {},
|
||||
// _ => unreachable!()
|
||||
// };
|
||||
// Ok(if nullable {
|
||||
// Typing::Nullable(Box::new(t))
|
||||
// } else {
|
||||
// t
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// fn build_default_value(&self, _pair: Pair<Rule>) -> Result<StaticValue> {
|
||||
// // TODO: _pair is an expression, parse it and evaluate it to a constant value
|
||||
// Ok(Value::Null)
|
||||
// }
|
||||
//
|
||||
// fn build_col_entry(&self, pair: Pair<Rule>) -> Result<(Col, bool)> {
|
||||
// let mut pairs = pair.into_inner();
|
||||
// let (name, is_key) = parse_col_name(pairs.next().unwrap())?;
|
||||
// let typ = self.build_type(pairs.next().unwrap())?;
|
||||
// let default = if let Some(p) = pairs.next() {
|
||||
// // TODO: check value is suitable for the type
|
||||
// self.build_default_value(p)?
|
||||
// } else {
|
||||
// Value::Null
|
||||
// };
|
||||
// Ok((Col {
|
||||
// name,
|
||||
// typ,
|
||||
// default,
|
||||
// }, is_key))
|
||||
// }
|
||||
//
|
||||
// fn build_col_defs(&self, pair: Pair<Rule>) -> Result<(Vec<Col>, Vec<Col>)> {
|
||||
// let mut keys = vec![];
|
||||
// let mut cols = vec![];
|
||||
// for pair in pair.into_inner() {
|
||||
// let (col, is_key) = self.build_col_entry(pair)?;
|
||||
// if is_key {
|
||||
// keys.push(col)
|
||||
// } else {
|
||||
// cols.push(col)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Ok((keys, cols))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[repr(u8)]
|
||||
// pub enum TableKind {
|
||||
// Node = 1,
|
||||
// Edge = 2,
|
||||
// Columns = 3,
|
||||
// Index = 4,
|
||||
// }
|
||||
//
|
||||
// impl RocksStorage {
|
||||
// #[allow(unused_variables)]
|
||||
// fn all_metadata(&self) -> Result<Vec<Structured>> {
|
||||
// let default_cf = self.db.get_cf_handle("default")?;
|
||||
// let it = self.db.iterator(&default_cf, None);
|
||||
// let mut ret = vec![];
|
||||
// let env = self.root_env.write().expect("Root environment poisoned");
|
||||
// while it.is_valid() {
|
||||
// let k = it.key();
|
||||
// let v = it.value();
|
||||
// let mut key_parser = ByteArrayParser::new(&k);
|
||||
// let mut data_parser = ByteArrayParser::new(&v);
|
||||
// key_parser.parse_varint().unwrap();
|
||||
// let table_name = key_parser.parse_value().unwrap().get_string().unwrap().to_string();
|
||||
// let table_kind = data_parser.parse_value().unwrap();
|
||||
// let table_id = TableId { name: table_name, local_id: 0 };
|
||||
//
|
||||
// match table_kind {
|
||||
// Value::UInt(i) if i == TableKind::Node as u64 => {
|
||||
// let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
||||
// .iter().map(|v| {
|
||||
// let vs = v.get_list().unwrap();
|
||||
// let mut vs = vs.iter();
|
||||
// let name = vs.next().unwrap().get_string().unwrap().to_string();
|
||||
// let typ = vs.next().unwrap().get_string().unwrap();
|
||||
// let typ = env.build_type_from_str(&typ).unwrap();
|
||||
// let default = vs.next().unwrap().owned_clone();
|
||||
// Col {
|
||||
// name,
|
||||
// typ,
|
||||
// default,
|
||||
// }
|
||||
// }).collect();
|
||||
// let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
||||
// .iter().map(|v| {
|
||||
// let vs = v.get_list().unwrap();
|
||||
// let mut vs = vs.iter();
|
||||
// let name = vs.next().unwrap().get_string().unwrap().to_string();
|
||||
// let typ = vs.next().unwrap().get_string().unwrap();
|
||||
// let typ = env.build_type_from_str(&typ).unwrap();
|
||||
// let default = vs.next().unwrap().owned_clone();
|
||||
// Col {
|
||||
// name,
|
||||
// typ,
|
||||
// default,
|
||||
// }
|
||||
// }).collect();
|
||||
// let node = Node {
|
||||
// status: StorageStatus::Stored,
|
||||
// id: table_id,
|
||||
// keys,
|
||||
// cols,
|
||||
// out_e: vec![], // TODO fix these
|
||||
// in_e: vec![],
|
||||
// attached: vec![],
|
||||
// col_map: BTreeMap::new(),
|
||||
// };
|
||||
// ret.push(Structured::Node(node));
|
||||
// }
|
||||
// Value::UInt(i) if i == TableKind::Edge as u64 => {
|
||||
// let src_name = data_parser.parse_value().unwrap().get_string().unwrap().to_string();
|
||||
// let dst_name = data_parser.parse_value().unwrap().get_string().unwrap().to_string();
|
||||
// let src_id = TableId { name: src_name, local_id: 0 };
|
||||
// let dst_id = TableId { name: dst_name, local_id: 0 };
|
||||
// let keys: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
||||
// .iter().map(|v| {
|
||||
// let vs = v.get_list().unwrap();
|
||||
// let mut vs = vs.iter();
|
||||
// let name = vs.next().unwrap().get_string().unwrap().to_string();
|
||||
// let typ = vs.next().unwrap().get_string().unwrap();
|
||||
// let typ = env.build_type_from_str(&typ).unwrap();
|
||||
// let default = vs.next().unwrap().owned_clone();
|
||||
// Col {
|
||||
// name,
|
||||
// typ,
|
||||
// default,
|
||||
// }
|
||||
// }).collect();
|
||||
// let cols: Vec<_> = data_parser.parse_value().unwrap().get_list().unwrap()
|
||||
// .iter().map(|v| {
|
||||
// let vs = v.get_list().unwrap();
|
||||
// let mut vs = vs.iter();
|
||||
// let name = vs.next().unwrap().get_string().unwrap().to_string();
|
||||
// let typ = vs.next().unwrap().get_string().unwrap();
|
||||
// let typ = env.build_type_from_str(&typ).unwrap();
|
||||
// let default = vs.next().unwrap().owned_clone();
|
||||
// Col {
|
||||
// name,
|
||||
// typ,
|
||||
// default,
|
||||
// }
|
||||
// }).collect();
|
||||
// let edge = Edge {
|
||||
// status: StorageStatus::Stored,
|
||||
// src: src_id,
|
||||
// dst: dst_id,
|
||||
// id: table_id,
|
||||
// keys,
|
||||
// cols,
|
||||
// col_map: BTreeMap::new(),
|
||||
// };
|
||||
// ret.push(Structured::Edge(edge));
|
||||
// }
|
||||
// Value::UInt(i) if i == TableKind::Columns as u64 => {
|
||||
// todo!()
|
||||
// }
|
||||
// Value::UInt(i) if i == TableKind::Index as u64 => {
|
||||
// todo!()
|
||||
// }
|
||||
// _ => unreachable!()
|
||||
// }
|
||||
//
|
||||
// it.next();
|
||||
// }
|
||||
// Ok(ret)
|
||||
// }
|
||||
//
|
||||
// fn persist_node(&mut self, node: &mut Node) -> Result<()> {
|
||||
// // let mut key_writer = ByteArrayBuilder::with_capacity(8);
|
||||
// // key_writer.build_varint(0);
|
||||
// // key_writer.build_value(&Value::Text(Arc::new(Cow::from(&node.id.name))));
|
||||
// // let mut val_writer = ByteArrayBuilder::with_capacity(128);
|
||||
// // val_writer.build_value(&Value::UInt(TableKind::Node as u64));
|
||||
// // val_writer.build_value(&Value::List(Arc::new(node.keys.iter().map(|k| {
|
||||
// // Value::List(Arc::new(vec![
|
||||
// // Value::RefString(&k.name),
|
||||
// // Value::OwnString(Arc::new(format!("{}", k.typ))),
|
||||
// // k.default.clone(),
|
||||
// // ]))
|
||||
// // }).collect())));
|
||||
// // val_writer.build_value(&Value::List(Arc::new(node.cols.iter().map(|k| {
|
||||
// // Value::List(Arc::new(vec![
|
||||
// // Value::RefString(&k.name),
|
||||
// // Value::OwnString(Arc::new(format!("{}", k.typ))),
|
||||
// // k.default.clone(),
|
||||
// // ]))
|
||||
// // }).collect())));
|
||||
// //
|
||||
// // self.put_global(&key_writer.get(), &val_writer.get())?;
|
||||
// // node.status = Stored;
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// fn persist_edge(&mut self, edge: &mut Edge) -> Result<()> {
|
||||
// // let mut key_writer = ByteArrayBuilder::with_capacity(8);
|
||||
// // key_writer.build_varint(0);
|
||||
// // key_writer.build_value(&Value::RefString(&edge.id.name));
|
||||
// //
|
||||
// // let mut val_writer = ByteArrayBuilder::with_capacity(128);
|
||||
// // val_writer.build_value(&Value::UInt(TableKind::Edge as u64));
|
||||
// // val_writer.build_value(&Value::RefString(&edge.src.name));
|
||||
// // val_writer.build_value(&Value::RefString(&edge.dst.name));
|
||||
// // val_writer.build_value(&Value::List(Arc::new(edge.keys.iter().map(|k| {
|
||||
// // Value::List(Arc::new(vec![
|
||||
// // Value::RefString(&k.name),
|
||||
// // Value::OwnString(Arc::new(format!("{}", k.typ))),
|
||||
// // k.default.clone(),
|
||||
// // ]))
|
||||
// // }).collect())));
|
||||
// // val_writer.build_value(&Value::List(Arc::new(edge.cols.iter().map(|k| {
|
||||
// // Value::List(Arc::new(vec![
|
||||
// // Value::RefString(&k.name),
|
||||
// // Value::OwnString(Arc::new(format!("{}", k.typ))),
|
||||
// // k.default.clone(),
|
||||
// // ]))
|
||||
// // }).collect())));
|
||||
// //
|
||||
// // self.put_global(&key_writer.get(), &val_writer.get())?;
|
||||
// // edge.status = Stored;
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl Evaluator<RocksStorage> {
|
||||
// pub fn restore_metadata(&mut self) -> Result<()> {
|
||||
// let mds = self.storage.all_metadata()?;
|
||||
// for md in &mds {
|
||||
// match md {
|
||||
// v @ Structured::Node(n) => {
|
||||
// // TODO: check if they are the same if one already exists
|
||||
// self.root_define(n.id.name.clone(), v.clone());
|
||||
// }
|
||||
// v @ Structured::Edge(e) => {
|
||||
// self.root_define(e.id.name.clone(), v.clone());
|
||||
// }
|
||||
// Structured::Columns(_) => {}
|
||||
// Structured::Index(_) => {}
|
||||
// Structured::Typing(_) => unreachable!(),
|
||||
// Structured::Value(_) => unreachable!()
|
||||
// }
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// // fn persist_change(&mut self, tname: &str, global: bool) -> Result<()> {
|
||||
// // self.storage.create_table(tname, global)?;
|
||||
// // let tbl = {
|
||||
// // self.resolve_mut(tname).unwrap()
|
||||
// // };
|
||||
// // if global {
|
||||
// // match tbl {
|
||||
// // Structured::Node(n) => self.storage.persist_node(n),
|
||||
// // Structured::Edge(e) => self.storage.persist_edge(e),
|
||||
// // Structured::Columns(_) => unimplemented!(),
|
||||
// // Structured::Index(_) => unimplemented!(),
|
||||
// // Structured::Typing(_) => panic!(),
|
||||
// // Structured::Value(_) => unreachable!()
|
||||
// // }
|
||||
// // } else {
|
||||
// // Ok(())
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
//
|
||||
// pub fn build_table(&mut self, pairs: Pairs<Rule>) -> Result<()> {
|
||||
// let mut new_tables = vec![];
|
||||
// for pair in pairs {
|
||||
// match pair.as_rule() {
|
||||
// r @ (Rule::global_def | Rule::local_def) => {
|
||||
// let inner = pair.into_inner().next().unwrap();
|
||||
// let global = r == Rule::global_def;
|
||||
// let local_id = self.storage.get_next_local_id(global);
|
||||
// let mut env_to_build =
|
||||
// // if global {
|
||||
// // self.storage.root_env.write().expect("Root environment poisoned").borrow_mut()
|
||||
// // } else {
|
||||
// self.env_stack.last_mut().unwrap()
|
||||
// ;
|
||||
// // };
|
||||
// new_tables.push((global, match inner.as_rule() {
|
||||
// Rule::node_def => {
|
||||
// env_to_build.build_node_def(inner, local_id)?
|
||||
// }
|
||||
// Rule::edge_def => {
|
||||
// env_to_build.build_edge_def(inner, local_id)?
|
||||
// }
|
||||
// Rule::columns_def => {
|
||||
// env_to_build.build_columns_def(inner, local_id)?
|
||||
// }
|
||||
// Rule::index_def => {
|
||||
// env_to_build.build_index_def(inner, local_id)?
|
||||
// }
|
||||
// _ => todo!()
|
||||
// }));
|
||||
// }
|
||||
// Rule::EOI => {}
|
||||
// _ => unreachable!()
|
||||
// }
|
||||
// }
|
||||
// for (global, tname) in &new_tables {
|
||||
// // self.persist_change(tname, *global).unwrap(); // TODO proper error handling
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// pub fn insert_data(&mut self, _pairs: Pairs<Rule>, _bindings: BTreeMap<&str, Value>) -> Result<()> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
// use pest::Parser as PestParser;
|
||||
// use crate::eval::EvaluatorWithStorage;
|
||||
// use crate::parser::Parser;
|
||||
//
|
||||
// fn send_sync<X: Send + Sync>(_x: &X) {}
|
||||
//
|
||||
// #[test]
|
||||
// fn definitions() {
|
||||
// let s = r#"
|
||||
// create node "Person" {
|
||||
// *id: Int,
|
||||
// name: String,
|
||||
// email: ?String,
|
||||
// habits: ?[?String]
|
||||
// }
|
||||
//
|
||||
// create edge (Person)-[Friend]->(Person) {
|
||||
// relation: ?String
|
||||
// }
|
||||
// "#;
|
||||
// let parsed = Parser::parse(Rule::file, s).unwrap();
|
||||
// let db = RocksStorage::new("_path_for_rocksdb_storagex".to_string()).unwrap();
|
||||
// send_sync(&db);
|
||||
// let mut eval = EvaluatorWithStorage::new(db).unwrap();
|
||||
// eval.build_table(parsed).unwrap();
|
||||
// eval.restore_metadata().unwrap();
|
||||
// // eval.storage.delete_storage().unwrap();
|
||||
// println!("{:#?}", eval.resolve("Person"));
|
||||
// println!("{:#?}", eval.resolve("Friend"));
|
||||
// }
|
||||
// }
|
@ -1,61 +0,0 @@
|
||||
// use std::borrow::Cow;
|
||||
// use std::collections::BTreeMap;
|
||||
// use crate::typing::{Structured};
|
||||
//
|
||||
// pub trait Env<V> where V: Clone {
|
||||
// fn define(&mut self, name: String, value: V) -> Option<V>;
|
||||
// fn define_new(&mut self, name: String, value: V) -> bool;
|
||||
// fn resolve(&self, name: &str) -> Option<Cow<V>>;
|
||||
// fn resolve_mut(&mut self, name: &str) -> Option<&mut V>;
|
||||
// fn undef(&mut self, name: &str) -> Option<V>;
|
||||
// }
|
||||
//
|
||||
// pub trait LayeredEnv<V>: Env<V> where V: Clone {
|
||||
// fn root_define(&mut self, name: String, value: V) -> Option<V>;
|
||||
// fn root_define_new(&mut self, name: String, value: V) -> bool;
|
||||
// fn root_resolve(&self, name: &str) -> Option<Cow<V>>;
|
||||
// fn root_undef(&mut self, name: &str) -> Option<V>;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// pub struct Environment {
|
||||
// map: BTreeMap<String, Structured>,
|
||||
// }
|
||||
//
|
||||
//
|
||||
// impl Default for Environment {
|
||||
// fn default() -> Self {
|
||||
// Self { map: BTreeMap::new() }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl Env<Structured> for Environment {
|
||||
// fn define(&mut self, name: String, value: Structured) -> Option<Structured> {
|
||||
// let old = self.map.remove(&name);
|
||||
// self.map.insert(name, value);
|
||||
// old
|
||||
// }
|
||||
//
|
||||
// fn define_new(&mut self, name: String, value: Structured) -> bool {
|
||||
// if let std::collections::btree_map::Entry::Vacant(e) = self.map.entry(name) {
|
||||
// e.insert(value);
|
||||
// true
|
||||
// } else {
|
||||
// false
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn resolve(&self, name: &str) -> Option<Cow<Structured>> {
|
||||
// self.map.get(name)
|
||||
// .map(|v| Cow::Borrowed(v))
|
||||
// }
|
||||
//
|
||||
// fn resolve_mut(&mut self, name: &str) -> Option<&mut Structured> {
|
||||
// self.map.get_mut(name)
|
||||
// }
|
||||
//
|
||||
//
|
||||
// fn undef(&mut self, name: &str) -> Option<Structured> {
|
||||
// self.map.remove(name)
|
||||
// }
|
||||
// }
|
@ -1,72 +0,0 @@
|
||||
// use std::fmt::{Debug, Formatter};
|
||||
// use crate::typing::{Typing};
|
||||
// use crate::value::{StaticValue, Value};
|
||||
// // use lazy_static::lazy_static;
|
||||
//
|
||||
// #[derive(PartialEq, Debug)]
|
||||
// pub struct Function {
|
||||
// pub args: Vec<Arg>,
|
||||
// pub var_arg: Option<Typing>,
|
||||
// pub ret_type: Typing,
|
||||
// pub fn_impl: FunctionImpl,
|
||||
// }
|
||||
//
|
||||
// pub enum FunctionImpl {
|
||||
// Native(&'static str, for<'a> fn(&[Value<'a>]) -> Value<'a>),
|
||||
// UserDefined(()),
|
||||
// }
|
||||
//
|
||||
// impl Debug for FunctionImpl {
|
||||
// fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl PartialEq for FunctionImpl {
|
||||
// fn eq(&self, other: &Self) -> bool {
|
||||
// match (self, other) {
|
||||
// (FunctionImpl::Native(a,_), FunctionImpl::Native(b,_)) => a == b,
|
||||
// (FunctionImpl::UserDefined(a), FunctionImpl::UserDefined(b)) => a == b,
|
||||
// (_, _) => false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(PartialEq, Debug)]
|
||||
// pub struct Arg {
|
||||
// pub typing: Typing,
|
||||
// pub default_val: Option<StaticValue>,
|
||||
// pub name: Option<String>,
|
||||
// }
|
||||
//
|
||||
// // lazy_static! {
|
||||
// // static ref BUILT_IN_FUNCTIONS : BTreeMap<&'static str, Function> = {
|
||||
// // let mut ret = BTreeMap::new();
|
||||
// //
|
||||
// // fn add_int<'a>(_args: &[Value<'a>]) -> Value<'a> {
|
||||
// // todo!()
|
||||
// // }
|
||||
// //
|
||||
// // fn add_float<'a>(_args: &[Value<'a>]) -> Value<'a> {
|
||||
// // todo!()
|
||||
// // }
|
||||
// //
|
||||
// // ret.insert("_add_int",
|
||||
// // Function {
|
||||
// // args: vec![],
|
||||
// // var_arg: Some(Typing::Base(BaseType::Int)),
|
||||
// // ret_type: Typing::Base(BaseType::Int),
|
||||
// // fn_impl: FunctionImpl::Native("_add_int", add_int)
|
||||
// // });
|
||||
// //
|
||||
// // ret.insert("_add_float",
|
||||
// // Function {
|
||||
// // args: vec![],
|
||||
// // var_arg: Some(Typing::Base(BaseType::Float)),
|
||||
// // ret_type: Typing::Base(BaseType::Float),
|
||||
// // fn_impl: FunctionImpl::Native("_add_float", add_float)
|
||||
// // });
|
||||
// //
|
||||
// // ret
|
||||
// // };
|
||||
// // }
|
@ -1,97 +0,0 @@
|
||||
// use std::borrow::Borrow;
|
||||
// use std::collections::BTreeMap;
|
||||
// use pest::iterators::Pair;
|
||||
// use crate::ast::{build_expr, Expr, ExprVisitor};
|
||||
// use crate::definition::build_name_in_def;
|
||||
// use crate::env::Env;
|
||||
// use crate::error::CozoError::{IncompatibleValue, UndefinedTable, ValueRequired};
|
||||
// use crate::eval::Evaluator;
|
||||
// use crate::storage::{RocksStorage};
|
||||
// use crate::error::Result;
|
||||
// use crate::parser::{Parser, Rule};
|
||||
// use crate::typing::Structured;
|
||||
// use crate::value::Value;
|
||||
//
|
||||
// impl Evaluator<RocksStorage> {
|
||||
// pub fn eval_mutation(&mut self, pair: Pair<Rule>) -> Result<()> {
|
||||
// let mut pairs = pair.into_inner();
|
||||
// let op = pairs.next().unwrap().as_rule();
|
||||
// let expr = pairs.next().unwrap();
|
||||
// let main_target;
|
||||
// // let filters;
|
||||
// match pairs.next() {
|
||||
// None => {
|
||||
// main_target = None;
|
||||
// // filters = None;
|
||||
// }
|
||||
// Some(v) => {
|
||||
// match v.as_rule() {
|
||||
// Rule::name_in_def => {
|
||||
// // let resolved = self.resolve(&build_name_in_def(v, true)?)
|
||||
// // .ok_or(UndefinedTable)?.borrow();
|
||||
// // main_target = Some(resolved);
|
||||
// todo!()
|
||||
// }
|
||||
// Rule::mutation_filter => {
|
||||
// main_target = None;
|
||||
// todo!()
|
||||
// }
|
||||
// _ => unreachable!()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// let expr = build_expr(expr)?;
|
||||
// let expr = self.visit_expr(&expr)?;
|
||||
// let val = match expr {
|
||||
// Expr::Const(v) => v,
|
||||
// _ => return Err(ValueRequired)
|
||||
// };
|
||||
// let val = val.get_list().ok_or(IncompatibleValue)?;
|
||||
// println!("{:#?}", val);
|
||||
// let coerced_values = self.coerce_table_values(&val, main_target);
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// fn coerce_table_values(&self, values: &[Value], default_table: Option<&Structured>) -> BTreeMap<&Structured, Vec<Value>> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use std::fs;
|
||||
// use super::*;
|
||||
// use crate::ast::{Expr, ExprVisitor, parse_expr_from_str};
|
||||
// use pest::Parser as PestParser;
|
||||
// use crate::env::Env;
|
||||
// use crate::storage::DummyStorage;
|
||||
// use crate::typing::Structured;
|
||||
//
|
||||
// #[test]
|
||||
// fn data() -> Result<()> {
|
||||
// let ddl = fs::read_to_string("test_data/hr.cozo")?;
|
||||
// let parsed = Parser::parse(Rule::file, &ddl).unwrap();
|
||||
// let db = RocksStorage::new("_path_hr".to_string())?;
|
||||
// let mut eval = Evaluator::new(db).unwrap();
|
||||
// eval.build_table(parsed).unwrap();
|
||||
// eval.restore_metadata().unwrap();
|
||||
//
|
||||
// let insertion = "insert $data;";
|
||||
// let mut insert_stmt = Parser::parse(Rule::mutation, insertion).unwrap();
|
||||
//
|
||||
// let data = fs::read_to_string("test_data/hr.json")?;
|
||||
// let parsed = parse_expr_from_str(&data)?;
|
||||
// let ev = Evaluator::new(DummyStorage {})?;
|
||||
// let evaluated = ev.visit_expr(&parsed)?;
|
||||
// let bound_value = match evaluated {
|
||||
// Expr::Const(v) => v,
|
||||
// _ => unreachable!()
|
||||
// };
|
||||
//
|
||||
// eval.define("$data".to_string(), Structured::Value(bound_value.owned_clone()));
|
||||
// eval.eval_mutation(insert_stmt.next().unwrap()).unwrap();
|
||||
// // println!("{:#?}", evaluated);
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
@ -1,141 +0,0 @@
|
||||
// use std::fs;
|
||||
// use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
// use std::sync::{RwLock};
|
||||
// use crate::error::{CozoError, Result};
|
||||
// use cozo_rocks::*;
|
||||
// use crate::env::Environment;
|
||||
// use crate::value::{cozo_comparator_v1};
|
||||
//
|
||||
//
|
||||
// pub struct RocksStorage {
|
||||
// pub db: DB,
|
||||
// #[allow(dead_code)]
|
||||
// path: String,
|
||||
// last_local_id: AtomicUsize,
|
||||
// pub root_env: RwLock<Environment>,
|
||||
// }
|
||||
//
|
||||
// const DEFAULT_CF: &str = "default";
|
||||
// const SCRATCH_CF: &str = "scratch";
|
||||
// const COMPARATOR_NAME: &str = "cozo_comparator_v1";
|
||||
//
|
||||
// impl RocksStorage {
|
||||
// #[allow(unused_variables)]
|
||||
// pub fn new(path: String) -> Result<Self> {
|
||||
// let options = Options::default()
|
||||
// .increase_parallelism()
|
||||
// .optimize_level_style_compaction()
|
||||
// .set_create_if_missing(true)
|
||||
// .set_comparator(COMPARATOR_NAME, cozo_comparator_v1);
|
||||
//
|
||||
// let db = DB::open(options, path.as_ref())?;
|
||||
// (match db.create_column_family(SCRATCH_CF) {
|
||||
// Err(s) if s.bridge_code == StatusBridgeCode::EXISTING_ERROR => Ok(()),
|
||||
// v => v
|
||||
// })?;
|
||||
// let mut env = Environment::default();
|
||||
// env.define_base_types();
|
||||
// Ok(RocksStorage {
|
||||
// db,
|
||||
// path,
|
||||
// last_local_id: AtomicUsize::new(0),
|
||||
// root_env: RwLock::new(env),
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// #[allow(unused_variables)]
|
||||
// pub fn delete_storage(self) -> Result<()> {
|
||||
// let path = self.path.clone();
|
||||
// drop(self);
|
||||
// fs::remove_dir_all(path)?;
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// #[allow(unused_variables)]
|
||||
// pub fn put_global(&self, k: &[u8], v: &[u8]) -> Result<()> {
|
||||
// let default_cf = self.db.get_cf_handle(DEFAULT_CF)?;
|
||||
// self.db.put(k, v, &default_cf, None)?;
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
// #[allow(unused_variables)]
|
||||
// pub fn create_table(&self, name: &str, _global: bool) -> Result<()> {
|
||||
// match self.db.create_column_family(table_name_to_cf_name(name)) {
|
||||
// Ok(_) => Ok(()),
|
||||
// Err(s) if s.bridge_code == StatusBridgeCode::EXISTING_ERROR => Ok(()),
|
||||
// Err(e) => Err(CozoError::Storage(e))
|
||||
// }
|
||||
// }
|
||||
// #[allow(unused_variables)]
|
||||
// pub fn drop_table(&self, name: &str, _global: bool) -> Result<()> {
|
||||
// self.db.drop_column_family(table_name_to_cf_name(name))?;
|
||||
// Ok(())
|
||||
// }
|
||||
//
|
||||
// pub fn get_next_local_id(&self, global: bool) -> usize {
|
||||
// if global {
|
||||
// 0
|
||||
// } else {
|
||||
// self.last_local_id.fetch_add(1, Ordering::Relaxed) + 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// fn table_name_to_cf_name(name: &str) -> String {
|
||||
// format!("${}", name)
|
||||
// }
|
||||
//
|
||||
// pub trait Storage {}
|
||||
//
|
||||
// pub struct DummyStorage;
|
||||
//
|
||||
// impl Storage for DummyStorage {}
|
||||
//
|
||||
// impl Storage for RocksStorage {}
|
||||
//
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use std::str::from_utf8;
|
||||
// use crate::value::{ByteArrayBuilder, cozo_comparator_v1, Value};
|
||||
//
|
||||
// // #[test]
|
||||
// // fn import() {
|
||||
// // use cozo_rocks::*;
|
||||
// // let options = Options::default()
|
||||
// // .increase_parallelism()
|
||||
// // .optimize_level_style_compaction()
|
||||
// // .set_create_if_missing(true)
|
||||
// // .set_comparator("cozo_comparator_v1", cozo_comparator_v1);
|
||||
// //
|
||||
// // let db = DB::open(options,
|
||||
// // "xxyyzz.db".as_ref()).unwrap();
|
||||
// //
|
||||
// // let mut builder = ByteArrayBuilder::default();
|
||||
// // builder.build_value(&Value::RefString("A key"));
|
||||
// // let key = builder;
|
||||
// //
|
||||
// // let mut builder = ByteArrayBuilder::default();
|
||||
// // builder.build_value(&Value::RefString("Another key"));
|
||||
// // let key2 = builder;
|
||||
// // let cf = db.get_cf_handle("default").unwrap();
|
||||
// // println!("{:?}", db.all_cf_names());
|
||||
// //
|
||||
// // let val = db.get(&key, &cf, None).unwrap();
|
||||
// // println!("before anything {}", val.is_none());
|
||||
// //
|
||||
// // db.put(&key, "A motherfucking value!!! 👋👋👋", &cf, None).unwrap();
|
||||
// // let batch = WriteBatch::default();
|
||||
// // batch.put(&key2, "Another motherfucking value!!! 👋👋👋", &cf).unwrap();
|
||||
// // db.write(batch, None).unwrap();
|
||||
// // // db.put("Yes man", "A motherfucking value!!! 👋👋👋", None).unwrap();
|
||||
// // let val = db.get(&key, &cf, None).unwrap().unwrap();
|
||||
// // println!("1 {}", from_utf8(val.as_ref()).unwrap());
|
||||
// // let val = db.get(&key2, &cf, None).unwrap().unwrap();
|
||||
// // // let val = val.as_bytes();
|
||||
// // println!("2 {}", from_utf8(val.as_ref()).unwrap());
|
||||
// // let val = db.get(&key, &cf, None).unwrap().unwrap();
|
||||
// // println!("3 {}", from_utf8(val.as_ref()).unwrap());
|
||||
// // println!("4 {}", from_utf8(db.get(&key, &cf, None).unwrap().unwrap().as_ref()).unwrap());
|
||||
// // }
|
||||
// }
|
@ -1,256 +0,0 @@
|
||||
// use std::collections::BTreeMap;
|
||||
// use std::fmt::{Debug, Display, Formatter, Write};
|
||||
// use crate::env::{Env, Environment};
|
||||
// use crate::value::{StaticValue, Value};
|
||||
//
|
||||
// #[derive(Debug, Eq, PartialEq, Clone)]
|
||||
// pub enum BaseType {
|
||||
// Bool,
|
||||
// Int,
|
||||
// UInt,
|
||||
// Float,
|
||||
// String,
|
||||
// BitArr,
|
||||
// U8Arr,
|
||||
// I8Arr,
|
||||
// I16Arr,
|
||||
// U16Arr,
|
||||
// I32Arr,
|
||||
// U32Arr,
|
||||
// I64Arr,
|
||||
// U64Arr,
|
||||
// F16Arr,
|
||||
// F32Arr,
|
||||
// F64Arr,
|
||||
// C32Arr,
|
||||
// C64Arr,
|
||||
// C128Arr,
|
||||
// Uuid,
|
||||
// Timestamp,
|
||||
// Datetime,
|
||||
// Timezone,
|
||||
// Date,
|
||||
// Time,
|
||||
// Duration,
|
||||
// BigInt,
|
||||
// BigDecimal,
|
||||
// Inet,
|
||||
// Crs,
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub struct Col {
|
||||
// pub name: String,
|
||||
// pub typ: Typing,
|
||||
// pub default: StaticValue,
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Clone)]
|
||||
// pub enum StorageStatus {
|
||||
// Planned,
|
||||
// Verified,
|
||||
// Stored,
|
||||
// }
|
||||
//
|
||||
// #[derive(PartialEq, Eq, Ord, PartialOrd, Clone)]
|
||||
// pub struct TableId {
|
||||
// pub name: String,
|
||||
// pub local_id: usize,
|
||||
// }
|
||||
//
|
||||
// impl TableId {
|
||||
// pub fn is_global(&self) -> bool {
|
||||
// self.local_id == 0
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// impl Debug for TableId {
|
||||
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// f.write_str(&self.name)?;
|
||||
// if self.local_id > 0 {
|
||||
// f.write_str(&format!("({})", self.local_id))?;
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(Ord, PartialOrd, Eq, PartialEq, Clone)]
|
||||
// pub struct ColumnId {
|
||||
// table_id: TableId,
|
||||
// is_key: bool,
|
||||
// col_order: usize,
|
||||
// }
|
||||
//
|
||||
// impl Debug for ColumnId {
|
||||
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// f.write_str(&format!("{:?}", self.table_id))?;
|
||||
// if self.is_key {
|
||||
// f.write_char('*')?;
|
||||
// } else {
|
||||
// f.write_char('-')?;
|
||||
// }
|
||||
// f.write_str(&format!("{}", self.col_order))?;
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub struct Node {
|
||||
// pub status: StorageStatus,
|
||||
// pub id: TableId,
|
||||
// pub keys: Vec<Col>,
|
||||
// pub cols: Vec<Col>,
|
||||
// pub out_e: Vec<TableId>,
|
||||
// pub in_e: Vec<TableId>,
|
||||
// pub attached: Vec<TableId>,
|
||||
// pub col_map: BTreeMap<String, ColumnId>,
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub struct Edge {
|
||||
// pub status: StorageStatus,
|
||||
// pub src: TableId,
|
||||
// pub dst: TableId,
|
||||
// pub id: TableId,
|
||||
// pub keys: Vec<Col>,
|
||||
// pub cols: Vec<Col>,
|
||||
// pub col_map: BTreeMap<String, ColumnId>,
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub struct Columns {
|
||||
// pub status: StorageStatus,
|
||||
// pub attached: TableId,
|
||||
// pub id: TableId,
|
||||
// pub cols: Vec<Col>,
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub struct Index {
|
||||
// pub status: StorageStatus,
|
||||
// pub id: TableId,
|
||||
// pub attached: TableId,
|
||||
// pub cols: Vec<String>,
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[derive(Eq, PartialEq, Clone)]
|
||||
// pub enum Typing {
|
||||
// Any,
|
||||
// Base(BaseType),
|
||||
// HList(Box<Typing>),
|
||||
// Nullable(Box<Typing>),
|
||||
// Tuple(Vec<Typing>),
|
||||
// NamedTuple(BTreeMap<String, Typing>),
|
||||
// }
|
||||
//
|
||||
// impl Display for Typing {
|
||||
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// match self {
|
||||
// Typing::Any => f.write_str("Any")?,
|
||||
// Typing::Base(b) => {
|
||||
// match b {
|
||||
// BaseType::Bool => f.write_str("Bool")?,
|
||||
// BaseType::Int => f.write_str("Int")?,
|
||||
// BaseType::UInt => f.write_str("UInt")?,
|
||||
// BaseType::Float => f.write_str("Float")?,
|
||||
// BaseType::String => f.write_str("String")?,
|
||||
// BaseType::BitArr => f.write_str("BitArr")?,
|
||||
// BaseType::U8Arr => f.write_str("U8Arr")?,
|
||||
// BaseType::I8Arr => f.write_str("I8Arr")?,
|
||||
// BaseType::I16Arr => f.write_str("I16Arr")?,
|
||||
// BaseType::U16Arr => f.write_str("U16Arr")?,
|
||||
// BaseType::I32Arr => f.write_str("I32Arr")?,
|
||||
// BaseType::U32Arr => f.write_str("U32Arr")?,
|
||||
// BaseType::I64Arr => f.write_str("I64Arr")?,
|
||||
// BaseType::U64Arr => f.write_str("U64Arr")?,
|
||||
// BaseType::F16Arr => f.write_str("F16Arr")?,
|
||||
// BaseType::F32Arr => f.write_str("F32Arr")?,
|
||||
// BaseType::F64Arr => f.write_str("F64Arr")?,
|
||||
// BaseType::C32Arr => f.write_str("C32Arr")?,
|
||||
// BaseType::C64Arr => f.write_str("C64Arr")?,
|
||||
// BaseType::C128Arr => f.write_str("C128Arr")?,
|
||||
// BaseType::Uuid => f.write_str("Uuid")?,
|
||||
// BaseType::Timestamp => f.write_str("Timestamp")?,
|
||||
// BaseType::Datetime => f.write_str("Datetime")?,
|
||||
// BaseType::Timezone => f.write_str("Timezone")?,
|
||||
// BaseType::Date => f.write_str("Date")?,
|
||||
// BaseType::Time => f.write_str("Time")?,
|
||||
// BaseType::Duration => f.write_str("Duration")?,
|
||||
// BaseType::BigInt => f.write_str("BigInt")?,
|
||||
// BaseType::BigDecimal => f.write_str("BigDecimal")?,
|
||||
// BaseType::Inet => f.write_str("Inet")?,
|
||||
// BaseType::Crs => f.write_str("Crs")?
|
||||
// }
|
||||
// }
|
||||
// Typing::HList(l) => {
|
||||
// f.write_char('[')?;
|
||||
// Display::fmt(l, f)?;
|
||||
// f.write_char(']')?;
|
||||
// }
|
||||
// Typing::Nullable(d) => {
|
||||
// f.write_char('?')?;
|
||||
// Display::fmt(d, f)?;
|
||||
// }
|
||||
// Typing::Tuple(_) => todo!(),
|
||||
// Typing::NamedTuple(_) => todo!()
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl Debug for Typing {
|
||||
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
// Display::fmt(self, f)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, PartialEq, Clone)]
|
||||
// pub enum Structured {
|
||||
// Typing(Typing),
|
||||
// Node(Node),
|
||||
// Edge(Edge),
|
||||
// Columns(Columns),
|
||||
// Index(Index),
|
||||
// Value(StaticValue),
|
||||
// }
|
||||
//
|
||||
// impl Structured {
|
||||
// pub fn storage_id(&self) -> Option<TableId> {
|
||||
// match self {
|
||||
// Structured::Typing(_) => None,
|
||||
// Structured::Node(n) => Some(n.id.clone()),
|
||||
// Structured::Edge(e) => Some(e.id.clone()),
|
||||
// Structured::Columns(c) => Some(c.id.clone()),
|
||||
// Structured::Index(i) => Some(i.id.clone()),
|
||||
// Structured::Value(_) => None
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl Environment {
|
||||
// pub fn define_base_types(&mut self) {
|
||||
// self.define("Any".to_string(), Structured::Typing(Typing::Any));
|
||||
// self.define("Bool".to_string(), Structured::Typing(Typing::Base(BaseType::Bool)));
|
||||
// self.define("Int".to_string(), Structured::Typing(Typing::Base(BaseType::Int)));
|
||||
// self.define("UInt".to_string(), Structured::Typing(Typing::Base(BaseType::UInt)));
|
||||
// self.define("Float".to_string(), Structured::Typing(Typing::Base(BaseType::Float)));
|
||||
// self.define("String".to_string(), Structured::Typing(Typing::Base(BaseType::String)));
|
||||
// self.define("Bytes".to_string(), Structured::Typing(Typing::Base(BaseType::U8Arr)));
|
||||
// self.define("U8Arr".to_string(), Structured::Typing(Typing::Base(BaseType::U8Arr)));
|
||||
// self.define("Uuid".to_string(), Structured::Typing(Typing::Base(BaseType::Uuid)));
|
||||
// self.define("Timestamp".to_string(), Structured::Typing(Typing::Base(BaseType::Timestamp)));
|
||||
// self.define("Datetime".to_string(), Structured::Typing(Typing::Base(BaseType::Datetime)));
|
||||
// self.define("Timezone".to_string(), Structured::Typing(Typing::Base(BaseType::Timezone)));
|
||||
// self.define("Date".to_string(), Structured::Typing(Typing::Base(BaseType::Date)));
|
||||
// self.define("Time".to_string(), Structured::Typing(Typing::Base(BaseType::Time)));
|
||||
// self.define("Duration".to_string(), Structured::Typing(Typing::Base(BaseType::Duration)));
|
||||
// self.define("BigInt".to_string(), Structured::Typing(Typing::Base(BaseType::BigInt)));
|
||||
// self.define("BigDecimal".to_string(), Structured::Typing(Typing::Base(BaseType::BigDecimal)));
|
||||
// self.define("Int".to_string(), Structured::Typing(Typing::Base(BaseType::Int)));
|
||||
// self.define("Crs".to_string(), Structured::Typing(Typing::Base(BaseType::Crs)));
|
||||
// }
|
||||
// }
|
@ -1,637 +0,0 @@
|
||||
// use std::borrow::{Cow};
|
||||
// use std::cmp::{min, Ordering};
|
||||
// use std::collections::{BTreeMap};
|
||||
// use std::io::{Write};
|
||||
// use ordered_float::OrderedFloat;
|
||||
// use uuid::Uuid;
|
||||
// use crate::typing::{Typing};
|
||||
// use Ordering::{Greater, Less, Equal};
|
||||
// use std::sync::Arc;
|
||||
//
|
||||
// // TODO: array types, alignment of values
|
||||
// #[repr(u8)]
|
||||
// #[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||
// pub enum ValueTag {
|
||||
// BoolFalseTag = 0,
|
||||
// NullTag = 2,
|
||||
// BoolTrueTag = 4,
|
||||
// FwdEdgeTag = 6,
|
||||
// BwdEdgeTag = 8,
|
||||
// IntTag = 11,
|
||||
// FloatTag = 13,
|
||||
// StringTag = 15,
|
||||
// UuidTag = 17,
|
||||
// UIntTag = 21,
|
||||
// // TimestampTag = 23,
|
||||
// // DatetimeTag = 25,
|
||||
// // TimezoneTag = 27,
|
||||
// // DateTag = 27,
|
||||
// // TimeTag = 29,
|
||||
// // DurationTag = 31,
|
||||
// // BigIntTag = 51,
|
||||
// // BigDecimalTag = 53,
|
||||
// // InetTag = 55,
|
||||
// // CrsTag = 57,
|
||||
// // BitArrTag = 60,
|
||||
// // U8ArrTag = 61,
|
||||
// // I8ArrTag = 62,
|
||||
// // U16ArrTag = 63,
|
||||
// // I16ArrTag = 64,
|
||||
// // U32ArrTag = 65,
|
||||
// // I32ArrTag = 66,
|
||||
// // U64ArrTag = 67,
|
||||
// // I64ArrTag = 68,
|
||||
// // F16ArrTag = 69,
|
||||
// // F32ArrTag = 70,
|
||||
// // F64ArrTag = 71,
|
||||
// // C32ArrTag = 72,
|
||||
// // C64ArrTag = 73,
|
||||
// // C128ArrTag = 74,
|
||||
// ListTag = 101,
|
||||
// DictTag = 103,
|
||||
// }
|
||||
//
|
||||
// #[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
// pub enum EdgeDirKind {
|
||||
// FwdEdgeDir,
|
||||
// BwdEdgeDir,
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub enum Value<'a> {
|
||||
// Null,
|
||||
// Bool(bool),
|
||||
// EdgeDir(EdgeDirKind),
|
||||
// UInt(u64),
|
||||
// Int(i64),
|
||||
// Float(f64),
|
||||
// Uuid(Uuid),
|
||||
// Text(Arc<Cow<'a, str>>),
|
||||
// List(Arc<Vec<Value<'a>>>),
|
||||
// Dict(Arc<BTreeMap<Cow<'a, str>, Value<'a>>>),
|
||||
// }
|
||||
//
|
||||
// pub type StaticValue = Value<'static>;
|
||||
//
|
||||
// impl<'a> Value<'a> {
|
||||
// pub fn get_list(&self) -> Option<Arc<Vec<Self>>> {
|
||||
// match self {
|
||||
// Value::List(v) => Some(v.clone()),
|
||||
// _ => None
|
||||
// }
|
||||
// }
|
||||
// pub fn get_string(&self) -> Option<Arc<String>> {
|
||||
// match self {
|
||||
// Value::Text(v) => todo!(),
|
||||
// // Value::Text(v) => Some(Arc::new(v.clone().into_owned())),
|
||||
// _ => None
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl<'a> PartialEq for Value<'a> {
|
||||
// fn eq(&self, other: &Self) -> bool {
|
||||
// use Value::*;
|
||||
//
|
||||
// match (self, other) {
|
||||
// (Null, Null) => true,
|
||||
// (Bool(a), Bool(b)) => a == b,
|
||||
// (EdgeDir(a), EdgeDir(b)) => a == b,
|
||||
// (UInt(a), UInt(b)) => a == b,
|
||||
// (Int(a), Int(b)) => a == b,
|
||||
// (Float(a), Float(b)) => a == b,
|
||||
// (Uuid(a), Uuid(b)) => a == b,
|
||||
// (Text(a), Text(b)) => a == b,
|
||||
// (List(a), List(b)) => a == b,
|
||||
// (Dict(a), Dict(b)) => a == b,
|
||||
// _ => false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub struct ByteArrayParser<'a> {
|
||||
// bytes: &'a [u8],
|
||||
// current: usize,
|
||||
// }
|
||||
//
|
||||
// impl<'a> ByteArrayParser<'a> {
|
||||
// pub fn new<T: AsRef<[u8]>>(source: &'a T) -> Self {
|
||||
// Self { bytes: source.as_ref(), current: 0 }
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// fn advance(&mut self, n: usize) -> Option<&'a [u8]> {
|
||||
// let cur = self.current;
|
||||
// if n + cur > self.bytes.len() {
|
||||
// None
|
||||
// } else {
|
||||
// self.current += n;
|
||||
// Some(&self.bytes[cur..cur + n])
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// fn at_end(&self) -> bool {
|
||||
// self.current == self.bytes.len()
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_varint(&mut self) -> Option<u64> {
|
||||
// let mut u: u64 = 0;
|
||||
// let mut shift = 0;
|
||||
// loop {
|
||||
// let buf = self.advance(1)?[0];
|
||||
// u |= ((buf & 0b01111111) as u64) << shift;
|
||||
// if buf & 0b10000000 == 0 {
|
||||
// break;
|
||||
// }
|
||||
// shift += 7;
|
||||
// }
|
||||
// Some(u)
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_value_tag(&mut self) -> Option<ValueTag> {
|
||||
// use ValueTag::*;
|
||||
//
|
||||
// let u = self.parse_varint()?;
|
||||
// match u {
|
||||
// u if u == NullTag as u64 => Some(NullTag),
|
||||
// u if u == BoolTrueTag as u64 => Some(BoolTrueTag),
|
||||
// u if u == BoolFalseTag as u64 => Some(BoolFalseTag),
|
||||
// u if u == FwdEdgeTag as u64 => Some(FwdEdgeTag),
|
||||
// u if u == BwdEdgeTag as u64 => Some(BwdEdgeTag),
|
||||
// u if u == IntTag as u64 => Some(IntTag),
|
||||
// u if u == FloatTag as u64 => Some(FloatTag),
|
||||
// u if u == StringTag as u64 => Some(StringTag),
|
||||
// u if u == UIntTag as u64 => Some(UIntTag),
|
||||
// u if u == ListTag as u64 => Some(ListTag),
|
||||
// u if u == DictTag as u64 => Some(DictTag),
|
||||
// u if u == UuidTag as u64 => Some(UuidTag),
|
||||
// _ => None
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn compare_varint(&mut self, other: &mut Self) -> Ordering {
|
||||
// self.parse_varint().expect(
|
||||
// "Failed to parse VarInt when comparing"
|
||||
// ).cmp(&other.parse_varint().expect(
|
||||
// "Failed to parse VarInt when comparing"
|
||||
// ))
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_zigzag(&mut self) -> Option<i64> {
|
||||
// let u = self.parse_varint()?;
|
||||
// Some(if u & 1 == 0 {
|
||||
// (u >> 1) as i64
|
||||
// } else {
|
||||
// -((u >> 1) as i64) - 1
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn compare_zigzag(&mut self, other: &mut Self) -> Ordering {
|
||||
// self.parse_zigzag().expect(
|
||||
// "Failed to parse ZigZag when comparing"
|
||||
// ).cmp(&other.parse_zigzag().expect(
|
||||
// "Failed to parse ZigZag when comparing"
|
||||
// ))
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_float(&mut self) -> Option<f64> {
|
||||
// let buf = self.advance(8)?.try_into().ok()?;
|
||||
// Some(f64::from_be_bytes(buf))
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_uuid(&mut self) -> Option<Uuid> {
|
||||
// Uuid::from_slice(self.advance(16)?).ok()
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn compare_float(&mut self, other: &mut Self) -> Ordering {
|
||||
// OrderedFloat(self.parse_float().expect(
|
||||
// "Failed to parse Float when comparing"
|
||||
// )).cmp(&OrderedFloat(other.parse_float().expect(
|
||||
// "Failed to parse Float when comparing"
|
||||
// )))
|
||||
// }
|
||||
// // This should first compare UUID version, then for V1, compare the timestamps
|
||||
// #[inline]
|
||||
// pub fn compare_uuid(&mut self, other: &mut Self) -> Ordering {
|
||||
// let ua = self.parse_uuid().expect(
|
||||
// "Failed to parse Uuid when comparing"
|
||||
// );
|
||||
// let (a3, a2, a1, a4) = ua.as_fields();
|
||||
// let ub = other.parse_uuid().expect(
|
||||
// "Failed to parse Uuid when comparing"
|
||||
// );
|
||||
// let (b3, b2, b1, b4) = ub.as_fields();
|
||||
// if let x @ (Greater | Less) = a1.cmp(&b1) { return x; }
|
||||
// if let x @ (Greater | Less) = a2.cmp(&b2) { return x; }
|
||||
// if let x @ (Greater | Less) = a3.cmp(&b3) { return x; }
|
||||
// a4.cmp(b4)
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn parse_string(&mut self) -> Option<&'a str> {
|
||||
// let l = self.parse_varint()?;
|
||||
// let bytes = self.advance(l as usize)?;
|
||||
// // unsafe {
|
||||
// // Some(std::str::from_utf8_unchecked(bytes))
|
||||
// // }
|
||||
// std::str::from_utf8(bytes).ok()
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn compare_string(&mut self, other: &mut Self) -> Ordering {
|
||||
// let len_a = self.parse_varint().expect("Failed to get String length when comparing");
|
||||
// let len_b = other.parse_varint().expect("Failed to get String length when comparing");
|
||||
// for _ in 0..min(len_a, len_b) {
|
||||
// let byte_a = self.advance(1).expect("Unexpected end of String when comparing")[0];
|
||||
// let byte_b = other.advance(1).expect("Unexpected end of String when comparing")[0];
|
||||
// if let x @ (Greater | Less) = byte_a.cmp(&byte_b) { return x; }
|
||||
// }
|
||||
// len_a.cmp(&len_b)
|
||||
// }
|
||||
// pub fn parse_list(&mut self) -> Option<Vec<Value<'a>>> {
|
||||
// let l = self.parse_varint()?;
|
||||
// let mut ret = Vec::with_capacity(l as usize);
|
||||
// for _ in 0..l {
|
||||
// let val = self.parse_value()?;
|
||||
// ret.push(val);
|
||||
// }
|
||||
// Some(ret)
|
||||
// }
|
||||
// pub fn parse_value(&mut self) -> Option<Value<'a>> {
|
||||
// use ValueTag::*;
|
||||
// use Value::*;
|
||||
// use EdgeDirKind::*;
|
||||
//
|
||||
// match self.parse_value_tag()? {
|
||||
// NullTag => Some(Null),
|
||||
// BoolTrueTag => Some(Bool(true)),
|
||||
// BoolFalseTag => Some(Bool(false)),
|
||||
// FwdEdgeTag => Some(EdgeDir(FwdEdgeDir)),
|
||||
// BwdEdgeTag => Some(EdgeDir(BwdEdgeDir)),
|
||||
// IntTag => Some(Int(self.parse_zigzag()?)),
|
||||
// FloatTag => Some(Float(self.parse_float()?)),
|
||||
// StringTag => Some(Text(Arc::new(Cow::from(self.parse_string()?)))),
|
||||
// UIntTag => Some(UInt(self.parse_varint()?)),
|
||||
// ListTag => Some(List(Arc::new(self.parse_list()?))),
|
||||
// DictTag => Some(Dict(Arc::new(self.parse_dict()?))),
|
||||
// UuidTag => Some(Uuid(self.parse_uuid()?))
|
||||
// }
|
||||
// }
|
||||
// pub fn compare_value(&mut self, other: &mut Self) -> Ordering {
|
||||
// use ValueTag::*;
|
||||
//
|
||||
// match (self.parse_value_tag(), other.parse_value_tag()) {
|
||||
// (None, None) => Equal,
|
||||
// (None, Some(_)) => Less,
|
||||
// (Some(_), None) => Greater,
|
||||
// (Some(type_a), Some(type_b)) => {
|
||||
// if let x @ (Greater | Less) = type_a.cmp(&type_b) { return x; }
|
||||
// match type_a {
|
||||
// IntTag => self.compare_zigzag(other),
|
||||
// FloatTag => self.compare_float(other),
|
||||
// StringTag => self.compare_string(other),
|
||||
// UIntTag => self.compare_varint(other),
|
||||
// ListTag => self.compare_list(other),
|
||||
// DictTag => self.compare_dict(other),
|
||||
// UuidTag => self.compare_uuid(other),
|
||||
// NullTag | BoolTrueTag | BoolFalseTag | FwdEdgeTag | BwdEdgeTag => Equal
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// pub fn compare_list(&mut self, other: &mut Self) -> Ordering {
|
||||
// let len_a = self.parse_varint().expect("Failed to get List length when comparing");
|
||||
// let len_b = other.parse_varint().expect("Failed to get List length when comparing");
|
||||
// for _ in 0..min(len_a, len_b) {
|
||||
// if let x @ (Greater | Less) = self.compare_value(other) { return x; }
|
||||
// }
|
||||
// len_a.cmp(&len_b)
|
||||
// }
|
||||
// pub fn parse_dict(&mut self) -> Option<BTreeMap<Cow<'a, str>, Value<'a>>> {
|
||||
// let l = self.parse_varint()?;
|
||||
// let mut ret = BTreeMap::new();
|
||||
//
|
||||
// for _ in 0..l {
|
||||
// let key = Cow::from(self.parse_string()?);
|
||||
// let val = self.parse_value()?;
|
||||
// ret.insert(key, val);
|
||||
// }
|
||||
// Some(ret)
|
||||
// }
|
||||
// pub fn compare_dict(&mut self, other: &mut Self) -> Ordering {
|
||||
// let len_a = self.parse_varint().expect("Failed to get Dict length when comparing");
|
||||
// let len_b = other.parse_varint().expect("Failed to get Dict length when comparing");
|
||||
// for _ in 0..min(len_a, len_b) {
|
||||
// if let x @ (Greater | Less) = self.compare_string(other) { return x; }
|
||||
// if let x @ (Greater | Less) = self.compare_value(other) { return x; }
|
||||
// }
|
||||
// len_a.cmp(&len_b)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub struct ByteArrayBuilder<T: Write + AsRef<[u8]>> {
|
||||
// byte_writer: T,
|
||||
// }
|
||||
//
|
||||
// impl<T: Write + AsRef<[u8]>> AsRef<[u8]> for ByteArrayBuilder<T> {
|
||||
// fn as_ref(&self) -> &[u8] {
|
||||
// self.byte_writer.as_ref()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl ByteArrayBuilder<Vec<u8>> {
|
||||
// pub fn default() -> Self { Self { byte_writer: vec![] } }
|
||||
// pub fn with_capacity(size: usize) -> Self {
|
||||
// Self::new(Vec::with_capacity(size))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl<T: Write + AsRef<[u8]>> ByteArrayBuilder<T> {
|
||||
// pub fn get(self) -> T {
|
||||
// self.byte_writer
|
||||
// }
|
||||
//
|
||||
// pub fn new(byte_writer: T) -> Self {
|
||||
// Self { byte_writer }
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_varint(&mut self, u: u64) -> &mut Self {
|
||||
// let mut u = u;
|
||||
// while u > 0b01111111 {
|
||||
// self.byte_writer.write_all(&[0b10000000 | (u as u8 & 0b01111111)]).expect(
|
||||
// "Failed to write when building VarInt"
|
||||
// );
|
||||
// u >>= 7;
|
||||
// }
|
||||
// self.byte_writer.write_all(&[u as u8]).expect(
|
||||
// "Failed to write when building Varint"
|
||||
// );
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_zigzag(&mut self, i: i64) -> &mut Self {
|
||||
// let u: u64 = if i >= 0 {
|
||||
// (i as u64) << 1
|
||||
// } else {
|
||||
// // Convoluted, to prevent overflow when calling .abs()
|
||||
// (((i + 1).abs() as u64) << 1) + 1
|
||||
// };
|
||||
// self.build_varint(u);
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_float(&mut self, f: f64) -> &mut Self {
|
||||
// self.byte_writer.write_all(&f.to_be_bytes()).expect(
|
||||
// "Failed to write when building Float"
|
||||
// );
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_uuid(&mut self, u: Uuid) -> &mut Self {
|
||||
// self.byte_writer.write_all(u.as_bytes()).expect(
|
||||
// "Failed to write when building Uuid"
|
||||
// );
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_string(&mut self, s: &str) -> &mut Self {
|
||||
// self.build_varint(s.len() as u64);
|
||||
// self.byte_writer.write_all(s.as_bytes()).expect("Failed to write when building String");
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// #[inline]
|
||||
// pub fn build_tag(&mut self, t: ValueTag) -> &mut Self {
|
||||
// self.byte_writer.write_all(&[t as u8]).expect("Failed to write when building Tag");
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// pub fn build_value(&mut self, v: &Value) -> &mut Self {
|
||||
// use ValueTag::*;
|
||||
//
|
||||
// match v {
|
||||
// Value::Null => self.build_tag(NullTag),
|
||||
// Value::Bool(b) => self.build_tag(if *b { BoolTrueTag } else { BoolFalseTag }),
|
||||
// Value::EdgeDir(e) => self.build_tag(match e {
|
||||
// EdgeDirKind::FwdEdgeDir => { FwdEdgeTag }
|
||||
// EdgeDirKind::BwdEdgeDir => { BwdEdgeTag }
|
||||
// }),
|
||||
// Value::UInt(u) => {
|
||||
// self.build_tag(UIntTag).build_varint(*u)
|
||||
// }
|
||||
// Value::Int(i) => {
|
||||
// self.build_tag(IntTag).build_zigzag(*i)
|
||||
// }
|
||||
// Value::Float(f) => {
|
||||
// self.build_tag(FloatTag).build_float(*f)
|
||||
// }
|
||||
// Value::Text(s) => {
|
||||
// self.build_tag(StringTag).build_string(s)
|
||||
// }
|
||||
// Value::List(l) => {
|
||||
// self.build_tag(ListTag).build_list(l)
|
||||
// }
|
||||
// Value::Dict(d) => {
|
||||
// self.build_tag(DictTag).build_dict(d)
|
||||
// }
|
||||
// Value::Uuid(u) => {
|
||||
// self.build_tag(UuidTag).build_uuid(*u)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub fn build_list(&mut self, l: &[Value]) -> &mut Self {
|
||||
// self.build_varint(l.len() as u64);
|
||||
// for el in l {
|
||||
// self.build_value(el);
|
||||
// }
|
||||
// self
|
||||
// }
|
||||
//
|
||||
// pub fn build_dict(&mut self, d: &BTreeMap<Cow<str>, Value>) -> &mut Self {
|
||||
// self.build_varint(d.len() as u64);
|
||||
// for (k, v) in d {
|
||||
// self.build_string(k).build_value(v);
|
||||
// }
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// pub fn cozo_comparator_v1(a: &[u8], b: &[u8]) -> i8 {
|
||||
// let mut ba = &mut ByteArrayParser { bytes: a, current: 0 };
|
||||
// let mut bb = &mut ByteArrayParser { bytes: b, current: 0 };
|
||||
// match ba.compare_varint(&mut bb) {
|
||||
// Less => return -1,
|
||||
// Greater => return 1,
|
||||
// Equal => {}
|
||||
// }
|
||||
// match cmp_data(&mut ba, &mut bb) {
|
||||
// Less => -1,
|
||||
// Equal => 0,
|
||||
// Greater => 1
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub fn cmp_data<'a>(pa: &mut ByteArrayParser<'a>, pb: &mut ByteArrayParser<'a>) -> Ordering {
|
||||
// loop {
|
||||
// match (pa.at_end(), pb.at_end()) {
|
||||
// (true, true) => return Equal,
|
||||
// (true, false) => return Less,
|
||||
// (false, true) => return Greater,
|
||||
// (false, false) => ()
|
||||
// }
|
||||
// if let x @ (Greater | Less) = pa.compare_value(pb) { return x; }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// impl<'a> Value<'a> {
|
||||
// pub fn owned_clone(&self) -> StaticValue {
|
||||
// use Value::*;
|
||||
//
|
||||
// match self {
|
||||
// Null => Null,
|
||||
// Bool(b) => Bool(*b),
|
||||
// EdgeDir(dir) => EdgeDir(*dir),
|
||||
// UInt(u) => UInt(*u),
|
||||
// Int(i) => Int(*i),
|
||||
// Float(f) => Float(*f),
|
||||
// // Text(s) => Text(Arc::new(Cow::Owned(s.into_owned()))),
|
||||
// Text(s) => todo!(),
|
||||
// List(l) => {
|
||||
// let mut inner = Vec::with_capacity(l.len());
|
||||
//
|
||||
// for el in l.iter() {
|
||||
// inner.push(el.owned_clone())
|
||||
// }
|
||||
// List(Arc::new(inner))
|
||||
// }
|
||||
// Dict(d) => {
|
||||
// let mut inner = BTreeMap::new();
|
||||
// for (k, v) in d.iter() {
|
||||
// let new_k = Cow::from(k.clone().into_owned());
|
||||
// inner.insert(new_k, v.owned_clone());
|
||||
// }
|
||||
// Dict(Arc::new(inner))
|
||||
// }
|
||||
// Uuid(u) => Uuid(*u),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// #[derive(Clone, Debug)]
|
||||
// pub struct CoercionError<'a> {
|
||||
// pub msg: String,
|
||||
// pub val: Value<'a>,
|
||||
// }
|
||||
//
|
||||
// impl Typing {
|
||||
// pub fn coerce<'a>(&self, v: Value<'a>) -> Result<Value<'a>, CoercionError<'a>> {
|
||||
// // TODO
|
||||
// Ok(v)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub struct CozoKey<'a> {
|
||||
// pub table_id: i64,
|
||||
// pub values: Vec<Value<'a>>,
|
||||
// }
|
||||
//
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
//
|
||||
// #[test]
|
||||
// fn varint() {
|
||||
// for u in 126..(2u64).pow(9) {
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_varint(u);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let u2 = parser.parse_varint().unwrap();
|
||||
// assert_eq!(u, u2);
|
||||
// }
|
||||
//
|
||||
// let u = u64::MIN;
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_varint(u);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let u2 = parser.parse_varint().unwrap();
|
||||
// assert_eq!(u, u2);
|
||||
//
|
||||
// let u = u64::MAX;
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_varint(u);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let u2 = parser.parse_varint().unwrap();
|
||||
// assert_eq!(u, u2);
|
||||
// }
|
||||
//
|
||||
// #[test]
|
||||
// fn zigzag() {
|
||||
// for i in 126..(2i64).pow(9) {
|
||||
// let mut builder = ByteArrayBuilder::default();
|
||||
// builder.build_zigzag(i);
|
||||
// let mut parser = ByteArrayParser::new(&builder);
|
||||
// let i2 = parser.parse_zigzag().unwrap();
|
||||
// assert_eq!(i, i2);
|
||||
// }
|
||||
// for i in 126..(2i64).pow(9) {
|
||||
// let i = -i;
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_zigzag(i);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let i2 = parser.parse_zigzag().unwrap();
|
||||
// assert_eq!(i, i2);
|
||||
// }
|
||||
//
|
||||
// let i = i64::MIN;
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_zigzag(i);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let i2 = parser.parse_zigzag().unwrap();
|
||||
// assert_eq!(i, i2);
|
||||
//
|
||||
// let i = i64::MAX;
|
||||
// let mut x = vec![];
|
||||
// let mut builder = ByteArrayBuilder::new(&mut x);
|
||||
// builder.build_zigzag(i);
|
||||
// let mut parser = ByteArrayParser::new(&x);
|
||||
// let i2 = parser.parse_zigzag().unwrap();
|
||||
// assert_eq!(i, i2);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[test]
|
||||
// fn size() {
|
||||
// println!("{:?}", std::mem::size_of::<Value>());
|
||||
// println!("{:?}", std::mem::size_of::<i64>());
|
||||
// println!("{:?}", std::mem::size_of::<Uuid>());
|
||||
// println!("{:?}", std::mem::size_of::<BTreeMap<Cow<str>, Value>>());
|
||||
// println!("{:?}", std::mem::size_of::<Vec<Value>>());
|
||||
// println!("{:?}", std::mem::size_of::<Cow<str>>());
|
||||
// println!("{:?}", std::mem::size_of::<Box<Cow<str>>>());
|
||||
// println!("{:?}", std::mem::size_of::<Box<Vec<Value>>>());
|
||||
// println!("{:?}", std::mem::size_of::<String>());
|
||||
// println!("{:?}", std::mem::size_of::<&str>());
|
||||
// }
|
||||
// }
|
Loading…
Reference in New Issue