Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arithmetic Expressions in Projections #30

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 45 additions & 45 deletions src/sql/mod.rs
Expand Up @@ -720,7 +720,7 @@ mod tests {
// Should have two nodes: source and "users" base table
let ncount = mig.graph().node_count();
assert_eq!(ncount, 2);
assert_eq!(get_node(&inc, &*mig, "users").name(), "users");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the &* make a difference in these tests? They seem to be passing fine without it as well, so I removed it - let me know if it should be there though and I'll revert the commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably a leftover from when migrations worked somewhat differently, and can indeed be removed.

assert_eq!(get_node(&inc, mig, "users").name(), "users");

assert!(
"SELECT users.id from users;"
Expand Down Expand Up @@ -755,9 +755,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "users").name(), "users");
assert_eq!(get_node(&inc, &*mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, &*mig, "users").description(), "B");
assert_eq!(get_node(&inc, mig, "users").name(), "users");
assert_eq!(get_node(&inc, mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, mig, "users").description(), "B");

// Establish a base write type for "articles"
assert!(
Expand All @@ -769,12 +769,12 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 3);
assert_eq!(get_node(&inc, &*mig, "articles").name(), "articles");
assert_eq!(get_node(&inc, mig, "articles").name(), "articles");
assert_eq!(
get_node(&inc, &*mig, "articles").fields(),
get_node(&inc, mig, "articles").fields(),
&["id", "author", "title"]
);
assert_eq!(get_node(&inc, &*mig, "articles").description(), "B");
assert_eq!(get_node(&inc, mig, "articles").description(), "B");

// Try a simple equi-JOIN query
let q = "SELECT users.name, articles.title \
Expand All @@ -788,13 +788,13 @@ mod tests {
&[&Column::from("articles.title"), &Column::from("users.name")],
);
// join node
let new_join_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let new_join_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
assert_eq!(
new_join_view.fields(),
&["id", "author", "title", "id", "name"]
);
// leaf node
let new_leaf_view = get_node(&inc, &*mig, &q.unwrap().name);
let new_leaf_view = get_node(&inc, mig, &q.unwrap().name);
assert_eq!(new_leaf_view.fields(), &["name", "title"]);
assert_eq!(new_leaf_view.description(), format!("π[4, 2]"));
});
Expand All @@ -813,9 +813,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "users").name(), "users");
assert_eq!(get_node(&inc, &*mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, &*mig, "users").description(), "B");
assert_eq!(get_node(&inc, mig, "users").name(), "users");
assert_eq!(get_node(&inc, mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, mig, "users").description(), "B");

// Try a simple query
let res = inc.add_query(
Expand All @@ -831,11 +831,11 @@ mod tests {
&[&Column::from("users.name")],
);
// filter node
let filter = get_node(&inc, &*mig, &format!("q_{:x}_n0_p0_f0", qid));
let filter = get_node(&inc, mig, &format!("q_{:x}_n0_p0_f0", qid));
assert_eq!(filter.fields(), &["id", "name"]);
assert_eq!(filter.description(), format!("σ[f0 = 42]"));
// leaf view node
let edge = get_node(&inc, &*mig, &res.unwrap().name);
let edge = get_node(&inc, mig, &res.unwrap().name);
assert_eq!(edge.fields(), &["name"]);
assert_eq!(edge.description(), format!("π[1]"));
});
Expand All @@ -854,9 +854,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, &*mig, "votes").fields(), &["aid", "userid"]);
assert_eq!(get_node(&inc, &*mig, "votes").description(), "B");
assert_eq!(get_node(&inc, mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, mig, "votes").fields(), &["aid", "userid"]);
assert_eq!(get_node(&inc, mig, "votes").description(), "B");

