workspace

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 10 Imported by: 18

Documentation

Overview

The Workspace API allows you to list, import, export, and delete notebooks and folders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delete

type Delete struct {
	// The absolute path of the notebook or directory.
	Path string `json:"path"`
	// The flag that specifies whether to delete the object recursively. It is
	// `false` by default. Please note this deleting directory is not atomic. If
	// it fails in the middle, some of objects under this directory may be
	// deleted and cannot be undone.
	Recursive bool `json:"recursive,omitempty"`
}

type Export

type Export struct {
	// Flag to enable direct download. If it is `true`, the response will be the
	// exported file itself. Otherwise, the response contains content as base64
	// encoded string.
	DirectDownload bool `json:"-" url:"direct_download,omitempty"`
	// This specifies the format of the exported file. By default, this is
	// `SOURCE`. However it may be one of: `SOURCE`, `HTML`, `JUPYTER`, `DBC`.
	//
	// The value is case sensitive.
	Format ExportFormat `json:"-" url:"format,omitempty"`
	// The absolute path of the notebook or directory. Exporting directory is
	// only support for `DBC` format.
	Path string `json:"-" url:"path"`
}

Export a notebook

type ExportFormat

type ExportFormat string

This specifies the format of the file to be imported. By default, this is `SOURCE`. However it may be one of: `SOURCE`, `HTML`, `JUPYTER`, `DBC`. The value is case sensitive.

const ExportFormatDbc ExportFormat = `DBC`
const ExportFormatHtml ExportFormat = `HTML`
const ExportFormatJupyter ExportFormat = `JUPYTER`
const ExportFormatRMarkdown ExportFormat = `R_MARKDOWN`
const ExportFormatSource ExportFormat = `SOURCE`

type ExportResponse

type ExportResponse struct {
	// The base64-encoded content. If the limit (10MB) is exceeded, exception
	// with error code **MAX_NOTEBOOK_SIZE_EXCEEDED** will be thrown.
	Content string `json:"content,omitempty"`
}

func (*ExportResponse) Bytes

func (r *ExportResponse) Bytes() ([]byte, error)

type GetStatus

type GetStatus struct {
	// The absolute path of the notebook or directory.
	Path string `json:"-" url:"path"`
}

Get status

type Import

type Import struct {
	// The base64-encoded content. This has a limit of 10 MB.
	//
	// If the limit (10MB) is exceeded, exception with error code
	// **MAX_NOTEBOOK_SIZE_EXCEEDED** will be thrown. This parameter might be
	// absent, and instead a posted file will be used.
	Content string `json:"content,omitempty"`
	// This specifies the format of the file to be imported. By default, this is
	// `SOURCE`. However it may be one of: `SOURCE`, `HTML`, `JUPYTER`, `DBC`.
	// The value is case sensitive.
	Format ExportFormat `json:"format,omitempty"`
	// The language of the object. This value is set only if the object type is
	// `NOTEBOOK`.
	Language Language `json:"language,omitempty"`
	// The flag that specifies whether to overwrite existing object. It is
	// `false` by default. For `DBC` format, `overwrite` is not supported since
	// it may contain a directory.
	Overwrite bool `json:"overwrite,omitempty"`
	// The absolute path of the notebook or directory. Importing directory is
	// only support for `DBC` format.
	Path string `json:"path"`
}

func PythonNotebookOverwrite

func PythonNotebookOverwrite(path, content string) Import

PythonNotebookOverwrite crafts Python import notebook request also by trimming the code specified in the second argument

func PythonNotebookOverwriteReader

func PythonNotebookOverwriteReader(path string, r io.Reader) (Import, error)

type Language

type Language string

The language of the object. This value is set only if the object type is `NOTEBOOK`.

const LanguagePython Language = `PYTHON`
const LanguageR Language = `R`
const LanguageScala Language = `SCALA`
const LanguageSql Language = `SQL`

type List

type List struct {
	// <content needed>
	NotebooksModifiedAfter int `json:"-" url:"notebooks_modified_after,omitempty"`
	// The absolute path of the notebook or directory.
	Path string `json:"-" url:"path"`
}

List contents

type ListResponse

type ListResponse struct {
	// List of objects.
	Objects []ObjectInfo `json:"objects,omitempty"`
}

type Mkdirs

type Mkdirs struct {
	// The absolute path of the directory. If the parent directories do not
	// exist, it will also create them. If the directory already exists, this
	// command will do nothing and succeed.
	Path string `json:"path"`
}

