Help Center > > Developer Guide> Data Export> Exporting Data to OBS in Parallel> Creating an OBS Foreign Table

Creating an OBS Foreign Table

Updated at:Oct 29, 2020 GMT+08:00

Procedure

  1. Based on the path planned in Planning Data Export, determine the value of the location parameter used for creating a foreign table.
  2. Obtain access keys (AK and SK) for accessing OBS. To obtain access keys, log in to the management console, move the cursor over the username in the upper right corner, and click My Credentials. Then choose Access Keys in the navigation tree on the left. On the Access Keys page, you can view the existing AKs or click Create Access Key to create an AK/SK pair.
  3. Examine the formats of data to be exported and determine the values of data format parameters used for creating a foreign table. For details, see data format parameters.
  4. Create an OBS table based on the parameter settings in the preceding steps. For details about how to create a foreign table, see CREATE FOREIGN TABLE (for GDS Import and Export).

Examples

Create a foreign table in the GaussDB(DWS) database. Set parameters as follows:

  • location

    The OBS path of the source data file has been obtained in step 2 in Planning Data Export.

    For example, set location as follows:

    location 'obs://mybucket/output_data/',
  • Access keys (AK and SK)
    • Set access_key to the AK you have obtained.
    • Set secret_access_key to the SK you have obtained.

    access_key and secret_access_key have been obtained during user creation. Replace the italic part with the actual keys.

  • Data format parameters
    • Set format to CSV.
    • Set encoding to UTF-8.
    • Set encrypt to off.
    • Set delimiter to ,.
    • Set header (whether the exported data file contains the header row).

      Specifies whether a file contains a header with the names of each column in the file.

      When exporting data from OBS, this parameter cannot be set to true. Use the default value false, indicating that the first row of the exported data file is not the header.

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
26
DROP FOREIGN TABLE IF EXISTS product_info_output_ext;
CREATE FOREIGN TABLE product_info_output_ext
(
    product_price                integer        not null,
    product_id                   char(30)       not null,
    product_time                 date           ,
    product_level                char(10)       ,
    product_name                 varchar(200)   ,
    product_type1                varchar(20)    ,
    product_type2                char(10)       ,
    product_monthly_sales_cnt    integer        ,
    product_comment_time         date           ,
    product_comment_num          integer        ,
    product_comment_content      varchar(200)                   
) 
SERVER gsmpp_server 
OPTIONS(
location 'obs://mybucket/output_data/',
FORMAT 'CSV' ,
DELIMITER ',',
encoding 'utf8',
header 'false',
ACCESS_KEY 'access_key_value_to_be_replaced',
SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced'
)
WRITE ONLY ;

If the following information is displayed, the foreign table has been created:

CREATE FOREIGN TABLE

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel