commands

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimLeadingWhitespace

func TrimLeadingWhitespace(commandStr string) (newCommand string)

TrimLeadingWhitespace removes leading whitespace, so that Python code blocks that are embedded into Go code still could be interpreted properly.

Types

type CancelCommand

type CancelCommand struct {
	ClusterId string `json:"clusterId,omitempty"`

	CommandId string `json:"commandId,omitempty"`

	ContextId string `json:"contextId,omitempty"`
}

type Command

type Command struct {
	// Running cluster id
	ClusterId string `json:"clusterId,omitempty"`
	// Executable code
	Command string `json:"command,omitempty"`
	// Running context id
	ContextId string `json:"contextId,omitempty"`

	Language Language `json:"language,omitempty"`
}

type CommandExecutionAPI

type CommandExecutionAPI struct {
	// contains filtered or unexported fields
}

This API allows execution of Python, Scala, SQL, or R commands on running Databricks Clusters.

func NewCommandExecution

func NewCommandExecution(client *client.DatabricksClient) *CommandExecutionAPI

func (*CommandExecutionAPI) Cancel

func (a *CommandExecutionAPI) Cancel(ctx context.Context, request CancelCommand) error

Cancel a command

Cancels a currently running command within an execution context.

The command ID is obtained from a prior successful call to __execute__.

func (*CommandExecutionAPI) CancelAndWait

func (a *CommandExecutionAPI) CancelAndWait(ctx context.Context, cancelCommand CancelCommand, options ...retries.Option[CommandStatusResponse]) (*CommandStatusResponse, error)

Calls CommandExecutionAPI.Cancel and waits to reach Cancelled state

You can override the default timeout of 20 minutes by calling adding retries.Timeout[CommandStatusResponse](60*time.Minute) functional option.

func (*CommandExecutionAPI) CommandStatus

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__.

func (*CommandExecutionAPI) ContextStatus

Get status

Gets the status for an execution context.

func (*CommandExecutionAPI) Create

func (a *CommandExecutionAPI) Create(ctx context.Context, request CreateContext) (*Created, error)

Create an execution context

Creates an execution context for running cluster commands.

If successful, this method returns the ID of the new execution context.

func (*CommandExecutionAPI) CreateAndWait

func (a *CommandExecutionAPI) CreateAndWait(ctx context.Context, createContext CreateContext, options ...retries.Option[ContextStatusResponse]) (*ContextStatusResponse, error)

Calls CommandExecutionAPI.Create and waits to reach Running state

You can override the default timeout of 20 minutes by calling adding retries.Timeout[ContextStatusResponse](60*time.Minute) functional option.

func (*CommandExecutionAPI) Destroy

func (a *CommandExecutionAPI) Destroy(ctx context.Context, request DestroyContext) error

Delete an execution context

Deletes an execution context.

func (*CommandExecutionAPI) Execute

func (a *CommandExecutionAPI) Execute(ctx context.Context, request Command) (*Created, error)

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.

func (*CommandExecutionAPI) ExecuteAndWait

Calls CommandExecutionAPI.Execute and waits to reach Finished or Error state

You can override the default timeout of 20 minutes by calling adding retries.Timeout[CommandStatusResponse](60*time.Minute) functional option.

func (*CommandExecutionAPI) Impl

Impl returns low-level CommandExecution API implementation

func (*CommandExecutionAPI) WithImpl

WithImpl could be used to override low-level API implementations for unit testing purposes with github.com/golang/mock or other mocking frameworks.

type CommandExecutionService

type CommandExecutionService interface {

	// Cancel a command
	//
	// Cancels a currently running command within an execution context.
	//
	// The command ID is obtained from a prior successful call to __execute__.
	Cancel(ctx context.Context, request CancelCommand) error

	// 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__.
	CommandStatus(ctx context.Context, request CommandStatusRequest) (*CommandStatusResponse, error)

	// Get status
	//
	// Gets the status for an execution context.
	ContextStatus(ctx context.Context, request ContextStatusRequest) (*ContextStatusResponse, error)

	// Create an execution context
	//
	// Creates an execution context for running cluster commands.
	//
	// If successful, this method returns the ID of the new execution context.
	Create(ctx context.Context, request CreateContext) (*Created, error)

	// Delete an execution context
	//
	// Deletes an execution context.
	Destroy(ctx context.Context, request DestroyContext) error

	// 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.
	Execute(ctx context.Context, request Command) (*Created, error)
}

This API allows execution of Python, Scala, SQL, or R commands on running Databricks Clusters.

type CommandExecutor

type CommandExecutor interface {
	Execute(ctx context.Context, clusterID, language, commandStr string) Results
}

CommandExecutor creates a spark context and executes a command and then closes context

func NewCommandExecutor

func NewCommandExecutor(client *client.DatabricksClient) CommandExecutor

type CommandMock

type CommandMock func(commandStr string) Results

CommandMock mocks the execution of command

func (CommandMock) Execute

func (m CommandMock) Execute(_ context.Context, _, _, commandStr string) Results

type CommandStatus

type CommandStatus string
const CommandStatusCancelled CommandStatus = `Cancelled`
const CommandStatusCancelling CommandStatus = `Cancelling`
const CommandStatusError CommandStatus = `Error`
const CommandStatusFinished CommandStatus = `Finished`
const CommandStatusQueued CommandStatus = `Queued`
const CommandStatusRunning CommandStatus = `Running`

type CommandStatusRequest

type CommandStatusRequest struct {
	ClusterId string `json:"-" url:"clusterId"`

	CommandId string `json:"-" url:"commandId"`

	ContextId string `json:"-" url:"contextId"`
}

Get command info

type CommandStatusResponse

type CommandStatusResponse struct {
	Id string `json:"id,omitempty"`

	Results *Results `json:"results,omitempty"`

	Status CommandStatus `json:"status,omitempty"`
}

type CommandsHighLevelAPI

type CommandsHighLevelAPI struct {
	// contains filtered or unexported fields
}

CommandsHighLevelAPI exposes more friendly wrapper over command execution

func (*CommandsHighLevelAPI) Execute

func (a *CommandsHighLevelAPI) Execute(ctx context.Context, clusterID, language, commandStr string) Results

Execute creates a spark context and executes a command and then closes context Any leading whitespace is trimmed

type ContextStatus

type ContextStatus string
const ContextStatusError ContextStatus = `Error`
const ContextStatusPending ContextStatus = `Pending`
const ContextStatusRunning ContextStatus = `Running`

type ContextStatusRequest

type ContextStatusRequest struct {
	ClusterId string `json:"-" url:"clusterId"`

	ContextId string `json:"-" url:"contextId"`
}

Get status

type ContextStatusResponse

type ContextStatusResponse struct {
	Id string `json:"id,omitempty"`

	Status ContextStatus `json:"status,omitempty"`
}

type CreateContext

type CreateContext struct {
	// Running cluster id
	ClusterId string `json:"clusterId,omitempty"`

	Language Language `json:"language,omitempty"`
}

type Created

type Created struct {
	Id string `json:"id,omitempty"`
}

type DestroyContext

type DestroyContext struct {
	ClusterId string `json:"clusterId"`

	ContextId string `json:"contextId"`
}

type Language

type Language string
const LanguagePython Language = `python`
const LanguageScala Language = `scala`
const LanguageSql Language = `sql`

type ResultType

type ResultType string
const ResultTypeError ResultType = `error`
const ResultTypeImage ResultType = `image`
const ResultTypeImages ResultType = `images`
const ResultTypeTable ResultType = `table`
const ResultTypeText ResultType = `text`

type Results

type Results struct {
	// The cause of the error
	Cause string `json:"cause,omitempty"`

	Data any `json:"data,omitempty"`
	// The image filename
	FileName string `json:"fileName,omitempty"`

	FileNames []string `json:"fileNames,omitempty"`
	// true if a JSON schema is returned instead of a string representation of
	// the Hive type.
	IsJsonSchema bool `json:"isJsonSchema,omitempty"`
	// internal field used by SDK
	Pos int `json:"pos,omitempty"`

	ResultType ResultType `json:"resultType,omitempty"`
	// The table schema
	Schema [][]any `json:"schema,omitempty"`
	// The summary of the error
	Summary string `json:"summary,omitempty"`
	// true if partial results are returned.
	Truncated bool `json:"truncated,omitempty"`
}

func (*Results) Err

func (r *Results) Err() error

Err returns error type

func (*Results) Error

func (r *Results) Error() string

Error returns error in a bit more friendly way

func (*Results) Failed

func (r *Results) Failed() bool

Failed tells if command execution failed

func (*Results) Scan

func (r *Results) Scan(dest ...any) bool

Scan scans for results TODO: change API, also in terraform (databricks_sql_permissions) for now we're adding `pos` field artificially. this must be removed before this repo is public.

func (*Results) Text

func (r *Results) Text() string

Text returns plain text results

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL