Skip to content

by ignores the join condition #1673

Open

Description

@anandology

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions