Rename or delete things so that there is only one type named Entid (#768)

* Delete the (apparently unused) EntId

* Rename edn's Entid to EntidOrIdent to avoid confusion with the Entid that's actually an i64

* Fix travis beta bustage (This is actually unrelated to entids, but is a trivial fix nonetheless)
This commit is contained in:
Thom 2018-06-26 16:34:18 -07:00 committed by GitHub
parent f335253d4c
commit 72a9b302f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 70 deletions

View file

@ -32,7 +32,7 @@ use mentat_core::{
ValueType, ValueType,
}; };
use edn::entities::{ use edn::entities::{
Entid, EntidOrIdent,
}; };
use schema::{ use schema::{
SchemaBuilding, SchemaBuilding,
@ -43,8 +43,8 @@ use types::Schema;
#[derive(Clone,Debug,Eq,Hash,Ord,PartialOrd,PartialEq)] #[derive(Clone,Debug,Eq,Hash,Ord,PartialOrd,PartialEq)]
pub(crate) struct Datom { pub(crate) struct Datom {
// TODO: generalize this. // TODO: generalize this.
e: Entid, e: EntidOrIdent,
a: Entid, a: EntidOrIdent,
v: edn::Value, v: edn::Value,
tx: i64, tx: i64,
added: Option<bool>, added: Option<bool>,
@ -70,10 +70,10 @@ pub(crate) struct FulltextValues(pub Vec<(i64, String)>);
impl Datom { impl Datom {
pub(crate) fn into_edn(&self) -> edn::Value { pub(crate) fn into_edn(&self) -> edn::Value {
let f = |entid: &Entid| -> edn::Value { let f = |entid: &EntidOrIdent| -> edn::Value {
match *entid { match *entid {
Entid::Entid(ref y) => edn::Value::Integer(y.clone()), EntidOrIdent::Entid(ref y) => edn::Value::Integer(y.clone()),
Entid::Ident(ref y) => edn::Value::Keyword(y.clone()), EntidOrIdent::Ident(ref y) => edn::Value::Keyword(y.clone()),
} }
}; };
@ -121,8 +121,8 @@ impl ToIdent for TypedValue {
} }
/// Convert a numeric entid to an ident `Entid` if possible, otherwise a numeric `Entid`. /// Convert a numeric entid to an ident `Entid` if possible, otherwise a numeric `Entid`.
fn to_entid(schema: &Schema, entid: i64) -> Entid { fn to_entid(schema: &Schema, entid: i64) -> EntidOrIdent {
schema.get_ident(entid).map_or(Entid::Entid(entid), |ident| Entid::Ident(ident.clone())) schema.get_ident(entid).map_or(EntidOrIdent::Entid(entid), |ident| EntidOrIdent::Ident(ident.clone()))
} }
/// Return the set of datoms in the store, ordered by (e, a, v, tx), but not including any datoms of /// Return the set of datoms in the store, ordered by (e, a, v, tx), but not including any datoms of
@ -160,7 +160,7 @@ pub(crate) fn datoms_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schem
let tx: i64 = row.get_checked(4)?; let tx: i64 = row.get_checked(4)?;
Ok(Some(Datom { Ok(Some(Datom {
e: Entid::Entid(e), e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a), a: to_entid(borrowed_schema, a),
v: value, v: value,
tx: tx, tx: tx,
@ -197,7 +197,7 @@ pub(crate) fn transactions_after<S: Borrow<Schema>>(conn: &rusqlite::Connection,
let added: bool = row.get_checked(5)?; let added: bool = row.get_checked(5)?;
Ok(Datom { Ok(Datom {
e: Entid::Entid(e), e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a), a: to_entid(borrowed_schema, a),
v: value, v: value,
tx: tx, tx: tx,

View file

@ -63,10 +63,10 @@ impl TransactableValue for ValueAndSpan {
fn into_entity_place(self) -> Result<EntityPlace<Self>> { fn into_entity_place(self) -> Result<EntityPlace<Self>> {
use self::SpannedValue::*; use self::SpannedValue::*;
match self.inner { match self.inner {
Integer(v) => Ok(EntityPlace::Entid(entities::Entid::Entid(v))), Integer(v) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(v))),
Keyword(v) => { Keyword(v) => {
if v.is_namespaced() { if v.is_namespaced() {
Ok(EntityPlace::Entid(entities::Entid::Ident(v))) Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident(v)))
} else { } else {
// We only allow namespaced idents. // We only allow namespaced idents.
bail!(DbError::InputError(errors::InputError::BadEntityPlace)) bail!(DbError::InputError(errors::InputError::BadEntityPlace))
@ -121,8 +121,8 @@ impl TransactableValue for TypedValue {
fn into_entity_place(self) -> Result<EntityPlace<Self>> { fn into_entity_place(self) -> Result<EntityPlace<Self>> {
match self { match self {
TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::Entid::Entid(x))), TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(x))),
TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::Entid::Ident((*x).clone()))), TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident((*x).clone()))),
TypedValue::String(x) => Ok(EntityPlace::TempId(TempId::External((*x).clone()))), TypedValue::String(x) => Ok(EntityPlace::TempId(TempId::External((*x).clone()))),
TypedValue::Boolean(_) | TypedValue::Boolean(_) |
TypedValue::Long(_) | TypedValue::Long(_) |

View file

@ -168,7 +168,7 @@ pub struct Tx<'conn, 'a, W> where W: TransactWatcher {
/// something suitable for the entity position rather than something suitable for a value position. /// something suitable for the entity position rather than something suitable for a value position.
pub fn remove_db_id<V: TransactableValue>(map: &mut entmod::MapNotation<V>) -> Result<Option<entmod::EntityPlace<V>>> { pub fn remove_db_id<V: TransactableValue>(map: &mut entmod::MapNotation<V>) -> Result<Option<entmod::EntityPlace<V>>> {
// TODO: extract lazy defined constant. // TODO: extract lazy defined constant.
let db_id_key = entmod::Entid::Ident(Keyword::namespaced("db", "id")); let db_id_key = entmod::EntidOrIdent::Ident(Keyword::namespaced("db", "id"));
let db_id: Option<entmod::EntityPlace<V>> = if let Some(id) = map.remove(&db_id_key) { let db_id: Option<entmod::EntityPlace<V>> = if let Some(id) = map.remove(&db_id_key) {
match id { match id {
@ -291,8 +291,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
fn intern_lookup_ref<W: TransactableValue>(&mut self, lookup_ref: &entmod::LookupRef<W>) -> Result<LookupRef> { fn intern_lookup_ref<W: TransactableValue>(&mut self, lookup_ref: &entmod::LookupRef<W>) -> Result<LookupRef> {
let lr_a: i64 = match lookup_ref.a { let lr_a: i64 = match lookup_ref.a {
AttributePlace::Entid(entmod::Entid::Entid(ref a)) => *a, AttributePlace::Entid(entmod::EntidOrIdent::Entid(ref a)) => *a,
AttributePlace::Entid(entmod::Entid::Ident(ref a)) => self.schema.require_entid(&a)?.into(), AttributePlace::Entid(entmod::EntidOrIdent::Ident(ref a)) => self.schema.require_entid(&a)?.into(),
}; };
let lr_attribute: &Attribute = self.schema.require_attribute_for_entid(lr_a)?; let lr_attribute: &Attribute = self.schema.require_attribute_for_entid(lr_a)?;
@ -319,8 +319,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
match x { match x {
entmod::EntityPlace::Entid(e) => { entmod::EntityPlace::Entid(e) => {
let e = match e { let e = match e {
entmod::Entid::Entid(ref e) => self.ensure_entid_exists(*e)?, entmod::EntidOrIdent::Entid(ref e) => self.ensure_entid_exists(*e)?,
entmod::Entid::Ident(ref e) => self.ensure_ident_exists(&e)?, entmod::EntidOrIdent::Ident(ref e) => self.ensure_ident_exists(&e)?,
}; };
Ok(Either::Left(e)) Ok(Either::Left(e))
}, },
@ -342,10 +342,10 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
} }
} }
fn entity_a_into_term_a(&mut self, x: entmod::Entid) -> Result<Entid> { fn entity_a_into_term_a(&mut self, x: entmod::EntidOrIdent) -> Result<Entid> {
let a = match x { let a = match x {
entmod::Entid::Entid(ref a) => *a, entmod::EntidOrIdent::Entid(ref a) => *a,
entmod::Entid::Ident(ref a) => self.schema.require_entid(&a)?.into(), entmod::EntidOrIdent::Ident(ref a) => self.schema.require_entid(&a)?.into(),
}; };
Ok(a) Ok(a)
} }
@ -354,7 +354,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
self.entity_e_into_term_e(x).map(|r| r.map_left(|ke| TypedValue::Ref(ke.0))) self.entity_e_into_term_e(x).map(|r| r.map_left(|ke| TypedValue::Ref(ke.0)))
} }
fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::Entid) -> Result<KnownEntidOr<LookupRefOrTempId>> { fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::EntidOrIdent) -> Result<KnownEntidOr<LookupRefOrTempId>> {
match backward_a.unreversed() { match backward_a.unreversed() {
None => { None => {
bail!(DbError::NotYetImplemented(format!("Cannot explode map notation value in :attr/_reversed notation for forward attribute"))); bail!(DbError::NotYetImplemented(format!("Cannot explode map notation value in :attr/_reversed notation for forward attribute")));
@ -510,7 +510,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract { deque.push_front(Entity::AddOrRetract {
op: op.clone(), op: op.clone(),
e: e.clone(), e: e.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(a)), a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(a)),
v: vv, v: vv,
}); });
} }
@ -573,7 +573,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract { deque.push_front(Entity::AddOrRetract {
op: OpType::Add, op: OpType::Add,
e: db_id.clone(), e: db_id.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(inner_a)), a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(inner_a)),
v: inner_v, v: inner_v,
}); });
} }

View file

@ -238,18 +238,18 @@ raw_forward_namespaced_keyword -> Keyword
raw_backward_namespaced_keyword -> Keyword raw_backward_namespaced_keyword -> Keyword
= v:raw_namespaced_keyword {? if v.is_backward() { Ok(v) } else { Err("expected namespaced :backward/_keyword") } } = v:raw_namespaced_keyword {? if v.is_backward() { Ok(v) } else { Err("expected namespaced :backward/_keyword") } }
entid -> Entid entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) } = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_namespaced_keyword { Entid::Ident(v) } / v:raw_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("entid") / #expected("entid")
forward_entid -> Entid forward_entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) } = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_forward_namespaced_keyword { Entid::Ident(v) } / v:raw_forward_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("forward entid") / #expected("forward entid")
backward_entid -> Entid backward_entid -> EntidOrIdent
= v:raw_backward_namespaced_keyword { Entid::Ident(v.to_reversed()) } = v:raw_backward_namespaced_keyword { EntidOrIdent::Ident(v.to_reversed()) }
/ #expected("backward entid") / #expected("backward entid")
lookup_ref -> LookupRef<ValueAndSpan> lookup_ref -> LookupRef<ValueAndSpan>
@ -265,7 +265,7 @@ entity_place -> EntityPlace<ValueAndSpan>
/ v:lookup_ref { EntityPlace::LookupRef(v) } / v:lookup_ref { EntityPlace::LookupRef(v) }
/ v:tx_function { EntityPlace::TxFunction(v) } / v:tx_function { EntityPlace::TxFunction(v) }
value_place_pair -> (Entid, ValuePlace<ValueAndSpan>) value_place_pair -> (EntidOrIdent, ValuePlace<ValueAndSpan>)
= k:(entid) __ v:(value_place) { (k, v) } = k:(entid) __ v:(value_place) { (k, v) }
map_notation -> MapNotation<ValueAndSpan> map_notation -> MapNotation<ValueAndSpan>

View file

@ -45,16 +45,16 @@ impl fmt::Display for TempId {
} }
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum Entid { pub enum EntidOrIdent {
Entid(i64), Entid(i64),
Ident(Keyword), Ident(Keyword),
} }
impl Entid { impl EntidOrIdent {
pub fn unreversed(&self) -> Option<Entid> { pub fn unreversed(&self) -> Option<EntidOrIdent> {
match self { match self {
&Entid::Entid(_) => None, &EntidOrIdent::Entid(_) => None,
&Entid::Ident(ref a) => a.unreversed().map(Entid::Ident), &EntidOrIdent::Ident(ref a) => a.unreversed().map(EntidOrIdent::Ident),
} }
} }
} }
@ -84,13 +84,13 @@ pub struct TxFunction {
pub op: PlainSymbol, pub op: PlainSymbol,
} }
pub type MapNotation<V> = BTreeMap<Entid, ValuePlace<V>>; pub type MapNotation<V> = BTreeMap<EntidOrIdent, ValuePlace<V>>;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum ValuePlace<V> { pub enum ValuePlace<V> {
// We never know at parse-time whether an integer or ident is really an entid, but we will often // We never know at parse-time whether an integer or ident is really an entid, but we will often
// know when building entities programmatically. // know when building entities programmatically.
Entid(Entid), Entid(EntidOrIdent),
// We never know at parse-time whether a string is really a tempid, but we will often know when // We never know at parse-time whether a string is really a tempid, but we will often know when
// building entities programmatically. // building entities programmatically.
TempId(TempId), TempId(TempId),
@ -103,7 +103,7 @@ pub enum ValuePlace<V> {
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum EntityPlace<V> { pub enum EntityPlace<V> {
Entid(Entid), Entid(EntidOrIdent),
TempId(TempId), TempId(TempId),
LookupRef(LookupRef<V>), LookupRef(LookupRef<V>),
TxFunction(TxFunction), TxFunction(TxFunction),
@ -111,7 +111,7 @@ pub enum EntityPlace<V> {
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum AttributePlace { pub enum AttributePlace {
Entid(Entid), Entid(EntidOrIdent),
} }
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]

View file

@ -71,7 +71,7 @@ impl Value {
Value::NamespacedSymbol(ref v) => pp.text(v.namespace()).append("/").append(v.name()), Value::NamespacedSymbol(ref v) => pp.text(v.namespace()).append("/").append(v.name()),
Value::PlainSymbol(ref v) => pp.text(v.to_string()), Value::PlainSymbol(ref v) => pp.text(v.to_string()),
Value::Keyword(ref v) => pp.text(v.to_string()), Value::Keyword(ref v) => pp.text(v.to_string()),
Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""), Value::Text(ref v) => pp.text("\"").append(v.as_str()).append("\""),
Value::Uuid(ref u) => pp.text("#uuid \"").append(u.hyphenated().to_string()).append("\""), Value::Uuid(ref u) => pp.text("#uuid \"").append(u.hyphenated().to_string()).append("\""),
Value::Instant(ref v) => pp.text("#inst \"").append(v.to_rfc3339_opts(SecondsFormat::AutoSi, true)).append("\""), Value::Instant(ref v) => pp.text("#inst \"").append(v.to_rfc3339_opts(SecondsFormat::AutoSi, true)).append("\""),
_ => pp.text(self.to_string()) _ => pp.text(self.to_string())

View file

@ -1,25 +0,0 @@
// Copyright 2016 Mozilla
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
extern crate edn;
use edn::symbols::Keyword;
pub type EntId = u32; // TODO: u64? Not all DB values will be representable in a u32.
/// The ability to transform entity identifiers (entids) into keyword names (idents).
pub trait ToIdent {
fn ident(&self, entid: EntId) -> Option<Keyword>;
}
/// The ability to transform idents into the corresponding entid.
pub trait ToEntId {
fn entid(&self, ident: &Keyword) -> Option<EntId>;
}

View file

@ -106,7 +106,6 @@ macro_rules! kw {
pub mod errors; pub mod errors;
pub mod conn; pub mod conn;
pub mod entity_builder; pub mod entity_builder;
pub mod ident;
pub mod query; pub mod query;
pub mod query_builder; pub mod query_builder;
pub mod store; pub mod store;