Improve Debug output for ConjoiningClauses; r=rnewman

Fixes #317, and also removes the '::' exploration of rust style
This commit is contained in:
Joe Walker 2017-02-16 15:16:04 +00:00
parent 7fc2a22d68
commit 60b2e6f885
2 changed files with 49 additions and 9 deletions

View file

@ -13,8 +13,13 @@
extern crate mentat_core; extern crate mentat_core;
extern crate mentat_query; extern crate mentat_query;
use ::std::collections::BTreeMap; use std::fmt::{
use ::std::collections::btree_map::Entry; Debug,
Formatter,
Result,
};
use std::collections::BTreeMap;
use std::collections::btree_map::Entry;
use self::mentat_core::{ use self::mentat_core::{
Attribute, Attribute,
@ -85,13 +90,25 @@ impl DatomsColumn {
pub type TableAlias = String; pub type TableAlias = String;
/// The association between a table and its alias. E.g., AllDatoms, "all_datoms123". /// The association between a table and its alias. E.g., AllDatoms, "all_datoms123".
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq)]
pub struct SourceAlias(pub DatomsTable, pub TableAlias); pub struct SourceAlias(pub DatomsTable, pub TableAlias);
impl Debug for SourceAlias {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "SourceAlias({:?}, {})", self.0, self.1)
}
}
/// A particular column of a particular aliased table. E.g., "datoms123", Attribute. /// A particular column of a particular aliased table. E.g., "datoms123", Attribute.
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone)]
pub struct QualifiedAlias(pub TableAlias, pub DatomsColumn); pub struct QualifiedAlias(pub TableAlias, pub DatomsColumn);
impl Debug for QualifiedAlias {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{}.{}", self.0, self.1.as_str())
}
}
impl QualifiedAlias { impl QualifiedAlias {
fn for_type_tag(&self) -> QualifiedAlias { fn for_type_tag(&self) -> QualifiedAlias {
QualifiedAlias(self.0.clone(), DatomsColumn::ValueTypeTag) QualifiedAlias(self.0.clone(), DatomsColumn::ValueTypeTag)
@ -115,13 +132,30 @@ pub fn default_table_aliaser() -> TableAliaser {
}) })
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq)]
pub enum ColumnConstraint { pub enum ColumnConstraint {
EqualsEntity(QualifiedAlias, Entid), EqualsEntity(QualifiedAlias, Entid),
EqualsValue(QualifiedAlias, TypedValue), EqualsValue(QualifiedAlias, TypedValue),
EqualsColumn(QualifiedAlias, QualifiedAlias), EqualsColumn(QualifiedAlias, QualifiedAlias),
} }
impl Debug for ColumnConstraint {
fn fmt(&self, f: &mut Formatter) -> Result {
use self::ColumnConstraint::*;
match self {
&EqualsEntity(ref qa, ref entid) => {
write!(f, "{:?} = entity({:?})", qa, entid)
}
&EqualsValue(ref qa, ref typed_value) => {
write!(f, "{:?} = value({:?})", qa, typed_value)
}
&EqualsColumn(ref qa1, ref qa2) => {
write!(f, "{:?} = {:?}", qa1, qa2)
}
}
}
}
/// A `ConjoiningClauses` (CC) is a collection of clauses that are combined with `JOIN`. /// A `ConjoiningClauses` (CC) is a collection of clauses that are combined with `JOIN`.
/// The topmost form in a query is a `ConjoiningClauses`. /// The topmost form in a query is a `ConjoiningClauses`.
/// ///
@ -171,9 +205,8 @@ pub struct ConjoiningClauses {
extracted_types: BTreeMap<Variable, QualifiedAlias>, extracted_types: BTreeMap<Variable, QualifiedAlias>,
} }
impl ::std::fmt::Debug for ConjoiningClauses { impl Debug for ConjoiningClauses {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> Result {
// TODO: improve this representation.
fmt.debug_struct("ConjoiningClauses") fmt.debug_struct("ConjoiningClauses")
.field("is_known_empty", &self.is_known_empty) .field("is_known_empty", &self.is_known_empty)
.field("from", &self.from) .field("from", &self.from)

View file

@ -33,13 +33,14 @@
extern crate edn; extern crate edn;
extern crate mentat_core; extern crate mentat_core;
use std::fmt;
use edn::{BigInt, OrderedFloat}; use edn::{BigInt, OrderedFloat};
pub use edn::{NamespacedKeyword, PlainSymbol}; pub use edn::{NamespacedKeyword, PlainSymbol};
use mentat_core::TypedValue; use mentat_core::TypedValue;
pub type SrcVarName = String; // Do not include the required syntactic '$'. pub type SrcVarName = String; // Do not include the required syntactic '$'.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Variable(pub PlainSymbol); pub struct Variable(pub PlainSymbol);
pub trait FromValue<T> { pub trait FromValue<T> {
@ -68,6 +69,12 @@ impl Variable {
} }
} }
impl fmt::Debug for Variable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "var({})", self.0)
}
}
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub enum SrcVar { pub enum SrcVar {
DefaultSrc, DefaultSrc,