Skip to content

Commit

Permalink
feat: add within function
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Jan 30, 2025
1 parent 707855c commit b1a6938
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import ibis.selectors as s
from ibis import _

from insights.insights.query_builders.sql_functions import handle_timespan


# aggregate functions
def count(
Expand Down Expand Up @@ -706,6 +708,21 @@ def date_sub(column, value, unit)
return column - ibis.interval(value, unit)


def within(column: ir.DateValue, timespan: str):
"""
def within(column, timespan)
Filter rows within a timespan. The timespan can be 'Last [N] [Parts]', 'Current [Parts]', or 'Next [N] [Parts]'.
Parts can be 'day', 'week', 'month', 'quarter', 'year' or 'fiscal year'.
Examples:
- within(order_date, 'Last 7 days')
- within(order_date, 'Current month')
- within(order_date, 'Next 2 weeks')
"""
return handle_timespan(column, timespan)


def now():
"""
def now()
Expand Down

0 comments on commit b1a6938

Please sign in to comment.