airflow.providers.databricks.operators.genie¶
Operators for asking Databricks Genie spaces questions as standalone tasks.
Attributes¶
Classes¶
Ask a Databricks Genie space one question and return a bounded, structured answer. |
Module Contents¶
- class airflow.providers.databricks.operators.genie.DatabricksGenieOperator(*, space_id, question=None, databricks_conn_id='databricks_default', conversation_id=None, message_id=None, polling_period_seconds=5, timeout=1800, resubmit_unconfirmed=False, databricks_retry_limit=3, databricks_retry_delay=1, deferrable=conf.getboolean('operators', 'default_deferrable', fallback=False), durable=None, **kwargs)[source]¶
Bases:
airflow.providers.common.compat.sdk.ResumableJobMixin,airflow.providers.common.compat.sdk.BaseOperatorAsk a Databricks Genie space one question and return a bounded, structured answer.
The operator submits the question once, persists the Genie conversation and message IDs to task state before waiting, then polls (or defers) until the message finishes. With durable execution (the default on Airflow 3.3 and later), a retry after a worker crash or timeout reconnects to the stored message instead of asking again. With
durable=False, or on older Airflow without the task state store, every try asks again.Genie has no idempotency key, so a submission whose outcome is unknown (a timeout, a connection error or a 5xx response) cannot be told apart from one that was never received. The operator fails without retrying in that case. A later try that still finds the unconfirmed submission in task state refuses to submit again; set
conversation_idandmessage_idto attach to the message you found, orresubmit_unconfirmed=Trueto ask again. A clear that discards task state (the default from Airflow 3.4) asks again without that check.See also
For more information on how to use this operator, take a look at the guide: Ask a Databricks Genie space
- Parameters:
space_id (str) – Genie space ID. (templated)
question (str | None) – Question to ask. Required unless
message_idis set. (templated)databricks_conn_id (str) – Databricks connection. Defaults to
databricks_default. (templated)conversation_id (str | None) – Existing conversation to ask the question in. The operator never deletes it. Defaults to
None, which starts a new conversation. An empty string meansNone. (templated)message_id (str | None) – Existing message to wait for instead of asking a question. Requires
conversation_id. An empty string meansNone. A fixed value applies to every Dag run, so prefer a run-scoped template such as"{{ params.genie_message_id }}". (templated)polling_period_seconds (float) – Seconds between status checks. Defaults to
5.timeout (float) – Maximum seconds to wait for the answer in one try. Timing out does not cancel the message. With durable execution the next try reconnects to it; with
durable=False, or on Airflow before 3.3, the next try asks again. Defaults to1800.resubmit_unconfirmed (bool) – Ask the question again even though an earlier submission’s outcome is unknown and may have created a message. Defaults to
False.databricks_retry_limit (int) – Attempts for each Genie read. Submissions are never retried. Defaults to
3.databricks_retry_delay (float) – Minimum seconds between read attempts. Defaults to
1.deferrable (bool) – Release the worker while waiting. Defaults to
[operators] default_deferrable, with a fallback ofFalse.durable (bool | None) – When
True(the default), the Genie message IDs are persisted to task state before waiting so a retry reconnects instead of asking again. Requires Airflow 3.3+; on earlier versions every try asks the question again.
- template_fields: collections.abc.Sequence[str] = ('space_id', 'question', 'databricks_conn_id', 'conversation_id', 'message_id')[source]¶
- execute(context)[source]¶
Derive when creating an operator.
The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.
Refer to get_template_context for more context.
- submit_job(context)[source]¶
Submit the job to the external system. Return its external ID.
The returned ID must not be
None, aNonereturn is treated as “no ID available” and the ID will not be persisted to task state.
- get_job_status(external_id, context)[source]¶
Query the external system for the current job status.
contextis provided so implementations can use it if needed to implement advanced features such as:cache terminal status to
task_state_storewhen the remote resource may be ephemeral (e.g. a K8s driver pod that gets garbage-collected after completion),
- is_job_active(status)[source]¶
Return True if the job is still running and can be reconnected to.
statusis a raw string returned by the external system — not an Airflow enum. Its values are backend-specific (e.g."RUNNING","Pending","ContainerCreating").
- is_job_succeeded(status)[source]¶
Return True if the job completed successfully.
statusis a raw string returned by the external system — not an Airflow enum. Its values are backend-specific (e.g."FINISHED","Succeeded").
- poll_until_complete(external_id, context)[source]¶
Wait for the message and return its bounded result.
execute_resumablereturns this value directly when it reconnects to an active message, so polling returns the result instead ofNone.