enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.34k stars 320 forks source link

`date_diff` operation works differently on Postgres and Snowflake #10438

Closed radeusgd closed 1 month ago

radeusgd commented 2 months ago

In either backend our date_diff operation delegates to SQL DATE_DIFF/DATEDIFF.

However, the two backends have differing semantics in some edge cases.

See parts of the test "should allow computing a SQL-like difference":

t1 = table_builder [["X", [Date.new 2021 11 3]], ["Y", [Date.new 2021 12 5]]]
(t1.at "X").date_diff (Date.new 2021 12 1) Date_Period.Month . to_vector . should_equal [0]

In the Snowflake backend this yields 1 instead of 0.

That is because, as documented, when computing a month difference, only year and month fields are considered - so the DB sees that the month differs and returns 1, disregarding the day field that shows us that not a full month passed yet.

In Snowflake we can check that even:

SELECT DATEDIFF('month', '2021-11-30', '2021-12-01')

which compares two dates just 1 day apart, still yields a 1 month difference if asked for months.

radeusgd commented 2 months ago

Possible solutions: