Enum mentat_query::FindSpec
[−]
[src]
pub enum FindSpec { FindRel(Vec<Element>), FindColl(Element), FindTuple(Vec<Element>), FindScalar(Element), }
A definition of the first part of a find query: the
[:find ?foo ?bar…]
bit.
There are four different kinds of find specs, allowing you to query for a single value, a collection of values from different entities, a single tuple (relation), or a collection of tuples.
Examples:
let elements = vec![ Element::Variable(Variable::from_valid_name("?foo")), Element::Variable(Variable::from_valid_name("?bar")), ]; let rel = FindSpec::FindRel(elements); if let FindSpec::FindRel(elements) = rel { assert_eq!(2, elements.len()); }
Variants
FindRel(Vec<Element>)
Returns an array of arrays.
FindColl(Element)
Returns an array of scalars, usually homogeneous.
This is equivalent to mapping over the results of a FindRel
,
returning the first value of each.
FindTuple(Vec<Element>)
Returns a single tuple: a heterogeneous array of scalars. Equivalent to
taking the first result from a FindRel
.
FindScalar(Element)
Returns a single scalar value. Equivalent to taking the first result
from a FindColl
.
Methods
impl FindSpec
[src]
Returns true if the provided FindSpec
returns at most one result.
pub fn is_unit_limited(&self) -> bool
[src]
pub fn expected_column_count(&self) -> usize
[src]
pub fn requires_distinct(&self) -> bool
[src]
Returns true if the provided FindSpec
cares about distinct results.
I use the words "cares about" because find is generally defined in terms of producing distinct results at the Datalog level.
Two of the find specs (scalar and tuple) produce only a single result. Those don't need to be
run with SELECT DISTINCT
, because we're only consuming a single result. Those queries will be
run with LIMIT 1
.
Additionally, some projections cannot produce duplicate results: [:find (max ?x) …]
, for
example.
This function gives us the hook to add that logic when we're ready.
Beyond this, DISTINCT
is not always needed. For example, in some kinds of accumulation or
sampling projections we might not need to do it at the SQL level because we're consuming into
a dupe-eliminating data structure like a Set, or we know that a particular query cannot produce
duplicate results.
ⓘImportant traits for Box<R>pub fn columns<'s>(&'s self) -> Box<Iterator<Item = &Element> + 's>
[src]
Trait Implementations
impl Debug for FindSpec
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more