Create two foreign tables and use them to export tables from a database to two buckets in OBS.
OBS and the database are in the same region. The example GaussDB(DWS) table to be exported is tpcds.customer_address.
Export information is set as follows:
Information about data formats is set based on the detailed data format parameters specified during data export from a database. The parameter settings are as follows:
access_key and secret_access_key have been obtained during user creation. Replace the italic part with the actual keys.
Based on the preceding settings, the foreign table is created using the following statements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | CREATE FOREIGN TABLE tpcds.customer_address_ext1 ( ca_address_sk integer , ca_address_id char(16) , ca_street_number char(10) , ca_street_name varchar(60) , ca_street_type char(15) , ca_suite_number char(10) , ca_city varchar(60) , ca_county varchar(30) , ca_state char(2) , ca_zip char(10) , ca_country varchar(20) , ca_gmt_offset decimal(5,2) , ca_location_type char(20) ) SERVER gsmpp_server OPTIONS(LOCATION 'obs://input-data1/data/', FORMAT 'CSV', ENCODING 'utf8', DELIMITER E'\x08', ENCRYPT 'off', ACCESS_KEY 'access_key_value_to_be_replaced', SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced' )Write Only; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | CREATE FOREIGN TABLE tpcds.customer_address_ext2 ( ca_address_sk integer , ca_address_id char(16) , ca_street_number char(10) , ca_street_name varchar(60) , ca_street_type char(15) , ca_suite_number char(10) , ca_city varchar(60) , ca_county varchar(30) , ca_state char(2) , ca_zip char(10) , ca_country varchar(20) , ca_gmt_offset decimal(5,2) , ca_location_type char(20) ) SERVER gsmpp_server OPTIONS(LOCATION 'obs://input-data2/data/', FORMAT 'CSV', ENCODING 'utf8', DELIMITER E'\x08', ENCRYPT 'off', ACCESS_KEY 'access_key_value_to_be_replaced', SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced' )Write Only; |
1 | INSERT INTO tpcds.customer_address_ext1 SELECT * FROM tpcds.customer_address; |
1 | INSERT INTO tpcds.customer_address_ext2 SELECT * FROM tpcds.customer_address; |
The design of OBS foreign tables does not allow exporting files to a non-empty path. However, in concurrent export scenarios, multiple files are exported to the same path, causing an error.
Assume that a user concurrently exports data from the same table to the same OBS foreign table, and that one SQL statement is executed to export data when another SQL statement is being executed and has not generated any file on the OBS server. In this case, certain data is overwritten although both SQL statements are successfully executed. Therefore, you are advised not to concurrently export data to the same OBS foreign table.
Use the two foreign tables to export tables from the database to two buckets in OBS.
OBS and the database are in the same region. Tables to be exported are tpcds.customer_address and tpcds.customer_demographics.
Information about data formats is set based on the detailed data format parameters specified during data export from GaussDB(DWS). The parameter settings are as follows:
access_key and secret_access_key have been obtained during user creation. Replace the italic part with the actual keys.
Based on the preceding settings, the foreign table is created using the following statements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | CREATE FOREIGN TABLE tpcds.customer_address_ext1 ( ca_address_sk integer , ca_address_id char(16) , ca_street_number char(10) , ca_street_name varchar(60) , ca_street_type char(15) , ca_suite_number char(10) , ca_city varchar(60) , ca_county varchar(30) , ca_state char(2) , ca_zip char(10) , ca_country varchar(20) , ca_gmt_offset decimal(5,2) , ca_location_type char(20) ) SERVER gsmpp_server OPTIONS(LOCATION 'obs://input-data1/data/', FORMAT 'CSV', ENCODING 'utf8', DELIMITER E'\x08', ENCRYPT 'off', ACCESS_KEY 'access_key_value_to_be_replaced', SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced' )Write Only; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | CREATE FOREIGN TABLE tpcds.customer_address_ext2 ( ca_address_sk integer , ca_address_id char(16) , ca_address_name varchar(20) , ca_address_code integer , ca_street_number char(10) , ca_street_name varchar(60) , ca_street_type char(15) , ca_suite_number char(10) , ca_city varchar(60) , ca_county varchar(30) , ca_state char(2) , ca_zip char(10) , ca_country varchar(20) , ca_gmt_offset decimal(5,2) ) SERVER gsmpp_server OPTIONS(LOCATION 'obs://input_data2/data/', FORMAT 'CSV', ENCODING 'utf8', DELIMITER E'\x08', QUOTE E'\x1b', ENCRYPT 'off', ACCESS_KEY 'access_key_value_to_be_replaced', SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced' )Write Only; |
1 | INSERT INTO tpcds.customer_address_ext1 SELECT * FROM tpcds.customer_address; |
1 | INSERT INTO tpcds.customer_address_ext2 SELECT * FROM tpcds.warehouse; |