External data source examples
To create parquet external table, you must first create an external data source by using the CREATE EXTERNAL DATASOURCE command. You can also use the ALTER, SHOW, DROP, and other commands to work with external data sources.
Note: Parquet external tables are read-only. The INSERT, DROP,
TRUNCATE, and other commands do not work with external data sources.
- To create an external data source on AWS S3, run the following.
-
CREATE EXTERNAL DATASOURCE my_datasource ON AWSS3 USING ( ACCESSKEYID "AKIAIOSFODNN7EXAMPLE" SECRETACCESSKEY "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" BUCKET "example_aws_bucket" REGION "us-east-1" );Note: AWS S3 supports only the following authentication method:- access key id with secret access key.
- To create data source on other S3-compatible provider, ENDPOINT option must be added.
-
CREATE EXTERNAL DATASOURCE my_datasource ON AWSS3 USING ( ACCESSKEYID "347aa3a4b34344f8bc7c7cccdf85ecaabfe" SECRETACCESSKEY "gvurfb82712ad14W7a7915h763a6examplekey" BUCKET "example_ibm_cloud_bucket" REGION "us-south" ENDPOINT "s3.us-south.cloud-object-storage.appdomain.cloud" );
- Similarly, you can create external data source on Azure. Azure supports the following authentication methods:
- Account key
authentication:
CREATE EXTERNAL DATASOURCE my_datasource ON AZUREBLOB USING ( CONTAINER "example_container" ACCOUNT "example_account" ACCOUNTKEY "abcdefghijklmnopqrstuvwxyz0123456789/+ABCDEabcdefghijklmnopqrstuvwxyz0123456789/+ABCDE==" );Note: The source is called AZUREBLOB, but it supports both BLOB and ADLSv2. - Alternatively, you can create data source without credentials, if bucket or container allows anonymous connections.
- For S3:
CREATE EXTERNAL DATASOURCE my_datasource ON AWSS3 USING ( BUCKET "example_aws_bucket" REGION "us-east-1" ); - To alter the external datasource to modify columns, run the following.
-
ALTER EXTERNAL DATASOURCE my_datasource ON AWSS3 USING ( BUCKET "other_bucket" ); - To show the external data source column values, run the following.
-
SHOW EXTERNAL DATASOURCE my_datasource; - To show the external data source in a cloud connection string format, run the following.
-
SHOW EXTERNAL DATASOURCE my_datasource VERBOSE; - To drop an external data source, run the following.
-
DROP EXTERNAL DATASOURCE my_datasource;Note: To DROP data source, you must first drop all the external tables that are using this data source.