Skip to content

Commit

Permalink
fix(mysql): remove not-allowed frame clause from rank window function
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Feb 12, 2024
1 parent 2ceb5a6 commit ee96cef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ibis/backends/mysql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
rewrite_last_to_last_value,
)
from ibis.common.patterns import replace
from ibis.expr.rewrites import p, rewrite_sample
from ibis.expr.rewrites import p, rewrite_sample, y

MySQL.Generator.TRANSFORMS |= {
sge.LogicalOr: rename_func("max"),
Expand Down Expand Up @@ -56,6 +56,13 @@ def rewrite_limit(_, **kwargs):
return _


@replace(p.WindowFunction(p.MinRank | p.DenseRank, y @ p.WindowFrame(start=None)))
def exclude_unsupported_window_frame_from_rank(_, y):
return ops.Subtract(
_.copy(frame=y.copy(start=None, end=0, order_by=y.order_by or (ops.NULL,))), 1
)


@public
class MySQLCompiler(SQLGlotCompiler):
__slots__ = ()
Expand All @@ -68,6 +75,7 @@ class MySQLCompiler(SQLGlotCompiler):
rewrite_first_to_first_value,
rewrite_last_to_last_value,
exclude_unsupported_window_frame_from_ops,
exclude_unsupported_window_frame_from_rank,
exclude_unsupported_window_frame_from_row_number,
rewrite_empty_order_by_window,
*SQLGlotCompiler.rewrites,
Expand Down

0 comments on commit ee96cef

Please sign in to comment.