type ObjectInfo

type ObjectInfo struct {
	// <content needed>
	CreatedAt int64 `json:"created_at,omitempty"`
	// The language of the object. This value is set only if the object type is
	// `NOTEBOOK`.
	Language Language `json:"language,omitempty"`
	// <content needed>
	ModifiedAt int64 `json:"modified_at,omitempty"`
	// <content needed>
	ObjectId int64 `json:"object_id,omitempty"`
	// The type of the object in workspace.
	ObjectType ObjectType `json:"object_type,omitempty"`
	// The absolute path of the object.
	Path string `json:"path,omitempty"`
	// <content needed>
	Size int64 `json:"size,omitempty"`
}

type ObjectType

type ObjectType string

The type of the object in workspace.

const ObjectTypeDirectory ObjectType = `DIRECTORY`
const ObjectTypeFile ObjectType = `FILE`
const ObjectTypeLibrary ObjectType = `LIBRARY`
const ObjectTypeNotebook ObjectType = `NOTEBOOK`
const ObjectTypeRepo ObjectType = `REPO`

type WorkspaceAPI

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

The Workspace API allows you to list, import, export, and delete notebooks and folders.

A notebook is a web-based interface to a document that contains runnable code, visualizations, and explanatory text.

func NewWorkspace

func NewWorkspace(client *client.DatabricksClient) *WorkspaceAPI

func (*WorkspaceAPI) Delete

func (a *WorkspaceAPI) Delete(ctx context.Context, request Delete) error

Delete a workspace object

Deletes an object or a directory (and optionally recursively deletes all objects in the directory). * If `path` does not exist, this call returns an error `RESOURCE_DOES_NOT_EXIST`. * If `path` is a non-empty directory and `recursive` is set to `false`, this call returns an error `DIRECTORY_NOT_EMPTY`.

Object deletion cannot be undone and deleting a directory recursively is not atomic.

func (*WorkspaceAPI) Export

func (a *WorkspaceAPI) Export(ctx context.Context, request Export) (*ExportResponse, error)

Export a notebook

Exports a notebook or the contents of an entire directory.

If `path` does not exist, this call returns an error `RESOURCE_DOES_NOT_EXIST`.

One can only export a directory in `DBC` format. If the exported data would exceed size limit, this call returns `MAX_NOTEBOOK_SIZE_EXCEEDED`. Currently, this API does not support exporting a library.

func (*WorkspaceAPI) GetByPath

func (a *WorkspaceAPI) GetByPath(ctx context.Context, name string) (*ObjectInfo, error)

GetByPath calls WorkspaceAPI.ObjectInfoPathToObjectIdMap and returns a single ObjectInfo.

Returns an error if there's more than one ObjectInfo with the same .Path.

Note: All ObjectInfo instances are loaded into memory before returning matching by name.

This method is generated by Databricks SDK Code Generator.

func (*WorkspaceAPI) GetStatus

func (a *WorkspaceAPI) GetStatus(ctx context.Context, request GetStatus) (*ObjectInfo, error)

Get status

Gets the status of an object or a directory. If `path` does not exist, this call returns an error `RESOURCE_DOES_NOT_EXIST`.

func (*WorkspaceAPI) GetStatusByPath

func (a *WorkspaceAPI) GetStatusByPath(ctx context.Context, path string) (*ObjectInfo, error)

Get status

Gets the status of an object or a directory. If `path` does not exist, this call returns an error `RESOURCE_DOES_NOT_EXIST`.

func (*WorkspaceAPI) Impl

func (a *WorkspaceAPI) Impl() WorkspaceService

Impl returns low-level Workspace API implementation

func (*WorkspaceAPI) Import

func (a *WorkspaceAPI) Import(ctx context.Context, request Import) error

Import a notebook

Imports a notebook or the contents of an entire directory. If `path` already exists and `overwrite` is set to `false`, this call returns an error `RESOURCE_ALREADY_EXISTS`. One can only use `DBC` format to import a directory.

func (*WorkspaceAPI) ListAll

func (a *WorkspaceAPI) ListAll(ctx context.Context, request List) ([]ObjectInfo, error)

List contents

Lists the contents of a directory, or the object if it is not a directory.If the input path does not exist, this call returns an error `RESOURCE_DOES_NOT_EXIST`.

This method is generated by Databricks SDK Code Generator.

