From 57bb0bb313397acda3708037f6edca4e1a5e7fbc Mon Sep 17 00:00:00 2001 From: khamitovdr Date: Fri, 11 Oct 2024 12:53:11 +0300 Subject: [PATCH] Added support for quarter interval --- .../formula/definitions/functions_datetime.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dl_connector_oracle/dl_connector_oracle/formula/definitions/functions_datetime.py b/lib/dl_connector_oracle/dl_connector_oracle/formula/definitions/functions_datetime.py index c317eb6cb..3ca203bab 100644 --- a/lib/dl_connector_oracle/dl_connector_oracle/formula/definitions/functions_datetime.py +++ b/lib/dl_connector_oracle/dl_connector_oracle/formula/definitions/functions_datetime.py @@ -59,7 +59,18 @@ class FuncDatetrunc2Oracle(base.FuncDatetrunc2): DEFINITIONS_DATETIME = [ # dateadd base.FuncDateadd1.for_dialect(D.ORACLE), - base.FuncDateadd2Unit.for_dialect(D.ORACLE), + base.FuncDateadd2Unit( + variants=[ + V( + D.ORACLE, + lambda date, what: ( + sa.cast(date + datetime_interval(un_literal(what), 1, literal_mult=True), sa.Date) + if un_literal(what).lower() != "quarter" + else sa.cast(date + datetime_interval("month", 3, literal_mult=True), sa.Date) + ), + ), + ] + ), base.FuncDateadd2Number.for_dialect(D.ORACLE), base.FuncDateadd3Legacy.for_dialect(D.ORACLE), base.FuncDateadd3DateConstNum( @@ -68,6 +79,8 @@ class FuncDatetrunc2Oracle(base.FuncDatetrunc2): D.ORACLE, lambda date, what, num: ( sa.cast(date + datetime_interval(un_literal(what), un_literal(num), literal_mult=True), sa.Date) + if un_literal(what).lower() != "quarter" + else sa.cast(date + datetime_interval("month", 3 * un_literal(num), literal_mult=True), sa.Date) ), ), ] @@ -78,6 +91,8 @@ class FuncDatetrunc2Oracle(base.FuncDatetrunc2): D.ORACLE, lambda dt, what, num: ( sa.cast(dt + datetime_interval(what.value, num.value, literal_mult=True), sa.Date) + if what.value.lower() != "quarter" + else sa.cast(dt + datetime_interval("month", 3 * num.value, literal_mult=True), sa.Date) ), ), ]