-
Notifications
You must be signed in to change notification settings - Fork 72
DBFS file handle that supports both reading and writing #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
effffb6
DBFS file handle that supports both reading and writing
pietern c117ef1
Address comments
pietern dc6cff9
First round of comments
pietern 69c3f10
Prefix with "dbfs open"
pietern 918566d
Docs
pietern 8a4a8f7
Fix test to match new error message
pietern 27fda6b
Update README.md
pietern f540b15
Update README.md
pietern 53ee739
Update README.md
pietern 175a758
Doc fixes
pietern 816e23c
Split out ReadFile and WriteFile to separate test
pietern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,49 @@ | ||
| // Databricks FileSystem (DBFS) API | ||
| // Databricks File System (DBFS) API | ||
| // | ||
| // We strongly recommend using clients created via | ||
| // [github.com/databricks/databricks-sdk-go/workspaces.New] to simplify | ||
| // configuration experience. | ||
| // We recommend using a client created via [databricks.NewWorkspaceClient] | ||
| // to simplify the configuration experience. | ||
| // | ||
| // Please use the high-level [DbfsAPI.Open] and [DbfsAPI.Overwrite] methods | ||
| // to work with remote files through Go's [io] interfaces. The return value | ||
| // of [DbfsAPI.Open] implements the [io.Reader] and [io.WriterTo] interfaces. | ||
| // The [io.WriterTo] interface is used by [io.Copy] and maximizes throughput by | ||
| // reading data with the DBFS maximum read chunk size of 1MB. | ||
| // # Reading and writing files | ||
| // | ||
| // Internally, these methods wrap the low level [DbfsAPI.Create], | ||
| // [DbfsAPI.Close], [DbfsAPI.Read], and [DbfsAPI.AddBlock] methods: | ||
| // You can open a file on DBFS for reading or writing with [DbfsAPI.Open]. | ||
| // This function returns a [Handle] that is compatible with a subset of [io] | ||
| // interfaces for reading, writing, and closing. | ||
| // | ||
| // Uploading a file from an [io.Reader]: | ||
| // | ||
| // upload, _ := os.Open("/path/to/local/file.ext") | ||
| // _ = w.Dbfs.Overwrite(ctx, "/path/to/remote/file", upload) | ||
| // remote, _ := w.Dbfs.Open(ctx, "/path/to/remote/file", dbfs.FileModeWrite|dbfs.FileModeOverwrite) | ||
| // io.Copy(remote, upload) | ||
| // remote.Close() | ||
| // | ||
| // Downloading a file to an [io.Writer]: | ||
| // | ||
| // download, _ := os.Create("/path/to/local") | ||
| // remote, _ := w.Dbfs.Open(ctx, "/path/to/remote") | ||
| // remote, _ := w.Dbfs.Open(ctx, "/path/to/remote/file", dbfs.FileModeRead) | ||
| // _ = io.Copy(download, remote) | ||
| // | ||
| // Moving files: | ||
| // # Reading and writing files from buffers | ||
| // | ||
| // You can read from or write to a DBFS file directly from a byte slice through | ||
| // the convenience functions [DbfsAPI.ReadFile] and [DbfsAPI.WriteFile]. | ||
| // | ||
| // Uploading a file from a byte slice: | ||
| // | ||
| // buf := []byte("Hello world!") | ||
| // _ = w.Dbfs.WriteFile(ctx, "/path/to/remote/file", buf) | ||
| // | ||
| // Downloading a file into a byte slice: | ||
| // | ||
| // buf, err := w.Dbfs.ReadFile(ctx, "/path/to/remote/file") | ||
| // | ||
| // # Moving files | ||
| // | ||
| // err := w.Dbfs.Move(ctx, dbfs.Move{ | ||
| // SourcePath: "/remote/src/path", | ||
| // DestinationPath: "/remote/dst/path", | ||
| // }) | ||
| // | ||
| // Creating directories: | ||
| // # Creating directories | ||
| // | ||
| // w.Dbfs.MkdirsByPath(ctx, "/remote/dir/path") | ||
| package dbfs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.