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: MSSQL RANK OVER does not support row clause #10291

Closed
1 task done
kalo37 opened this issue Oct 9, 2024 · 1 comment · Fixed by #10302
Closed
1 task done

bug: MSSQL RANK OVER does not support row clause #10291

kalo37 opened this issue Oct 9, 2024 · 1 comment · Fixed by #10302
Labels
bug Incorrect behavior inside of ibis

Comments

@kalo37
Copy link

kalo37 commented Oct 9, 2024

What happened?

It looks like if rows are not specified when calling .over(), by default the compiler will add "UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING" to the rows clause. This causes issue with T-SQL since the rows clause cannot be specified when using its ranking functions.

When executing the query, this causes a SQL error saying "The function "rank" may not have a window frame"

Compiled:

SELECT 
[t0].[col1], 
[t0].[col2], 
[t0].[col3], 
RANK() OVER (PARTITION BY [t0].[PfId] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) - 1 AS [rank_] 
FROM table [t0]

The query would work after removing ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING

What version of ibis are you using?

10.0.0dev97

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

MSSQL

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@IndexSeek
Copy link
Member

Thank you for reporting this! I could reproduce this and was getting a similar error.

data = {
    "color": ["E", "E", "E", "I", "J"],
    "price": [326, 326, 327, 334, 335],
}

df = pd.DataFrame(data)

con.create_table("diamonds_sample", df, overwrite=True)
expr = con.table("diamonds_sample").mutate(ibis.rank().over(group_by="color", order_by="price"))
expr

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
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants