You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a column from a joined table is used in by, it is ignoring the join condition.
For example, take the orders table from the blaze docs:
create table products (
id integer primary key,
name text
);
create table orders (
id integer primary key,
product_id integer references products(id),
quantity integer
);
Using that database as source:
>>> from blaze import data, by, merge, compute
>>> url = "postgresql:///testdb"
>>> d = data(url)
Using a joined column correctly uses the join condition:
>>> print(compute(d.orders.product_id.name))
SELECT products.name
FROM products, orders
WHERE orders.product_id = products.id
But using the same in by ignore the join condition completely:
>>> print(compute(by(d.orders.product_id.name, count=d.orders.id.count())))
SELECT products.name, count(orders.id) AS count
FROM products, orders GROUP BY products.name
The correct query is:
SELECT products.name, count(orders.id) AS count
FROM products, orders
WHERE orders.product_id = products.id
GROUP BY products.name
Activity