Expand type code when applying ground. (#475)
This commit is contained in:
parent
79fa0994b3
commit
e1e549440f
2 changed files with 17 additions and 4 deletions
|
@ -40,6 +40,7 @@ use errors::{
|
|||
use super::QualifiedAlias;
|
||||
|
||||
use types::{
|
||||
ColumnConstraint,
|
||||
ComputedTable,
|
||||
EmptyBecause,
|
||||
SourceAlias,
|
||||
|
@ -241,6 +242,8 @@ impl ConjoiningClauses {
|
|||
self.bind_value(&var, value.clone());
|
||||
}
|
||||
|
||||
let vt = value.value_type();
|
||||
|
||||
// Check to see whether this variable is already associated to a column.
|
||||
// If so, we want to add an equality filter (or, in the future, redo the existing patterns).
|
||||
if let Some(QualifiedAlias(table, column)) = self.column_bindings
|
||||
|
@ -249,6 +252,13 @@ impl ConjoiningClauses {
|
|||
self.constrain_column_to_constant(table, column, value);
|
||||
}
|
||||
|
||||
// Are we also trying to figure out the type of the value when the query runs?
|
||||
// If so, constrain that!
|
||||
if let Some(table) = self.extracted_types.get(&var)
|
||||
.map(|qa| qa.0.clone()) {
|
||||
self.wheres.add_intersection(ColumnConstraint::HasType(table, vt));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -684,12 +684,15 @@ fn test_unbound_attribute_with_ground_entity() {
|
|||
|
||||
#[test]
|
||||
fn test_unbound_attribute_with_ground() {
|
||||
// TODO: this needs to expand the type code. #475.
|
||||
let query = r#"[:find ?x :where [?x _ ?v] (not [(ground 5) ?v])]"#;
|
||||
let query = r#"[:find ?x ?v :where [?x _ ?v] (not [(ground 17) ?v])]"#;
|
||||
let schema = prepopulated_schema();
|
||||
let SQLQuery { sql, .. } = translate(&schema, query);
|
||||
assert_eq!(sql, "SELECT DISTINCT `all_datoms00`.e AS `?x` FROM `all_datoms` AS `all_datoms00` \
|
||||
WHERE NOT EXISTS (SELECT 1 WHERE `all_datoms00`.v = 5)");
|
||||
assert_eq!(sql, "SELECT DISTINCT `all_datoms00`.e AS `?x`, \
|
||||
`all_datoms00`.v AS `?v`, \
|
||||
`all_datoms00`.value_type_tag AS `?v_value_type_tag` \
|
||||
FROM `all_datoms` AS `all_datoms00` \
|
||||
WHERE NOT EXISTS (SELECT 1 WHERE `all_datoms00`.v = 17 AND \
|
||||
`all_datoms00`.value_type_tag = 5)");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue