Expand type code when applying ground. (#475)

This commit is contained in:
Richard Newman 2017-06-09 07:40:32 -07:00 committed by Richard Newman
parent 79fa0994b3
commit e1e549440f
2 changed files with 17 additions and 4 deletions

View file

@ -40,6 +40,7 @@ use errors::{
use super::QualifiedAlias; use super::QualifiedAlias;
use types::{ use types::{
ColumnConstraint,
ComputedTable, ComputedTable,
EmptyBecause, EmptyBecause,
SourceAlias, SourceAlias,
@ -241,6 +242,8 @@ impl ConjoiningClauses {
self.bind_value(&var, value.clone()); self.bind_value(&var, value.clone());
} }
let vt = value.value_type();
// Check to see whether this variable is already associated to a column. // 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 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 if let Some(QualifiedAlias(table, column)) = self.column_bindings
@ -249,6 +252,13 @@ impl ConjoiningClauses {
self.constrain_column_to_constant(table, column, value); 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(()) Ok(())
} }

View file

@ -684,12 +684,15 @@ fn test_unbound_attribute_with_ground_entity() {
#[test] #[test]
fn test_unbound_attribute_with_ground() { fn test_unbound_attribute_with_ground() {
// TODO: this needs to expand the type code. #475. let query = r#"[:find ?x ?v :where [?x _ ?v] (not [(ground 17) ?v])]"#;
let query = r#"[:find ?x :where [?x _ ?v] (not [(ground 5) ?v])]"#;
let schema = prepopulated_schema(); let schema = prepopulated_schema();
let SQLQuery { sql, .. } = translate(&schema, query); let SQLQuery { sql, .. } = translate(&schema, query);
assert_eq!(sql, "SELECT DISTINCT `all_datoms00`.e AS `?x` FROM `all_datoms` AS `all_datoms00` \ assert_eq!(sql, "SELECT DISTINCT `all_datoms00`.e AS `?x`, \
WHERE NOT EXISTS (SELECT 1 WHERE `all_datoms00`.v = 5)"); `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)");
} }