question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: filters not applied to joined tables

See original GitHub issue

Given, two tables, if they are joined, and then a filter is applied, the filter is actually being ignored:

import ibis

ibis.options.interactive = True

connection = ibis.sqlite.connect('data/geography.db')
countries = connection.table('countries')
gdp = connection.table('gdp')

expr = (countries.inner_join(gdp,
                             predicates=countries['iso_alpha3'] == gdp['country_code'])
                 .filter(gdp['year'] == 2017))
expr

Intuitively, the result should only contain the rows with year == 2017, but the filter is not applied.

The database in this example can be found at: https://github.com/datapythonista/ibis/tree/tutorial/docs/source/tutorial/data

The SQL compiled from the expression, can be obtained with:

>>> str(expr.compile())
SELECT t0.iso_alpha2, t0.iso_alpha3, t0.iso_numeric, t0.fips, t0.name, t0.capital, t0.area_km2, t0.population, t0.continent, t0.country_code, t0.year, t0.value 
FROM (SELECT t1.iso_alpha2 AS iso_alpha2, t1.iso_alpha3 AS iso_alpha3, t1.iso_numeric AS iso_numeric, t1.fips AS fips, t1.name AS name, t1.capital AS capital, t1.area_km2 AS area_km2, t1.population AS population, t1.continent AS continent, t2.country_code AS country_code, t2.year AS year, t2.value AS value 
FROM base.countries AS t1 JOIN base.gdp AS t2 ON t1.iso_alpha3 = t2.country_code) AS t0, base.gdp 
WHERE base.gdp.year = ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
cpcloudcommented, Jan 4, 2022

A third alternative is to call materialize in the filter:

import ibis

connection = ibis.sqlite.connect("docs/source/tutorial/data/geography.db")
countries = connection.table("countries")
gdp = connection.table("gdp")

expr = countries.inner_join(
    gdp, predicates=countries["iso_alpha3"] == gdp["country_code"]
).filter(lambda t: t.materialize()["year"] == 2017)
1reaction
datapythonistacommented, Oct 19, 2020

I would like to release after finishing the refactoring of the backends. Whenever that happens, but I think it’ll probably be in one week or two. If this is implemented by then it can surely be released, but I don’t see this as a blocker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why a filter is not applying to another joined table?
Solved: I'm trying to filter all people who have had a meeting from the activity table and list the Skills attached from the...
Read more >
"Filtering in related table could not be applied" error
This article describes a reason and possible resolution for the "Filtering in related table could not be applied" error.
Read more >
Create and manage relationships in Power BI Desktop
If you query two or more tables at the same time, when the data is loaded, Power BI Desktop attempts to find and...
Read more >
Templated Filters and Derived Tables - Variable not found ...
Derived tables are a common use case for applying templated filters. This is because templated filters allow us to restrict tables to ...
Read more >
[Compiling error] Filtering On field from aggregate left join table
Add this filter in the join condition instead of the filter tab. It will probably fix your issue. Checking for nullidentifier on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found