GithubHelp home page GithubHelp logo

a inner join sql return wrong results about polars HOT 7 CLOSED

l1t1 avatar l1t1 commented on September 27, 2024 1
a inner join sql return wrong results

from polars.

Comments (7)

ion-elgreco avatar ion-elgreco commented on September 27, 2024

Similar thing happens to cross join: #11927

from polars.

l1t1 avatar l1t1 commented on September 27, 2024

seems left join also wrong

df = pl.DataFrame({
    "id":['1','2','3']
})

df2 = pl.DataFrame({
    "id":['4','5','6']
})
ctx = pl.SQLContext(df=df, df2=df2)

lp1=ctx.execute(
    """
    SELECT df.id as id1,df2.id as id2
    FROM df
        left JOIN df2
    on df.id=df2.id
    """,
    eager=False,
)
lp1.collect()
shape: (3, 2)
┌─────┬─────┐
│ id1 ┆ id2 │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═════╡
│ 11   │
│ 22   │
│ 33   │
└─────┴─────┘

should returns

shape: (3, 2)
┌─────┬─────┐
│ id1 ┆ id2 │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═════╡
│ 1   ┆ null   │
│ 2   ┆ null   │
│ 3   ┆ null   │
└─────┴─────┘

from polars.

ritchie46 avatar ritchie46 commented on September 27, 2024

@universalmind303 can you take a look here? It seems we create wrong plans somehow, as it only happens in SQL.

from polars.

alexander-beedie avatar alexander-beedie commented on September 27, 2024

Triage:

  • For the first query: we don't actually recognise/support implicit join syntax (at all) yet, so it gets parsed (incorrectly) as a simple filter op where A == B. I'll have to see if we can identify the implicit join syntax and either generate the equivalent inner join or raise an error.

  • For the second query: it seems we aren't resolving the post-join column selection properly here. We're doing the join correctly, but then returning only the cols from the left hand table. Will look at this first 🤔

from polars.

l1t1 avatar l1t1 commented on September 27, 2024

SELECT t.A, t.fruits, t1.B, t1.cars FROM t, t1 WHERE t.A=t1.B still returns wrong result in version 10. 20.31

from polars.

alexander-beedie avatar alexander-beedie commented on September 27, 2024

SELECT t.A, t.fruits, t1.B, t1.cars FROM t, t1 WHERE t.A=t1.B still returns wrong result in version 10. 20.31

Indeed - as mentioned earlier we don't support implicit join syntax at the moment; can you confirm that the other error is fixed and open an issue for implicit join syntax as a new feature request? (Easier for us to track open/closed issues if they are distinct) 😎👍

from polars.

l1t1 avatar l1t1 commented on September 27, 2024

confirmed the inner join syntax works now

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.