// Try a simple COUNT function
let res = inc.add_query(
Expand Down Expand Up @@ -886,11 +886,11 @@ mod tests {
},
],
);
let agg_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let agg_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
assert_eq!(agg_view.fields(), &["aid", "votes"]);
assert_eq!(agg_view.description(), format!("|*| γ[0]"));
// check edge view
let edge_view = get_node(&inc, &*mig, &res.unwrap().name);
let edge_view = get_node(&inc, mig, &res.unwrap().name);
assert_eq!(edge_view.fields(), &["votes"]);
assert_eq!(edge_view.description(), format!("π[1]"));
});
Expand Down Expand Up @@ -938,9 +938,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "users").name(), "users");
assert_eq!(get_node(&inc, &*mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, &*mig, "users").description(), "B");
assert_eq!(get_node(&inc, mig, "users").name(), "users");
assert_eq!(get_node(&inc, mig, "users").fields(), &["id", "name"]);
assert_eq!(get_node(&inc, mig, "users").description(), "B");

// Add a new query
let res = inc.add_query("SELECT id, name FROM users WHERE users.id = 42;", None, mig);
Expand Down Expand Up @@ -976,12 +976,12 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "users").name(), "users");
assert_eq!(get_node(&inc, mig, "users").name(), "users");
assert_eq!(
get_node(&inc, &*mig, "users").fields(),
get_node(&inc, mig, "users").fields(),
&["id", "name", "address"]
);
assert_eq!(get_node(&inc, &*mig, "users").description(), "B");
assert_eq!(get_node(&inc, mig, "users").description(), "B");

