sunank200 commented on code in PR #37101:
URL: https://github.com/apache/airflow/pull/37101#discussion_r1498995225


##########
airflow/datasets/__init__.py:
##########
@@ -55,3 +55,13 @@ def __eq__(self, other):
 
     def __hash__(self):
         return hash(self.uri)
+
+    def __or__(self, other):
+        from airflow.models.dataset import DatasetAny

Review Comment:
   The code is changed  now



##########
airflow/models/dataset.py:
##########
@@ -341,9 +341,9 @@ def __repr__(self) -> str:
 
 class DatasetBooleanCondition:
     """
-    Base class for boolean logic for dataset triggers.
+    Base class for boolean conditions on datasets. This class is intended for 
internal use only.
 
-    :meta private:

Review Comment:
   code is changed after rebase and this taken care of.



##########
airflow/serialization/serialized_objects.py:
##########
@@ -407,6 +407,8 @@ def serialize_to_json(
                 serialized_object[key] = encode_timetable(value)
             elif key == "dataset_triggers":
                 serialized_object[key] = cls.serialize(value)
+            elif key == "dataset_triggers":
+                serialized_object[key] = cls.serialize(value)

Review Comment:
   Changed it. I think it was messed during rebased



##########
tests/serialization/test_dag_serialization.py:
##########
@@ -554,6 +554,9 @@ def validate_deserialized_dag(self, serialized_dag, dag):
         compare_serialization_list = {
             "dataset_triggers",
         }
+        compare_serialization_list = {
+            "dataset_triggers",
+        }

Review Comment:
   Changed it.I think is was messed during rebase.



##########
airflow/datasets/__init__.py:
##########
@@ -55,3 +55,13 @@ def __eq__(self, other):
 
     def __hash__(self):
         return hash(self.uri)
+
+    def __or__(self, other):
+        from airflow.models.dataset import DatasetAny

Review Comment:
   It was to deal with cyclic imports



##########
airflow/models/dataset.py:
##########
@@ -374,12 +386,96 @@ def all_datasets(self) -> dict[str, Dataset]:
 
 
 class DatasetAny(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "and" relationship."""
+    """
+    Represents a logical OR condition of datasets.
+
+    Inherits from DatasetBooleanCondition.
+    """
 
     agg_func = any
 
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):

Review Comment:
   changed.



