mentat/query-algebrizer-traits/errors.rs

118 lines
3.8 KiB
Rust
Raw Normal View History

// 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.
2018-06-01 02:31:21 +00:00
use std; // To refer to std::result::Result.
use core_traits::{ValueType, ValueTypeSet};
use edn::{query::PlainSymbol, ParseError};
pub type Result<T> = std::result::Result<T, AlgebrizerError>;
2018-06-01 02:31:21 +00:00
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BindingError {
NoBoundVariable,
UnexpectedBinding,
RepeatedBoundVariable, // TODO: include repeated variable(s).
/// Expected `[[?x ?y]]` but got some other type of binding. Mentat is deliberately more strict
/// than Datomic: we won't try to make sense of non-obvious (and potentially erroneous) bindings.
ExpectedBindRel,
/// Expected `[[?x ?y]]` or `[?x ...]` but got some other type of binding. Mentat is
/// deliberately more strict than Datomic: we won't try to make sense of non-obvious (and
/// potentially erroneous) bindings.
ExpectedBindRelOrBindColl,
/// Expected `[?x1 … ?xN]` or `[[?x1 … ?xN]]` but got some other number of bindings. Mentat is
/// deliberately more strict than Datomic: we prefer placeholders to omission.
InvalidNumberOfBindings {
number: usize,
expected: usize,
},
}
#[derive(Clone, Debug, Eq, Fail, PartialEq)]
2018-06-01 02:31:21 +00:00
pub enum AlgebrizerError {
#[fail(display = "{} var {} is duplicated", _0, _1)]
DuplicateVariableError(PlainSymbol, &'static str),
2018-06-01 02:31:21 +00:00
#[fail(display = "unexpected FnArg")]
UnsupportedArgument,
#[fail(
display = "value of type {} provided for var {}, expected {}",
_0, _1, _2
)]
2018-06-01 02:31:21 +00:00
InputTypeDisagreement(PlainSymbol, ValueType, ValueType),
#[fail(
display = "invalid number of arguments to {}: expected {}, got {}.",
_0, _1, _2
)]
2018-06-01 02:31:21 +00:00
InvalidNumberOfArguments(PlainSymbol, usize, usize),
#[fail(
display = "invalid argument to {}: expected {} in position {}.",
_0, _1, _2
)]
2018-06-01 02:31:21 +00:00
InvalidArgument(PlainSymbol, &'static str, usize),
#[fail(
display = "invalid argument to {}: expected one of {:?} in position {}.",
_0, _1, _2
)]
2018-06-01 02:31:21 +00:00
InvalidArgumentType(PlainSymbol, ValueTypeSet, usize),
2018-06-01 02:31:21 +00:00
// TODO: flesh this out.
#[fail(display = "invalid expression in ground constant")]
InvalidGroundConstant,
#[fail(
display = "invalid limit {} of type {}: expected natural number.",
_0, _1
)]
2018-06-01 02:31:21 +00:00
InvalidLimit(String, ValueType),
2018-06-01 02:31:21 +00:00
#[fail(display = "mismatched bindings in ground")]
GroundBindingsMismatch,
2018-06-01 02:31:21 +00:00
#[fail(display = "no entid found for ident: {}", _0)]
UnrecognizedIdent(String),
2018-06-01 02:31:21 +00:00
#[fail(display = "no function named {}", _0)]
UnknownFunction(PlainSymbol),
2018-06-01 02:31:21 +00:00
#[fail(display = ":limit var {} not present in :in", _0)]
UnknownLimitVar(PlainSymbol),
Parse and Algebrize `not` & `not-join`. (#302) (Closes #303, #389, #422 ) r=rnewman * Part 1 - Parse `not` and `not-join` * Part 2 - Validate `not` and `not-join` pre-algebrization * Address review comments rnewman. * Remove `WhereNotClause` and populate `NotJoin` with `WhereClause`. * Fix validation for `not` and `not-join`, removing tests that were invalid. * Address rustification comments. * Rebase against `rust` branch. * Part 3 - Add required types for NotJoin. * Implement `PartialEq` for `ConjoiningClauses` so `ComputedTable` can be included inside `ColumnConstraint::NotExists` * Part 4 - Implement `apply_not_join` * Part 5 - Call `apply_not_join` from inside `apply_clause` * Part 6 - Translate `not-join` into `NOT EXISTS` SQL * Address review comments. * Rename `projected` to `unified` to better describe the fact that we are not projecting any variables. * Check for presence of each unified var in either `column_bindings` or `input_bindings` and bail if not there. * Copy over `input_bindings` for each var in `unified`. * Only copy over the first `column_binding` for each variable in `unified` rather than the whole list. * Update tests. * Address review comments. * Make output from Debug for NotExists more useful * Clear up misunderstanding. Any single failing clause in the not will cause the entire not to be considered empty * Address review comments. * Remove Limit requirement from cc_to_exists. * Use Entry.or_insert instead of matching on the entry to add to column_bindings. * Move addition of value_bindings to before apply_clauses on template. * Tidy up tests with some variable reuse. * Addressed nits, * Address review comments. * Move addition of column_bindings to above apply_clause. * Update tests. * Add test to ensure that unbound vars fail * Improve test for unbound variable to check for correct variable and error * address nits
2017-04-28 09:44:11 +00:00
2018-06-01 02:31:21 +00:00
#[fail(display = "unbound variable {} in order clause or function call", _0)]
UnboundVariable(PlainSymbol),
2018-06-01 02:31:21 +00:00
// TODO: flesh out.
#[fail(display = "non-matching variables in 'or' clause")]
NonMatchingVariablesInOrClause,
2018-06-01 02:31:21 +00:00
#[fail(display = "non-matching variables in 'not' clause")]
NonMatchingVariablesInNotClause,
#[fail(display = "binding error in {}: {:?}", _0, _1)]
InvalidBinding(PlainSymbol, BindingError),
#[fail(display = "{}", _0)]
EdnParseError(#[cause] ParseError),
}
impl From<ParseError> for AlgebrizerError {
fn from(error: ParseError) -> AlgebrizerError {
AlgebrizerError::EdnParseError(error)
}
}