Skip to content

Commit 4390e63

Browse files
committedDec 19, 2024
Handle window function frame cause appropriately
1 parent 9d56d33 commit 4390e63

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎metricflow-semantics/metricflow_semantics/sql/sql_exprs.py

+14
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,20 @@ def requires_ordering(self) -> bool:
10341034
else:
10351035
assert_values_exhausted(self)
10361036

1037+
@property
1038+
def allows_frame_clause(self) -> bool:
1039+
"""Whether the function allows a frame clause, e.g., 'ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING'."""
1040+
if (
1041+
self is SqlWindowFunction.FIRST_VALUE
1042+
or self is SqlWindowFunction.LAST_VALUE
1043+
or self is SqlWindowFunction.AVERAGE
1044+
):
1045+
return True
1046+
if self is SqlWindowFunction.ROW_NUMBER or self is SqlWindowFunction.LAG:
1047+
return False
1048+
else:
1049+
assert_values_exhausted(self)
1050+
10371051
@classmethod
10381052
def get_window_function_for_period_agg(cls, period_agg: PeriodAggregation) -> SqlWindowFunction:
10391053
"""Get the window function to use for given period agg option."""

‎metricflow/sql/render/expr_renderer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def visit_window_function_expr(self, node: SqlWindowFunctionExpression) -> SqlEx
428428
)
429429
)
430430

431-
if len(order_by_args_rendered) > 0:
431+
if len(order_by_args_rendered) > 0 and node.sql_function.allows_frame_clause:
432432
window_string_lines.append("ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING")
433433

434434
window_string = "\n".join(window_string_lines)

0 commit comments

Comments
 (0)