rawwar commented on code in PR #48507:
URL: https://github.com/apache/airflow/pull/48507#discussion_r2024138039
##########
providers/databricks/src/airflow/providers/databricks/hooks/databricks.py:
##########
@@ -189,6 +189,65 @@ def from_json(cls, data: str) -> ClusterState:
return ClusterState(**json.loads(data))
+class SQLStatementState:
+ """Utility class for the SQL statement state concept of Databricks
statements."""
+
+ SQL_STATEMENT_LIFE_CYCLE_STATES = [
+ "PENDING",
+ "RUNNING",
+ "SUCCEEDED",
+ "FAILED",
+ "CANCELED",
+ "CLOSED",
+ ]
+
+ def __init__(
+ self, state: str = "", error_code: str = "", error_message: str = "",
*args, **kwargs
+ ) -> None:
+ if state not in self.SQL_STATEMENT_LIFE_CYCLE_STATES:
+ raise AirflowException(
+ f"Unexpected SQL statement life cycle state: {state}: If the
state has "
+ "been introduced recently, please check the Databricks user "
+ "guide for troubleshooting information"
+ )
+
+ self.state = state
+ self.error_code = error_code
+ self.error_message = error_message
+
+ @property
+ def is_terminal(self) -> bool:
+ """True if the current state is a terminal state."""
+ return self.state in ("SUCCEEDED", "FAILED", "CANCELED", "CLOSED")
+
+ @property
+ def is_running(self) -> bool:
+ """True if the current state is running."""
+ return self.state in ("PENDING", "RUNNING")
+
+ @property
+ def is_successful(self) -> bool:
+ """True if the state is SUCCEEDED."""
+ return self.state == "SUCCEEDED"
+
+ def __eq__(self, other) -> bool:
+ return (
+ self.state == other.state
+ and self.error_code == other.error_code
+ and self.error_message == other.error_message
+ )
Review Comment:
```suggestion
def __eq__(self, other) -> bool:
if not isinstance(other, SQLStatementState):
return NotImplemented
return (
self.state == other.state
and self.error_code == other.error_code
and self.error_message == other.error_message
)
```
--
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]