全部產品
Search
文件中心

Lindorm:訪問OSS資料

更新時間:Jan 23, 2026

OLAP 資源群組提供了 FILES 函數來直接存取 OSS 中的檔案,以便於進行檔案的匯入與匯出。本文檔介紹了使用 FILES 函數讀寫 OSS 檔案的方法。

函數說明

FILES 函數中提供 OSS 的訪問憑證及相關參數後,FILES 函數就可以當成一張表,作為 INSERT 的目的地或者 SELECT 的資料來源,實現資料的讀取或匯出。

文法:

FILES( path , format, compression, ...)

參數配置說明:

所有參數均為 "key" = "value" 對。

參數

說明

path

OSS 路徑(需以 s3:// 開頭),例如"s3://bucket_name/path/to/dir/"

format

檔案格式,支援 parquetcsv

compression

壓縮演算法,支援uncompressed(無壓縮)、gzipsnappyzstd

single

是否將資料匯出到單個檔案:true(資料存放區在單個資料檔案中)或 false(預設,如果匯出資料量超過 512 MB,資料將儲存在多個檔案中)

aws.s3.access_key

OSS 存取金鑰 AK

aws.s3.secret_key

OSS 存取金鑰 SK

aws.s3.endpoint

OSS 訪問端點,例如"oss-cn-hangzhou-internal.aliyuncs.com"

資料匯出到OSS

SQL樣本如下:

INSERT INTO FILES(
  "path" = "s3://bucket_name/path/to/dir/",
  "format" = "parquet",
  "compression" = "snappy",
  "single" = "true",
  "aws.s3.access_key" = "your_ak",
  "aws.s3.secret_key" = "your_sk",
  "aws.s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com"
) SELECT * FROM sometable;

將查詢的結果寫入到指定的 OSS 目錄中。

查詢OSS資料

範例程式碼如下:

select * from FILES(
  "path" = "s3://bucket_name/path/to/dir/*.parquet",
  "format" = "parquet",
  "aws.s3.access_key" = "your_ak",
  "aws.s3.secret_key" = "your_sk",
  "aws.s3.endpoint" = "oss-cn-hangzhou-internal.aliyuncs.com" 
);
說明
  • path 不可直接寫目錄路徑,需使用 /dir/* 格式來指定目錄下所有檔案,或用 *.parquet 來匹配特定尾碼的檔案。

  • format 為必填參數。

  • 查詢時 compression 可省略,系統自動識別檔案壓縮格式。