Skip to content

Commit

Permalink
feat(cubestore): Three tables join support
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jan 2, 2021
1 parent d138516 commit b776398
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
22 changes: 4 additions & 18 deletions rust/cubestore/src/queryplanner/serialized_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,8 @@ impl SerializedPlan {
meta_store.clone(),
snapshots,
Some(
join_on
.as_ref()
.unwrap_or(&Vec::new())
.iter()
.map(|c| c.to_string())
.chain(
on.iter()
.map(|(l, _)| l.split(".").last().unwrap().to_string()),
)
on.iter()
.map(|(l, _)| l.split(".").last().unwrap().to_string())
.collect(),
),
)
Expand All @@ -588,15 +581,8 @@ impl SerializedPlan {
meta_store.clone(),
snapshots,
Some(
join_on
.as_ref()
.unwrap_or(&Vec::new())
.iter()
.map(|c| c.to_string())
.chain(
on.iter()
.map(|(_, r)| r.split(".").last().unwrap().to_string()),
)
on.iter()
.map(|(_, r)| r.split(".").last().unwrap().to_string())
.collect(),
),
)
Expand Down
36 changes: 36 additions & 0 deletions rust/cubestore/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,42 @@ mod tests {
}).await;
}

#[tokio::test]
async fn three_tables_join() {
Config::run_test("three_tables_join", async move |services| {
let service = services.sql_service;

service.exec_query("CREATE SCHEMA foo").await.unwrap();

service.exec_query("CREATE TABLE foo.orders (customer_id text, product_id int, amount int)").await.unwrap();
service.exec_query("CREATE INDEX orders_by_product ON foo.orders (product_id)").await.unwrap();
service.exec_query("CREATE TABLE foo.customers (id text, city text, state text)").await.unwrap();
service.exec_query("CREATE TABLE foo.products (id int, name text)").await.unwrap();

service.exec_query(
"INSERT INTO foo.orders (customer_id, product_id, amount) VALUES ('a', 1, 10), ('b', 2, 2), ('b', 2, 3)"
).await.unwrap();

service.exec_query(
"INSERT INTO foo.customers (id, city, state) VALUES ('a', 'San Francisco', 'CA'), ('b', 'New York', 'NY')"
).await.unwrap();

service.exec_query(
"INSERT INTO foo.products (id, name) VALUES (1, 'Potato'), (2, 'Tomato')"
).await.unwrap();

let result = service.exec_query(
"SELECT c.city, p.name, sum(o.amount) FROM foo.orders o \
LEFT JOIN foo.customers c ON o.customer_id = c.id \
LEFT JOIN foo.products p ON o.product_id = p.id \
GROUP BY 1, 2 ORDER BY 3 DESC"
).await.unwrap();

assert_eq!(result.get_rows()[0], Row::new(vec![TableValue::String("San Francisco".to_string()), TableValue::String("Potato".to_string()), TableValue::Int(10)]));
assert_eq!(result.get_rows()[1], Row::new(vec![TableValue::String("New York".to_string()), TableValue::String("Tomato".to_string()), TableValue::Int(5)]));
}).await;
}

#[tokio::test]
async fn in_list() {
Config::run_test("in_list", async move |services| {
Expand Down

0 comments on commit b776398

Please sign in to comment.