2017-02-03 23:52:02 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-02-22 03:55:27 +00:00
|
|
|
extern crate mentat_core;
|
2017-02-03 23:52:02 +00:00
|
|
|
extern crate mentat_query;
|
2017-02-04 00:52:03 +00:00
|
|
|
|
|
|
|
mod cc;
|
|
|
|
|
2017-02-22 03:55:27 +00:00
|
|
|
use mentat_core::{
|
|
|
|
Schema,
|
|
|
|
};
|
|
|
|
|
2017-02-03 23:52:02 +00:00
|
|
|
use mentat_query::{
|
|
|
|
FindQuery,
|
2017-02-04 00:52:03 +00:00
|
|
|
FindSpec,
|
2017-02-03 23:52:02 +00:00
|
|
|
SrcVar,
|
2017-02-22 03:55:27 +00:00
|
|
|
WhereClause,
|
2017-02-03 23:52:02 +00:00
|
|
|
};
|
|
|
|
|
2017-02-04 00:52:03 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
pub struct AlgebraicQuery {
|
|
|
|
default_source: SrcVar,
|
|
|
|
find_spec: FindSpec,
|
|
|
|
has_aggregates: bool,
|
|
|
|
limit: Option<i64>,
|
2017-02-22 03:55:27 +00:00
|
|
|
pub cc: cc::ConjoiningClauses,
|
2017-02-03 23:52:02 +00:00
|
|
|
}
|
|
|
|
|
2017-02-04 00:52:03 +00:00
|
|
|
#[allow(dead_code)]
|
2017-02-22 03:55:27 +00:00
|
|
|
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!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-04 00:52:03 +00:00
|
|
|
AlgebraicQuery {
|
|
|
|
default_source: parsed.default_source,
|
|
|
|
find_spec: parsed.find_spec,
|
|
|
|
has_aggregates: false, // TODO: we don't parse them yet.
|
|
|
|
limit: None,
|
2017-02-22 03:55:27 +00:00
|
|
|
cc: cc,
|
2017-02-04 00:52:03 +00:00
|
|
|
}
|
2017-02-03 23:52:02 +00:00
|
|
|
}
|
2017-02-16 23:38:53 +00:00
|
|
|
|
|
|
|
pub use cc::{
|
2017-02-22 03:55:27 +00:00
|
|
|
ColumnConstraint,
|
2017-02-16 23:38:53 +00:00
|
|
|
ConjoiningClauses,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub use cc::{
|
|
|
|
DatomsColumn,
|
|
|
|
DatomsTable,
|
|
|
|
QualifiedAlias,
|
|
|
|
SourceAlias,
|
|
|
|
TableAlias,
|
|
|
|
};
|
|
|
|
|