recursive typing resolve
parent
517756e087
commit
017025884a
@ -1,3 +1,4 @@
|
||||
pub mod engine;
|
||||
pub mod eval;
|
||||
pub mod plan;
|
||||
pub mod table_def;
|
@ -0,0 +1,10 @@
|
||||
use pest::iterators::Pair;
|
||||
use crate::db::engine::Session;
|
||||
use crate::parser::Rule;
|
||||
use crate::relation::tuple::Tuple;
|
||||
|
||||
impl<'a> Session<'a> {
|
||||
pub fn parse_table_def(&self, pair: Pair<Rule>) -> Tuple<Vec<u8>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
use std::borrow::Borrow;
|
||||
use crate::relation::tuple::Tuple;
|
||||
use crate::error::{CozoError, Result};
|
||||
use crate::relation::typing::Typing;
|
||||
use crate::relation::value::Value;
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum DataKind {
|
||||
DataTuple = 0,
|
||||
Node = 1,
|
||||
Edge = 2,
|
||||
Associate = 3,
|
||||
Index = 4,
|
||||
Value = 5,
|
||||
TypeAlias = 6,
|
||||
}
|
||||
// In storage, key layout is `[0, name, stack_depth]` where stack_depth is a non-positive number as zigzag
|
||||
// Also has inverted index `[0, stack_depth, name]` for easy popping of stacks
|
||||
|
||||
|
||||
impl<T: AsRef<[u8]>> Tuple<T> {
|
||||
pub fn data_kind(&self) -> Result<DataKind> {
|
||||
use DataKind::*;
|
||||
Ok(match self.get_prefix() {
|
||||
0 => DataTuple,
|
||||
1 => Node,
|
||||
2 => Edge,
|
||||
3 => Associate,
|
||||
4 => Index,
|
||||
5 => Value,
|
||||
6 => TypeAlias,
|
||||
v => return Err(CozoError::UndefinedDataKind(v))
|
||||
})
|
||||
}
|
||||
pub fn interpret_as_type(&self) -> Result<Typing> {
|
||||
if let Value::Text(s) = self.get(0).ok_or_else(|| CozoError::BadDataFormat(self.as_ref().to_vec()))? {
|
||||
Ok(Typing::try_from(s.borrow())?)
|
||||
} else {
|
||||
return Err(CozoError::BadDataFormat(self.as_ref().to_vec()));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue