w.command_execution
: Command Execution¶
- class databricks.sdk.service.compute.CommandExecutionAPI¶
This API allows execution of Python, Scala, SQL, or R commands on running Databricks Clusters.
- cancel([, cluster_id: Optional[str], command_id: Optional[str], context_id: Optional[str]]) Wait[CommandStatusResponse] ¶
Cancel a command.
Cancels a currently running command within an execution context.
The command ID is obtained from a prior successful call to __execute__.
- Parameters:
cluster_id – str (optional)
command_id – str (optional)
context_id – str (optional)
- Returns:
Long-running operation waiter for
CommandStatusResponse
. See :method:wait_command_status_command_execution_cancelled for more details.
- cancel_and_wait([, cluster_id: Optional[str], command_id: Optional[str], context_id: Optional[str], timeout: datetime.timedelta = 0:20:00]) CommandStatusResponse ¶
- command_status(cluster_id: str, context_id: str, command_id: str) CommandStatusResponse ¶
Get command info.
Gets the status of and, if available, the results from a currently executing command.
The command ID is obtained from a prior successful call to __execute__.
- Parameters:
cluster_id – str
context_id – str
command_id – str
- Returns:
- context_status(cluster_id: str, context_id: str) ContextStatusResponse ¶
Get status.
Gets the status for an execution context.
- Parameters:
cluster_id – str
context_id – str
- Returns:
- create([, cluster_id: Optional[str], language: Optional[Language]]) Wait[ContextStatusResponse] ¶
Usage:
import os from databricks.sdk import WorkspaceClient from databricks.sdk.service import compute w = WorkspaceClient() cluster_id = os.environ["TEST_DEFAULT_CLUSTER_ID"] context = w.command_execution.create(cluster_id=cluster_id, language=compute.Language.PYTHON).result() # cleanup w.command_execution.destroy(cluster_id=cluster_id, context_id=context.id)
Create an execution context.
Creates an execution context for running cluster commands.
If successful, this method returns the ID of the new execution context.
- Parameters:
cluster_id – str (optional) Running cluster id
language –
Language
(optional)
- Returns:
Long-running operation waiter for
ContextStatusResponse
. See :method:wait_context_status_command_execution_running for more details.
- create_and_wait([, cluster_id: Optional[str], language: Optional[Language], timeout: datetime.timedelta = 0:20:00]) ContextStatusResponse ¶
- destroy(cluster_id: str, context_id: str)¶
Delete an execution context.
Deletes an execution context.
- Parameters:
cluster_id – str
context_id – str
- execute([, cluster_id: Optional[str], command: Optional[str], context_id: Optional[str], language: Optional[Language]]) Wait[CommandStatusResponse] ¶
Usage:
import os from databricks.sdk import WorkspaceClient from databricks.sdk.service import compute w = WorkspaceClient() cluster_id = os.environ["TEST_DEFAULT_CLUSTER_ID"] context = w.command_execution.create(cluster_id=cluster_id, language=compute.Language.PYTHON).result() text_results = w.command_execution.execute(cluster_id=cluster_id, context_id=context.id, language=compute.Language.PYTHON, command="print(1)").result() # cleanup w.command_execution.destroy(cluster_id=cluster_id, context_id=context.id)
Run a command.
Runs a cluster command in the given execution context, using the provided language.
If successful, it returns an ID for tracking the status of the command’s execution.
- Parameters:
cluster_id – str (optional) Running cluster id
command – str (optional) Executable code
context_id – str (optional) Running context id
language –
Language
(optional)
- Returns:
Long-running operation waiter for
CommandStatusResponse
. See :method:wait_command_status_command_execution_finished_or_error for more details.
- execute_and_wait([, cluster_id: Optional[str], command: Optional[str], context_id: Optional[str], language: Optional[Language], timeout: datetime.timedelta = 0:20:00]) CommandStatusResponse ¶
- wait_command_status_command_execution_cancelled(cluster_id: str, command_id: str, context_id: str, timeout: datetime.timedelta = 0:20:00, callback: Optional[Callable[[CommandStatusResponse], None]]) CommandStatusResponse ¶
- wait_command_status_command_execution_finished_or_error(cluster_id: str, command_id: str, context_id: str, timeout: datetime.timedelta = 0:20:00, callback: Optional[Callable[[CommandStatusResponse], None]]) CommandStatusResponse ¶
- wait_context_status_command_execution_running(cluster_id: str, context_id: str, timeout: datetime.timedelta = 0:20:00, callback: Optional[Callable[[ContextStatusResponse], None]]) ContextStatusResponse ¶