- From v3.1 onwards, the database supports directly loading data from files on cloud storage using the INSERT command and the FILES function, thereby you do not need to create an external catalog or file external table first. Besides, FILES() can automatically infer the table schema of the files, greatly simplifying the process of data loading.
- The File External Table feature was designed to help with loading data into the database, NOT to perform efficient queries against external systems as a normal operation. A more performant solution would be to load the data into the database.
Limits
- File external tables must be created in databases within the default_catalog. You can run SHOW CATALOGS to query catalogs created in the cluster.
- Only Parquet, ORC, Avro, RCFile, and SequenceFile data files are supported.
- You can only use file external tables to query data in the target data file. Data write operations such as INSERT, DELETE, and DROP are not supported.
Prerequisites
Before you create a file external table, you must configure your cluster so that the database can access the external storage system where the target data file is stored. The configurations required for a file external table are the same as those required for a Hive catalog, except that you do not need to configure a metastore. See Hive catalog - Integration preparations for more information about configurations.Create a database (Optional)
After connecting to your cluster, you can create a file external table in an existing database or create a new database to manage file external tables. To query existing databases in the cluster, run SHOW DATABASES. Then you can runUSE <db_name> to switch to the target database.
The syntax for creating a database is as follows.
Create a file external table
After accessing the target database, you can create a file external table in this database.Syntax
Parameters
FileLayoutParams
A set of parameters for accessing the target data file.StorageCredentialParams (Optional)
A set of parameters about how the database integrates with the target storage system. This parameter set is optional. You need to configureStorageCredentialParams only when the target storage system is AWS S3 or other S3-compatible storage.
For other storage systems, you can ignore StorageCredentialParams.
AWS S3
If you need to access a data file stored in AWS S3, configure the following authentication parameters inStorageCredentialParams.
- If you choose the instance profile-based authentication method, configure
StorageCredentialParamsas follows:
- If you choose the assumed role-based authentication method, configure
StorageCredentialParamsas follows:
- If you choose the IAM user-based authentication method, configure
StorageCredentialParamsas follows:
For information about how to choose an authentication method for accessing AWS S3 and how to configure an access control policy in the AWS IAM Console, see Authentication parameters for accessing AWS S3.
S3-compatible storage
If you need to access an S3-compatible storage system, such as MinIO, configureStorageCredentialParams as follows to ensure a successful integration:
StorageCredentialParams.
Mapping of column types
The following table provides the mapping of column types between the target data file and the file external table.Examples
HDFS
Create a file external table namedt0 to query Parquet data files stored in an HDFS path.
AWS S3
Example 1: Create a file external table and use instance profile to access a single Parquet file in AWS S3.Query a file external table
Syntax:t0 created in Examples - HDFS, run the following command: