Expand query algebrizer. r=nalexander

This commit is contained in:
Richard Newman 2017-02-21 19:55:27 -08:00
parent 76f51015d9
commit 91c75f26c8
2 changed files with 25 additions and 6 deletions

View file

@ -90,7 +90,7 @@ impl DatomsColumn {
pub type TableAlias = String;
/// The association between a table and its alias. E.g., AllDatoms, "all_datoms123".
#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Clone)]
pub struct SourceAlias(pub DatomsTable, pub TableAlias);
impl Debug for SourceAlias {
@ -187,10 +187,10 @@ pub struct ConjoiningClauses {
aliaser: TableAliaser,
/// A vector of source/alias pairs used to construct a SQL `FROM` list.
from: Vec<SourceAlias>,
pub from: Vec<SourceAlias>,
/// A list of fragments that can be joined by `AND`.
wheres: Vec<ColumnConstraint>,
pub wheres: Vec<ColumnConstraint>,
/// A map from var to qualified columns. Used to project.
bindings: BTreeMap<Variable, Vec<QualifiedAlias>>,

View file

@ -8,14 +8,20 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate mentat_query;
mod cc;
use mentat_core::{
Schema,
};
use mentat_query::{
FindQuery,
FindSpec,
SrcVar,
WhereClause,
};
#[allow(dead_code)]
@ -24,21 +30,34 @@ pub struct AlgebraicQuery {
find_spec: FindSpec,
has_aggregates: bool,
limit: Option<i64>,
cc: cc::ConjoiningClauses,
pub cc: cc::ConjoiningClauses,
}
#[allow(dead_code)]
pub fn algebrize(parsed: FindQuery) -> AlgebraicQuery {
pub fn algebrize(schema: &Schema, parsed: FindQuery) -> AlgebraicQuery {
// TODO: integrate default source into pattern processing.
// TODO: flesh out the rest of find-into-context.
let mut cc = cc::ConjoiningClauses::default();
let where_clauses = parsed.where_clauses;
for where_clause in where_clauses {
if let WhereClause::Pattern(p) = where_clause {
cc.apply_pattern(schema, &p);
} else {
unimplemented!();
}
}
AlgebraicQuery {
default_source: parsed.default_source,
find_spec: parsed.find_spec,
has_aggregates: false, // TODO: we don't parse them yet.
limit: None,
cc: cc::ConjoiningClauses::default(),
cc: cc,
}
}
pub use cc::{
ColumnConstraint,
ConjoiningClauses,
};