func (*WorkspaceAPI) Mkdirs

func (a *WorkspaceAPI) Mkdirs(ctx context.Context, request Mkdirs) error

Create a directory

Creates the specified directory (and necessary parent directories if they do not exist). If there is an object (not a directory) at any prefix of the input path, this call returns an error `RESOURCE_ALREADY_EXISTS`.

Note that if this operation fails it may have succeeded in creating some of the necessary\nparrent directories.

func (*WorkspaceAPI) MkdirsByPath

func (a *WorkspaceAPI) MkdirsByPath(ctx context.Context, path string) error

Create a directory

Creates the specified directory (and necessary parent directories if they do not exist). If there is an object (not a directory) at any prefix of the input path, this call returns an error `RESOURCE_ALREADY_EXISTS`.

Note that if this operation fails it may have succeeded in creating some of the necessary\nparrent directories.

func (*WorkspaceAPI) ObjectInfoPathToObjectIdMap

func (a *WorkspaceAPI) ObjectInfoPathToObjectIdMap(ctx context.Context, request List) (map[string]int64, error)

ObjectInfoPathToObjectIdMap calls WorkspaceAPI.ListAll and creates a map of results with ObjectInfo.Path as key and ObjectInfo.ObjectId as value.

Returns an error if there's more than one ObjectInfo with the same .Path.

Note: All ObjectInfo instances are loaded into memory before creating a map.

This method is generated by Databricks SDK Code Generator.

func (*WorkspaceAPI) RecursiveList

func (a *WorkspaceAPI) RecursiveList(ctx context.Context, path string) ([]ObjectInfo, error)

RecursiveList traverses the workspace tree and returns all non-directory objects under the path

func (*WorkspaceAPI) WithImpl

func (a *WorkspaceAPI) WithImpl(impl WorkspaceService) *WorkspaceAPI

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

type WorkspaceService

type WorkspaceService interface {

	// Delete a workspace object
	//
	// Deletes an object or a directory (and optionally recursively deletes all
	// objects in the directory). * If `path` does not exist, this call returns
	// an error `RESOURCE_DOES_NOT_EXIST`. * If `path` is a non-empty directory
	// and `recursive` is set to `false`, this call returns an error
	// `DIRECTORY_NOT_EMPTY`.
	//
	// Object deletion cannot be undone and deleting a directory recursively is
	// not atomic.
	Delete(ctx context.Context, request Delete) error

	// Export a notebook
	//
	// Exports a notebook or the contents of an entire directory.
	//
	// If `path` does not exist, this call returns an error
	// `RESOURCE_DOES_NOT_EXIST`.
	//
	// One can only export a directory in `DBC` format. If the exported data
	// would exceed size limit, this call returns `MAX_NOTEBOOK_SIZE_EXCEEDED`.
	// Currently, this API does not support exporting a library.
	Export(ctx context.Context, request Export) (*ExportResponse, error)

	// Get status
	//
	// Gets the status of an object or a directory. If `path` does not exist,
	// this call returns an error `RESOURCE_DOES_NOT_EXIST`.
	GetStatus(ctx context.Context, request GetStatus) (*ObjectInfo, error)

	// Import a notebook
	//
	// Imports a notebook or the contents of an entire directory. If `path`
	// already exists and `overwrite` is set to `false`, this call returns an
	// error `RESOURCE_ALREADY_EXISTS`. One can only use `DBC` format to import
	// a directory.
	Import(ctx context.Context, request Import) error

	// List contents
	//
	// Lists the contents of a directory, or the object if it is not a
	// directory.If the input path does not exist, this call returns an error
	// `RESOURCE_DOES_NOT_EXIST`.
	//
	// Use ListAll() to get all ObjectInfo instances
	List(ctx context.Context, request List) (*ListResponse, error)

	// Create a directory
	//
	// Creates the specified directory (and necessary parent directories if they
	// do not exist). If there is an object (not a directory) at any prefix of
	// the input path, this call returns an error `RESOURCE_ALREADY_EXISTS`.
	//
	// Note that if this operation fails it may have succeeded in creating some
	// of the necessary\nparrent directories.
	Mkdirs(ctx context.Context, request Mkdirs) error
}

The Workspace API allows you to list, import, export, and delete notebooks and folders.

A notebook is a web-based interface to a document that contains runnable code, visualizations, and explanatory text.

Jump to

Keyboard shortcuts

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