Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
### CLI
* Skip non-exportable objects (e.g., `MLFLOW_EXPERIMENT`) during `workspace export-dir` instead of failing ([#4081](https://github.com/databricks/cli/issues/4081))

* Improve performance of `databricks fs cp` command by parallelizing file uploads when
copying directories with the `--recursive` flag.

### Bundles

### Dependency updates
Expand Down
5 changes: 5 additions & 0 deletions acceptance/cmd/fs/cp/dir-to-dir/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions acceptance/cmd/fs/cp/dir-to-dir/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localdir/file1.txt -> dbfs:/Volumes/main/default/data/uploaded-dir/file1.txt
localdir/file2.txt -> dbfs:/Volumes/main/default/data/uploaded-dir/file2.txt
6 changes: 6 additions & 0 deletions acceptance/cmd/fs/cp/dir-to-dir/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir -p localdir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating these files at test runtime, you can create and commit them here. That way, the test can directly read them without having to write them first.

I recommend commiting input files directly unless the file contents are dynamic.

echo -n "file1 content" > localdir/file1.txt
echo -n "file2 content" > localdir/file2.txt

# Recursive directory copy (output sorted for deterministic ordering).
$CLI fs cp -r localdir dbfs:/Volumes/main/default/data/uploaded-dir 2>&1 | sort
20 changes: 20 additions & 0 deletions acceptance/cmd/fs/cp/dir-to-dir/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Local = true
Cloud = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend setting Cloud = true for this test as well. That validates the implementation against a real server. You can use fs cat to confirm that the files were uploaded.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also nice to ensure that the local test server implementation matches the remote behaviour, atleast for the interfaces we own (like the fs commands)

Ignore = ["localdir"]

# Recursive copy: localdir/ -> uploaded-dir/.
[[Server]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a local sserver supporing these operations (see: libs/testserver/handlers.go). This should work even without the overrides:

	server.Handle("HEAD", "/api/2.0/fs/directories/{path:.*}", func(req Request) any {
		return Response{
			Body: "dir path: " + req.Vars["dir_path"],
		}
	})

	server.Handle("PUT", "/api/2.0/fs/files/{path:.*}", func(req Request) any {
		path := req.Vars["path"]
		overwrite := req.URL.Query().Get("overwrite") == "true"
		return req.Workspace.WorkspaceFilesImportFile(path, req.Body, overwrite)
	})

Pattern = "PUT /api/2.0/fs/directories/Volumes/main/default/data/uploaded-dir"
Response.StatusCode = 200

[[Server]]
Pattern = "HEAD /api/2.0/fs/directories/Volumes/main/default/data/uploaded-dir"
Response.StatusCode = 200

[[Server]]
Pattern = "PUT /api/2.0/fs/files/Volumes/main/default/data/uploaded-dir/file1.txt"
Response.StatusCode = 200

[[Server]]
Pattern = "PUT /api/2.0/fs/files/Volumes/main/default/data/uploaded-dir/file2.txt"
Response.StatusCode = 200
5 changes: 5 additions & 0 deletions acceptance/cmd/fs/cp/file-to-dir/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions acceptance/cmd/fs/cp/file-to-dir/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

>>> [CLI] fs cp local.txt dbfs:/Volumes/main/default/data/mydir/
local.txt -> dbfs:/Volumes/main/default/data/mydir/local.txt
4 changes: 4 additions & 0 deletions acceptance/cmd/fs/cp/file-to-dir/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo -n "hello world!" > local.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, local.txt can be commited.


# Copy file into a directory (trailing slash indicates directory target).
trace $CLI fs cp local.txt dbfs:/Volumes/main/default/data/mydir/
12 changes: 12 additions & 0 deletions acceptance/cmd/fs/cp/file-to-dir/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Local = true
Cloud = false
Ignore = ["local.txt"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you commit local.txt, you can remove this config. Same for the test above.


# Copy file into existing directory: local.txt -> mydir/local.txt.
[[Server]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as earlier, we should not need these overrides.

Pattern = "HEAD /api/2.0/fs/directories/Volumes/main/default/data/mydir"
Response.StatusCode = 200

[[Server]]
Pattern = "PUT /api/2.0/fs/files/Volumes/main/default/data/mydir/local.txt"
Response.StatusCode = 200
5 changes: 5 additions & 0 deletions acceptance/cmd/fs/cp/file-to-file/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions acceptance/cmd/fs/cp/file-to-file/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

>>> [CLI] fs cp local.txt dbfs:/Volumes/main/default/data/uploaded.txt
local.txt -> dbfs:/Volumes/main/default/data/uploaded.txt

>>> [CLI] fs cp dbfs:/Volumes/main/default/data/remote.txt downloaded.txt
dbfs:/Volumes/main/default/data/remote.txt -> downloaded.txt
content from volume
9 changes: 9 additions & 0 deletions acceptance/cmd/fs/cp/file-to-file/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
echo -n "hello world!" > local.txt

# Upload local file to volume.
trace $CLI fs cp local.txt dbfs:/Volumes/main/default/data/uploaded.txt

# Download file from volume to local.
trace $CLI fs cp dbfs:/Volumes/main/default/data/remote.txt downloaded.txt

cat downloaded.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional)

Suggested change
cat downloaded.txt
trace cat downloaded.txt
rm download.txt

By removing it here, you do not need to Ignore it in test.toml.

34 changes: 34 additions & 0 deletions acceptance/cmd/fs/cp/file-to-file/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Local = true
Cloud = false
Ignore = ["local.txt", "downloaded.txt"]

# Upload: local.txt -> dbfs:/Volumes/.../uploaded.txt.
[[Server]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, remove overrides.

Pattern = "HEAD /api/2.0/fs/directories/Volumes/main/default/data/uploaded.txt"
Response.StatusCode = 404

[[Server]]
Pattern = "HEAD /api/2.0/fs/files/Volumes/main/default/data/uploaded.txt"
Response.StatusCode = 404

[[Server]]
Pattern = "HEAD /api/2.0/fs/directories/Volumes/main/default/data"
Response.StatusCode = 200

[[Server]]
Pattern = "PUT /api/2.0/fs/files/Volumes/main/default/data/uploaded.txt"
Response.StatusCode = 200

# Download: dbfs:/Volumes/.../remote.txt -> downloaded.txt.
[[Server]]
Pattern = "HEAD /api/2.0/fs/directories/Volumes/main/default/data/remote.txt"
Response.StatusCode = 404

[[Server]]
Pattern = "HEAD /api/2.0/fs/files/Volumes/main/default/data/remote.txt"
Response.StatusCode = 200

[[Server]]
Pattern = "GET /api/2.0/fs/files/Volumes/main/default/data/remote.txt"
Response.StatusCode = 200
Response.Body = "content from volume"
5 changes: 5 additions & 0 deletions acceptance/cmd/fs/cp/input-validation/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions acceptance/cmd/fs/cp/input-validation/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

>>> errcode [CLI] fs cp src dst --concurrency -1
Error: --concurrency must be at least 1

Exit code: 1

>>> errcode [CLI] fs cp src dst --concurrency 0
Error: --concurrency must be at least 1

Exit code: 1
3 changes: 3 additions & 0 deletions acceptance/cmd/fs/cp/input-validation/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Invalid concurrency values should fail.
trace errcode $CLI fs cp src dst --concurrency -1
trace errcode $CLI fs cp src dst --concurrency 0
2 changes: 2 additions & 0 deletions acceptance/cmd/fs/cp/input-validation/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Local = true
Cloud = false
Loading