##########
airflow/models/dataset.py:
##########
@@ -374,12 +386,96 @@ def all_datasets(self) -> dict[str, Dataset]:
 
 
 class DatasetAny(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "and" relationship."""
+    """
+    Represents a logical OR condition of datasets.
+
+    Inherits from DatasetBooleanCondition.
+    """
 
     agg_func = any
 
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(*self.objects, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(self, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAny({', '.join(map(str, self.objects))})"
+
 
 class DatasetAll(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "or" relationship."""
+    """Represents a logical AND condition of datasets. Inherits from 
DatasetBooleanCondition."""
 
     agg_func = all
+
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(self, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(*self.objects, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAnd({', '.join(map(str, self.objects))})"
+
+
+class DatasetsExpression:
+    """
+    Represents a node in an expression tree for dataset conditions.
+
+    :param value: The value of the node, which can be a 'Dataset', '&', or '|'.
+    :param left: The left child node.
+    :param right: The right child node.
+    """
+
+    def __init__(self, value, left=None, right=None):

Review Comment:
   Changed it



##########
airflow/models/dataset.py:
##########
@@ -374,12 +386,96 @@ def all_datasets(self) -> dict[str, Dataset]:
 
 
 class DatasetAny(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "and" relationship."""
+    """
+    Represents a logical OR condition of datasets.
+
+    Inherits from DatasetBooleanCondition.
+    """
 
     agg_func = any
 
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(*self.objects, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(self, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAny({', '.join(map(str, self.objects))})"
+
 
 class DatasetAll(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "or" relationship."""
+    """Represents a logical AND condition of datasets. Inherits from 
DatasetBooleanCondition."""
 
     agg_func = all
+
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(self, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(*self.objects, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAnd({', '.join(map(str, self.objects))})"

Review Comment:
   Changed it



##########
airflow/models/dataset.py:
##########
@@ -341,9 +341,9 @@ def __repr__(self) -> str:
 
 class DatasetBooleanCondition:
     """
-    Base class for boolean logic for dataset triggers.
+    Base class for boolean conditions on datasets. This class is intended for 
internal use only.
 
-    :meta private:
+    :param objects: A variable number of Dataset, DatasetAny, or DatasetAll 
instances.

Review Comment:
   code is changed after rebase and this taken care of.



##########
airflow/models/dataset.py:
##########
@@ -374,12 +386,96 @@ def all_datasets(self) -> dict[str, Dataset]:
 
 
 class DatasetAny(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "and" relationship."""
+    """
+    Represents a logical OR condition of datasets.
+
+    Inherits from DatasetBooleanCondition.
+    """
 
     agg_func = any
 
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(*self.objects, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(self, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAny({', '.join(map(str, self.objects))})"
+
 
 class DatasetAll(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "or" relationship."""
+    """Represents a logical AND condition of datasets. Inherits from 
DatasetBooleanCondition."""
 
     agg_func = all
+
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(self, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(*self.objects, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAnd({', '.join(map(str, self.objects))})"
+
+
+class DatasetsExpression:
+    """
+    Represents a node in an expression tree for dataset conditions.
+
+    :param value: The value of the node, which can be a 'Dataset', '&', or '|'.
+    :param left: The left child node.
+    :param right: The right child node.
+    """
+
+    def __init__(self, value, left=None, right=None):
+        self.value = value  # value can be 'Dataset', '&', or '|'
+        self.left = left
+        self.right = right
+
+    def __or__(self, other: Dataset | DatasetsExpression) -> 
DatasetsExpression:
+        return DatasetsExpression("|", self, other)
+
+    def __and__(self, other: Dataset | DatasetsExpression) -> 
DatasetsExpression:
+        return DatasetsExpression("&", self, other)
+
+    def __repr__(self):
+        if isinstance(self.value, Dataset):
+            return f"Dataset(uri='{self.value.uri}')"
+        elif self.value == "&":
+            return repr(DatasetAll(self.left, self.right))
+        elif self.value == "|":
+            return repr(DatasetAny(self.left, self.right))
+

Review Comment:
   Added else part now



##########
airflow/models/dataset.py:
##########
@@ -374,12 +386,96 @@ def all_datasets(self) -> dict[str, Dataset]:
 
 
 class DatasetAny(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "and" relationship."""
+    """
+    Represents a logical OR condition of datasets.
+
+    Inherits from DatasetBooleanCondition.
+    """
 
     agg_func = any
 
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(*self.objects, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(self, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAny({', '.join(map(str, self.objects))})"
+
 
 class DatasetAll(DatasetBooleanCondition):
-    """Use to combine datasets schedule references in an "or" relationship."""
+    """Represents a logical AND condition of datasets. Inherits from 
DatasetBooleanCondition."""
 
     agg_func = all
+
+    def __init__(self, *objects: Dataset | DatasetAny | DatasetAll):
+        """Initialize with one or more Dataset, DatasetAny, or DatasetAll 
instances."""
+        super().__init__(*objects)
+
+    def __or__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAny(self, other)
+        return NotImplemented
+
+    def __and__(self, other):
+        if isinstance(other, (Dataset, DatasetAny, DatasetAll)):
+            return DatasetAll(*self.objects, other)
+        return NotImplemented
+
+    def __repr__(self) -> str:
+        return f"DatasetAnd({', '.join(map(str, self.objects))})"
+
+
+class DatasetsExpression:
+    """
+    Represents a node in an expression tree for dataset conditions.
+
+    :param value: The value of the node, which can be a 'Dataset', '&', or '|'.
+    :param left: The left child node.
+    :param right: The right child node.
+    """
+
+    def __init__(self, value, left=None, right=None):
+        self.value = value  # value can be 'Dataset', '&', or '|'
+        self.left = left
+        self.right = right
+
+    def __or__(self, other: Dataset | DatasetsExpression) -> 
DatasetsExpression:
+        return DatasetsExpression("|", self, other)
+
+    def __and__(self, other: Dataset | DatasetsExpression) -> 
DatasetsExpression:
+        return DatasetsExpression("&", self, other)
+
+    def __repr__(self):

Review Comment:
   Changed it



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to