// Add a new query
let res = inc.add_query("SELECT id, name FROM users WHERE users.id = ?;", None, mig);
Expand All @@ -1002,7 +1002,7 @@ mod tests {
assert_eq!(mig.graph().node_count(), ncount + 2);
// only the identity node is returned in the vector of new nodes
assert_eq!(qfp.new_nodes.len(), 1);
assert_eq!(get_node(&inc, &*mig, &qfp.name).description(), "≡");
assert_eq!(get_node(&inc, mig, &qfp.name).description(), "≡");
// we should be based off the identity as our leaf
let id_node = qfp.new_nodes.iter().next().unwrap();
assert_eq!(qfp.query_leaf, *id_node);
Expand All @@ -1022,7 +1022,7 @@ mod tests {
// only the projection node is returned in the vector of new nodes
assert_eq!(qfp.new_nodes.len(), 1);
assert_eq!(
get_node(&inc, &*mig, &qfp.name).description(),
get_node(&inc, mig, &qfp.name).description(),
"π[0, 1, 2]"
);
// we should be based off the new projection as our leaf
Expand All @@ -1044,9 +1044,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, &*mig, "votes").fields(), &["aid", "userid"]);
assert_eq!(get_node(&inc, &*mig, "votes").description(), "B");
assert_eq!(get_node(&inc, mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, mig, "votes").fields(), &["aid", "userid"]);
assert_eq!(get_node(&inc, mig, "votes").description(), "B");
// Try a simple COUNT function without a GROUP BY clause
let res = inc.add_query("SELECT COUNT(votes.userid) AS count FROM votes;", None, mig);
assert!(res.is_ok());
Expand All @@ -1069,16 +1069,16 @@ mod tests {
},
],
);
let proj_helper_view = get_node(&inc, &*mig, &format!("q_{:x}_n0_prj_hlpr", qid));
let proj_helper_view = get_node(&inc, mig, &format!("q_{:x}_n0_prj_hlpr", qid));
assert_eq!(proj_helper_view.fields(), &["userid", "grp"]);
assert_eq!(proj_helper_view.description(), format!("π[1, lit: 0]"));
// check aggregation view
let agg_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let agg_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
assert_eq!(agg_view.fields(), &["grp", "count"]);
assert_eq!(agg_view.description(), format!("|*| γ[1]"));
// check edge view -- note that it's not actually currently possible to read from
// this for a lack of key (the value would be the key)
let edge_view = get_node(&inc, &*mig, &res.unwrap().name);
let edge_view = get_node(&inc, mig, &res.unwrap().name);
assert_eq!(edge_view.fields(), &["count"]);
assert_eq!(edge_view.description(), format!("π[1]"));
});
Expand All @@ -1097,9 +1097,9 @@ mod tests {
);
// Should have source and "users" base table node
assert_eq!(mig.graph().node_count(), 2);
assert_eq!(get_node(&inc, &*mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, &*mig, "votes").fields(), &["userid", "aid"]);
assert_eq!(get_node(&inc, &*mig, "votes").description(), "B");
assert_eq!(get_node(&inc, mig, "votes").name(), "votes");
assert_eq!(get_node(&inc, mig, "votes").fields(), &["userid", "aid"]);
assert_eq!(get_node(&inc, mig, "votes").description(), "B");
// Try a simple COUNT function without a GROUP BY clause
let res = inc.add_query(
"SELECT COUNT(*) AS count FROM votes GROUP BY votes.userid;",
Expand All @@ -1123,12 +1123,12 @@ mod tests {
},
],
);
let agg_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let agg_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
assert_eq!(agg_view.fields(), &["userid", "count"]);
assert_eq!(agg_view.description(), format!("|*| γ[0]"));
// check edge view -- note that it's not actually currently possible to read from
// this for a lack of key (the value would be the key)
let edge_view = get_node(&inc, &*mig, &res.unwrap().name);
let edge_view = get_node(&inc, mig, &res.unwrap().name);
assert_eq!(edge_view.fields(), &["count"]);
assert_eq!(edge_view.description(), format!("π[1]"));
});
Expand Down Expand Up @@ -1181,7 +1181,7 @@ mod tests {
// XXX(malte): non-deterministic join ordering make it difficult to assert on the join
// views
// leaf view
let leaf_view = get_node(&inc, &*mig, "q_3");
let leaf_view = get_node(&inc, mig, "q_3");
assert_eq!(leaf_view.fields(), &["name", "title", "uid"]);
});
}
Expand Down Expand Up @@ -1232,20 +1232,20 @@ mod tests {
&Column::from("votes.uid"),
],
);
let join1_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let join1_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
// articles join votes
assert_eq!(
join1_view.fields(),
&["aid", "title", "author", "id", "name"]
);
let join2_view = get_node(&inc, &*mig, &format!("q_{:x}_n1", qid));
let join2_view = get_node(&inc, mig, &format!("q_{:x}_n1", qid));
// join1_view join users
assert_eq!(
join2_view.fields(),
&["aid", "title", "author", "id", "name", "aid", "uid"]
);
// leaf view
let leaf_view = get_node(&inc, &*mig, "q_3");
let leaf_view = get_node(&inc, mig, "q_3");
assert_eq!(leaf_view.fields(), &["name", "title", "uid"]);
});
}
Expand All @@ -1265,7 +1265,7 @@ mod tests {
assert!(res.is_ok());

// leaf view node
let edge = get_node(&inc, &*mig, &res.unwrap().name);
let edge = get_node(&inc, mig, &res.unwrap().name);
assert_eq!(edge.fields(), &["name", "literal"]);
assert_eq!(edge.description(), format!("π[1, lit: 1]"));
});
Expand Down Expand Up @@ -1330,13 +1330,13 @@ mod tests {
],
);
// join node
let new_join_view = get_node(&inc, &*mig, &format!("q_{:x}_n0", qid));
let new_join_view = get_node(&inc, mig, &format!("q_{:x}_n0", qid));
assert_eq!(
new_join_view.fields(),
&["id", "name", "id", "author", "title"]
);
// leaf node
let new_leaf_view = get_node(&inc, &*mig, &q.unwrap().name);
let new_leaf_view = get_node(&inc, mig, &q.unwrap().name);
assert_eq!(new_leaf_view.fields(), &["name", "title"]);
assert_eq!(new_leaf_view.description(), format!("π[1, 4]"));
});
Expand Down