Skip to content

Commit

Permalink
Add support for UC Volumes to the databricks fs commands (#1209)
Browse files Browse the repository at this point in the history
## Changes
```
shreyas.goenka@THW32HFW6T cli % databricks fs -h
Commands to do file system operations on DBFS and UC Volumes.

Usage:
  databricks fs [command]

Available Commands:
  cat         Show file content.
  cp          Copy files and directories.
  ls          Lists files.
  mkdir       Make directories.
  rm          Remove files and directories.
```

This PR adds support for UC Volumes to the fs commands. The fs commands
for UC volumes work the same as they currently do for DBFS. This is
ensured by running the same test matrix we across both DBFS and UC
Volumes versions of the fs commands.

## Tests
Support for UC volumes is tested by running the same tests as we did
originally for DBFS commands. The tests require a `main` catalog to
exist in the workspace, which does in our test workspaces environments
which have the `TEST_METASTORE_ID` environment variable set.

For the Files API filer, we do the same by running mostly common tests
to ensure the filers for "local", "wsfs", "dbfs" and "files API" are
consistent.

The tests are also made to all run in parallel to reduce the time taken.
To ensure the separation of the tests, each test creates its own UC
schema (for UC volumes tests) or DBFS directories (for DBFS tests).
  • Loading branch information
shreyas-goenka committed Feb 20, 2024
1 parent d9f34e6 commit 5ba0aaa
Show file tree
Hide file tree
Showing 14 changed files with 1,126 additions and 659 deletions.
4 changes: 2 additions & 2 deletions cmd/fs/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func newCatCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cat FILE_PATH",
Short: "Show file content",
Long: `Show the contents of a file.`,
Short: "Show file content.",
Long: `Show the contents of a file in DBFS or a UC Volume.`,
Args: cobra.ExactArgs(1),
PreRunE: root.MustWorkspaceClient,
}
Expand Down
9 changes: 3 additions & 6 deletions cmd/fs/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func (c *copy) emitFileCopiedEvent(sourcePath, targetPath string) error {
func newCpCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cp SOURCE_PATH TARGET_PATH",
Short: "Copy files and directories to and from DBFS.",
Long: `Copy files to and from DBFS.
Short: "Copy files and directories.",
Long: `Copy files and directories to and from any paths on DBFS, UC Volumes or your local filesystem.
For paths in DBFS it is required that you specify the "dbfs" scheme.
For paths in DBFS and UC Volumes, it is required that you specify the "dbfs" scheme.
For example: dbfs:/foo/bar.
Recursively copying a directory will copy all files inside directory
Expand All @@ -152,9 +152,6 @@ func newCpCommand() *cobra.Command {
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

// TODO: Error if a user uses '\' as path separator on windows when "file"
// scheme is specified (https://github.com/databricks/cli/issues/485)

// Get source filer and source path without scheme
fullSourcePath := args[0]
sourceFiler, sourcePath, err := filerForPath(ctx, fullSourcePath)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func New() *cobra.Command {
cmd := &cobra.Command{
Use: "fs",
Short: "Filesystem related commands",
Long: `Commands to do DBFS operations.`,
Long: `Commands to do file system operations on DBFS and UC Volumes.`,
GroupID: "workspace",
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/fs/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func toJsonDirEntry(f fs.DirEntry, baseDir string, isAbsolute bool) (*jsonDirEnt
func newLsCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ls DIR_PATH",
Short: "Lists files",
Long: `Lists files`,
Short: "Lists files.",
Long: `Lists files in DBFS and UC Volumes.`,
Args: cobra.ExactArgs(1),
PreRunE: root.MustWorkspaceClient,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/fs/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func newMkdirCommand() *cobra.Command {
// Alias `mkdirs` for this command exists for legacy purposes. This command
// is called databricks fs mkdirs in our legacy CLI: https://github.com/databricks/databricks-cli
Aliases: []string{"mkdirs"},
Short: "Make directories",
Long: `Mkdir will create directories along the path to the argument directory.`,
Short: "Make directories.",
Long: `Make directories in DBFS and UC Volumes. Mkdir will create directories along the path to the argument directory.`,
Args: cobra.ExactArgs(1),
PreRunE: root.MustWorkspaceClient,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/fs/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func newRmCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "rm PATH",
Short: "Remove files and directories from dbfs.",
Long: `Remove files and directories from dbfs.`,
Short: "Remove files and directories.",
Long: `Remove files and directories from DBFS and UC Volumes.`,
Args: cobra.ExactArgs(1),
PreRunE: root.MustWorkspaceClient,
}
Expand Down
Loading

0 comments on commit 5ba0aaa

Please sign in to comment.