跳到主要内容

Staging Files

Databend recommends two file upload methods for stages: PRESIGN and PUT/GET commands. These methods enable direct data transfer between the client and your storage, eliminating intermediaries and resulting in cost savings by reducing traffic between Databend and your storage.

Alt text

The PRESIGN method generates a time-limited URL with a signature, which clients can use to securely initiate file uploads. This URL grants temporary access to the designated stage, allowing clients to directly transfer data without relying on Databend servers for the entire process, enhancing both security and efficiency.

If you're using BendSQL to manage files in a stage, you can use the PUT command for uploading files and the GET command for downloading files.

  • The GET command currently can only download all files in a stage, not individual ones.
  • These commands are exclusive to BendSQL and the GET command will not function when Databend uses the file system as the storage backend.

Examples

Uploading with Presigned URL

The following examples demonstrate how to upload a sample file (books.parquet) to the user stage, an internal stage, and an external stage with presigned URLs.

PRESIGN UPLOAD @~/books.parquet;

Result:

┌────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Name │ Value │
├────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ method │ PUT │
│ headers│ {"host":"s3.us-east-2.amazonaws.com"} │
│ url │ https://s3.us-east-2.amazonaws.com/databend-toronto/stage/user/root/books.parquet?X-Amz-Algorithm... │
└────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
curl -X PUT -T books.parquet "https://s3.us-east-2.amazonaws.com/databend-toronto/stage/user/root/books.parquet?X-Amz-Algorithm=... ...

Check the staged file:

LIST @~;

Result:

┌───────────────┬──────┬──────────────────────────────────────┬─────────────────────────────────┬─────────┐
│ name │ size │ md5 │ last_modified │ creator │
├───────────────┼──────┼──────────────────────────────────────┼─────────────────────────────────┼─────────┤
│ books.parquet │ 998 │ 88432bf90aadb79073682988b39d461c │ 2023-06-27 16:03:51.000 +0000 │ │
└───────────────┴──────┴──────────────────────────────────────┴─────────────────────────────────┴─────────┘

Uploading with PUT Command

The following examples demonstrate how to use BendSQL to upload a sample file (books.parquet) to the user stage, an internal stage, and an external stage with the PUT command.

PUT fs:///Users/eric/Documents/books.parquet @~

Result:

┌───────────────────────────────────────────────┐
│ file │ status │
├─────────────────────────────────────┼─────────┤
│ /Users/eric/Documents/books.parquet │ SUCCESS │
└───────────────────────────────────────────────┘

Check the staged file:

LIST @~;

Result:

┌────────────────────────────────────────────────────────────────────────┐
│ name │ size │ ··· │ last_modified │ creator │
├───────────────┼────────┼─────┼──────────────────────┼──────────────────┤
│ books.parquet │ 998 │ ... │ 2023-09-04 03:27:... │ NULL │
└────────────────────────────────────────────────────────────────────────┘

Downloading with GET Command

The following examples demonstrate how to use BendSQL to download a sample file (books.parquet) from the user stage, an internal stage, and an external stage with the GET command.

LIST @~;

Result:

┌────────────────────────────────────────────────────────────────────────┐
│ name │ size │ ··· │ last_modified │ creator │
├───────────────┼────────┼─────┼──────────────────────┼──────────────────┤
│ books.parquet │ 998 │ ... │ 2023-09-04 03:27:... │ NULL │
└────────────────────────────────────────────────────────────────────────┘
GET @~/ fs:///Users/eric/Downloads/fromStage/;

Result:

┌─────────────────────────────────────────────────────────┐
│ file │ status │
├───────────────────────────────────────────────┼─────────┤
│ /Users/eric/Downloads/fromStage/books.parquet │ SUCCESS │
└─────────────────────────────────────────────────────────┘
这篇文章对您有帮助吗?
Yes
No
开始使用 Databend Cloud
低成本
快速分析
多种数据源
弹性扩展
注册