Skip to content

Commit bfdebac

Browse files
authored
Fixing bug with test broker_gen2 (#392)
The actual defog SQL text is as follows: ```sql SELECT COUNT(t.sbTxCustId) AS transaction_count FROM sbTransaction AS t JOIN sbCustomer AS c ON t.sbTxCustId = c.sbCustId WHERE c.sbCustJoinDate >= date('now', '-70 days') ``` But the current PyDough implemnetation uses `DATETIME("now", "-70 days")` which does not truncate to the start of the day. To fix this, changed it to `DATETIME("now", "-70 days", "start of day")` so it is the same as the refsol.
1 parent 85838f5 commit bfdebac

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

tests/test_pydough_functions/defog_test_functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ def impl_defog_broker_gen2():
579579
Return the number of transactions by users who joined in the past 70
580580
days.
581581
"""
582-
selected_tx = transactions.WHERE(customer.join_date >= DATETIME("now", "-70 days"))
582+
selected_tx = transactions.WHERE(
583+
customer.join_date >= DATETIME("now", "-70 days", "start of day")
584+
)
583585

584586
return Broker.CALCULATE(transaction_count=COUNT(selected_tx.customer_id))
585587

tests/test_sql_refsols/defog_broker_gen2_ansi.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ SELECT
33
FROM main.sbtransaction AS sbtransaction
44
JOIN main.sbcustomer AS sbcustomer
55
ON sbcustomer.sbcustid = sbtransaction.sbtxcustid
6-
AND sbcustomer.sbcustjoindate >= DATE_ADD(CURRENT_TIMESTAMP(), -70, 'DAY')
6+
AND sbcustomer.sbcustjoindate >= DATE_TRUNC('DAY', DATE_ADD(CURRENT_TIMESTAMP(), -70, 'DAY'))

tests/test_sql_refsols/defog_broker_gen2_sqlite.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ SELECT
33
FROM main.sbtransaction AS sbtransaction
44
JOIN main.sbcustomer AS sbcustomer
55
ON sbcustomer.sbcustid = sbtransaction.sbtxcustid
6-
AND sbcustomer.sbcustjoindate >= DATETIME('now', '-70 day')
6+
AND sbcustomer.sbcustjoindate >= DATE(DATETIME('now', '-70 day'), 'start of day')

0 commit comments

Comments
 (0)