ashb commented on code in PR #66696:
URL: https://github.com/apache/airflow/pull/66696#discussion_r3217575378


##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -898,6 +898,35 @@ def is_active(self) -> bool:
         )
 
 
+class NullableDatetimeRangeFilter(RangeFilter):
+    """
+    RangeFilter for nullable datetime columns that preserves NULL-as-now 
semantics.
+
+    Uses explicit OR conditions instead of COALESCE(column, now()) so 
PostgreSQL
+    can use btree indexes on each branch via BitmapOr plans rather than forcing
+    a full table scan.
+    """
+
+    def to_orm(self, select: Select) -> Select:
+        if self.value is None:
+            return select
+
+        if self.value.lower_bound_gte:
+            x = self.value.lower_bound_gte
+            select = select.where(or_(self.attribute >= x, 
and_(self.attribute.is_(None), func.now() >= x)))
+        if self.value.lower_bound_gt:
+            x = self.value.lower_bound_gt
+            select = select.where(or_(self.attribute > x, 
and_(self.attribute.is_(None), func.now() > x)))
+        if self.value.upper_bound_lte:
+            x = self.value.upper_bound_lte
+            select = select.where(or_(self.attribute <= x, 
and_(self.attribute.is_(None), func.now() <= x)))
+        if self.value.upper_bound_lt:
+            x = self.value.upper_bound_lt
+            select = select.where(or_(self.attribute < x, 
and_(self.attribute.is_(None), func.now() < x)))

Review Comment:
   If we are looking to optimize: if lower and upper bound is set, can we use 
`BETWEEN`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to