Skip to main content

CREATE FILE

You can execute the CREATE FILE statement to create a file. After a file is created, the file is uploaded and persisted in StarRocks. In a database, only an admin user can create and delete files, and all users who have permission to access the database can use the files that belong to the database.

tip

This operation requires the SYSTEM-level FILE privilege. You can follow the instructions in GRANT to grant this privilege.

Basic concepts

File: refers to the file that is created and saved in StarRocks. After a file is created and stored in StarRocks, StarRocks assigns a unique ID to the file. You can find a file based on the database name, catalog, and file name.

Syntax

CREATE FILE "file_name" [IN database]
[properties]

Parameters

ParameterRequiredDescription
file_nameYesThe name of the file.
databaseNoThe database to which the file belongs. If you do not specify this parameter, this parameter defaults to the name of the database that you access in the current session.
propertiesYesThe properties of the file. The following table describes the configuration items of properties.

Configuration items of properties

Configuration itemRequiredDescription
urlYesThe URL from which you can download the file. Only an unauthenticated HTTP URL is supported. After the file is stored in StarRocks, the URL is no longer needed.
catalogYesThe category to which the file belongs. You can specify a catalog based on your business requirements. However, in some situations, you must set this parameter to a specific catalog. For example, if you load data from Kafka, StarRocks searches for files in the catalog from the Kafka data source.
MD5NoThe message-digest algorithm that is used to check a file. If you specify this parameter, StarRocks checks the file after the file is downloaded.

Examples

  • Create a file named test.pem under the category named kafka.
CREATE FILE "test.pem"
PROPERTIES
(
"url" = "https://starrocks-public.oss-cn-xxxx.aliyuncs.com/key/test.pem",
"catalog" = "kafka"
);
  • Create a file named client.key under the category named my_catalog.
CREATE FILE "client.key"
IN my_database
PROPERTIES
(
"url" = "http://test.bj.bcebos.com/kafka-key/client.key",
"catalog" = "my_catalog",
"md5" = "b5bb901bf10f99205b39a46ac3557dd9"
);