-
Notifications
You must be signed in to change notification settings - Fork 154
Add fs cat command for dbfs files #430
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
26 commits
Select commit
Hold shift + click to select a range
b5f5f11
Add fs ls command for dbfs
shreyas-goenka a4879c0
added integration tests
shreyas-goenka 2706beb
lint
shreyas-goenka 6b667b5
added test for ls on flie
shreyas-goenka db953ac
Merge remote-tracking branch 'origin' into fs-ls
shreyas-goenka 492382c
added resolvedbfs path func
shreyas-goenka 3e947bb
Add fs cat command for dbfs files
shreyas-goenka 3dc4770
manually check for dbfs prefix
shreyas-goenka 070cb69
Merge branch 'fs-ls' into fs-cat
shreyas-goenka 19d8387
fin
shreyas-goenka 19a2051
comments
shreyas-goenka 8050dc5
move sort outside
shreyas-goenka fc7fbbe
-
shreyas-goenka b048c86
address comments
shreyas-goenka 265e517
address comments 2
shreyas-goenka 0882609
added preallocation of size
shreyas-goenka 9160a6e
initialize dbfs client at root
shreyas-goenka 2f3ad71
Merge branch 'fs-ls' into fs-cat
shreyas-goenka bd9d980
address comments
shreyas-goenka 8c4c41a
remove unused error
shreyas-goenka bf37dc4
-
shreyas-goenka d561ce1
Merge remote-tracking branch 'origin' into fs-cat
shreyas-goenka 0202679
-
shreyas-goenka 6239a3a
-
shreyas-goenka 588b953
-
shreyas-goenka abfe279
-
shreyas-goenka 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package fs | ||
|
|
||
| import ( | ||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/databricks/cli/libs/filer" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var catCmd = &cobra.Command{ | ||
| Use: "cat FILE_PATH", | ||
| Short: "Show file content", | ||
| Long: `Show the contents of a file.`, | ||
| Args: cobra.ExactArgs(1), | ||
| PreRunE: root.MustWorkspaceClient, | ||
|
|
||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
| w := root.WorkspaceClient(ctx) | ||
|
|
||
| path, err := resolveDbfsPath(args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| f, err := filer.NewDbfsClient(w, "/") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| r, err := f.Read(ctx, path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return cmdio.RenderReader(ctx, r) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| fsCmd.AddCommand(catCmd) | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "context" | ||
| "io/fs" | ||
| "path" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/libs/filer" | ||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestFsCatForDbfs(t *testing.T) { | ||
| t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) | ||
|
|
||
| ctx := context.Background() | ||
| w, err := databricks.NewWorkspaceClient() | ||
| require.NoError(t, err) | ||
|
|
||
| tmpDir := temporaryDbfsDir(t, w) | ||
|
|
||
| f, err := filer.NewDbfsClient(w, tmpDir) | ||
| require.NoError(t, err) | ||
|
|
||
| err = f.Write(ctx, "a/hello.txt", strings.NewReader("abc"), filer.CreateParentDirectories) | ||
| require.NoError(t, err) | ||
|
|
||
| stdout, stderr := RequireSuccessfulRun(t, "fs", "cat", "dbfs:"+path.Join(tmpDir, "a", "hello.txt")) | ||
| assert.Equal(t, "", stderr.String()) | ||
| assert.Equal(t, "abc", stdout.String()) | ||
| } | ||
|
|
||
| func TestFsCatForDbfsOnNonExistentFile(t *testing.T) { | ||
| t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) | ||
|
|
||
| _, _, err := RequireErrorRun(t, "fs", "cat", "dbfs:/non-existent-file") | ||
| assert.ErrorIs(t, err, fs.ErrNotExist) | ||
| } | ||
|
|
||
| func TestFsCatForDbfsInvalidScheme(t *testing.T) { | ||
| t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) | ||
|
|
||
| _, _, err := RequireErrorRun(t, "fs", "cat", "dab:/non-existent-file") | ||
| assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dab:/non-existent-file") | ||
| } | ||
|
|
||
| func TestFsCatDoesNotSupportOutputModeJson(t *testing.T) { | ||
| t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) | ||
|
|
||
| ctx := context.Background() | ||
| w, err := databricks.NewWorkspaceClient() | ||
| require.NoError(t, err) | ||
|
|
||
| tmpDir := temporaryDbfsDir(t, w) | ||
|
|
||
| f, err := filer.NewDbfsClient(w, tmpDir) | ||
| require.NoError(t, err) | ||
|
|
||
| err = f.Write(ctx, "hello.txt", strings.NewReader("abc")) | ||
| require.NoError(t, err) | ||
|
|
||
| _, _, err = RequireErrorRun(t, "fs", "cat", "dbfs:"+path.Join(tmpDir, "hello.txt"), "--output=json") | ||
| assert.ErrorContains(t, err, "json output not supported") | ||
| } | ||
|
|
||
| // TODO: Add test asserting an error when cat is called on an directory. Need this to be | ||
| // fixed in the SDK first (https://github.com/databricks/databricks-sdk-go/issues/414) |
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
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.