airflow.providers.databricks.operators.genie

Operators for asking Databricks Genie spaces questions as standalone tasks.

Attributes

GenieMessageRef

Classes

DatabricksGenieOperator

Ask a Databricks Genie space one question and return a bounded, structured answer.

Module Contents

airflow.providers.databricks.operators.genie.GenieMessageRef[source]
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.BaseOperator

Ask 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_id and message_id to attach to the message you found, or resubmit_unconfirmed=True to 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_id is 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 means None. (templated)

  • message_id (str | None) – Existing message to wait for instead of asking a question. Requires conversation_id. An empty string means None. 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 to 1800.

  • 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 of False.

  • 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]
ui_color = '#1CB1C2'[source]
external_id_key = 'databricks_genie_message'[source]
space_id[source]
question = None[source]
databricks_conn_id = 'databricks_default'[source]
conversation_id = None[source]
message_id = None[source]
polling_period_seconds = 5[source]
timeout = 1800[source]
resubmit_unconfirmed = False[source]
databricks_retry_limit = 3[source]
databricks_retry_delay = 1[source]
deferrable[source]
property hook: airflow.providers.databricks.hooks.genie.DatabricksGenieHook[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, a None return 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.

context is provided so implementations can use it if needed to implement advanced features such as:

  • cache terminal status to task_state_store when 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.

status is 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.

status is 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_resumable returns this value directly when it reconnects to an active message, so polling returns the result instead of None.

get_job_result(external_id, context)[source]

Return the job result after completion. Return None if not applicable.

execute_complete(context, event=None, *, ref)[source]

Was this entry helpful?