Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: row_number() with .select() doesn't have OVER ... clause when used after join (.mutate() works correctly) #10261

Open
1 task done
NickCrews opened this issue Oct 1, 2024 · 0 comments
Labels
bug Incorrect behavior inside of ibis

Comments

@NickCrews
Copy link
Contributor

NickCrews commented Oct 1, 2024

What happened?

import ibis

be = ibis.get_backend()

t1 = be.create_table("t1", {"x": [1, 2, 3]}, overwrite=True)
t2 = be.create_table("t2", {"x": [2, 3, 4]}, overwrite=True)
j = t1.join(t2, "x")
rn_mutate = j.mutate(rn=ibis.row_number())
ibis.to_sql(rn_mutate)
# SELECT
#   "t4"."x",
#   ROW_NUMBER() OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "rn"
# FROM (
#   SELECT
#     "t2"."x"
#   FROM "memory"."main"."t1" AS "t2"
#   INNER JOIN "memory"."main"."t2" AS "t3"
#     ON "t2"."x" = "t3"."x"
# ) AS "t4"
rn_select = j.select(*j.columns, rn=ibis.row_number())
ibis.to_sql(rn_select)
# SELECT
#   "t2"."x",
#   ROW_NUMBER() AS "rn"
# FROM "memory"."main"."t1" AS "t2"
# INNER JOIN "memory"."main"."t2" AS "t3"
#   ON "t2"."x" = "t3"."x"

If I try to execute the rn_select, I get Catalog Error: Scalar Function with name row_number does not exist!

We are just missing the OVER ... clause: If we add it, then it works:

be.sql(
 """
SELECT
  "t2"."x",
  ROW_NUMBER() OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS "rn"
FROM "memory"."main"."t1" AS "t2"
INNER JOIN "memory"."main"."t2" AS "t3"
  ON "t2"."x" = "t3"."x"
"""
)

What version of ibis are you using?

main

What backend(s) are you using, if any?

All backends probably suffer from this?

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@NickCrews NickCrews added the bug Incorrect behavior inside of ibis label Oct 1, 2024
@NickCrews NickCrews changed the title bug: row_number() with .select() doesn't have OVER ... clause (.mutate() works correctly) bug: row_number() with .select() doesn't have OVER ... clause when used after join (.mutate() works correctly) Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis
Projects
Status: backlog
Development

No branches or pull requests

1 participant