• Data Warehouse Service

  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. Data Export
  5. Exporting Data to OBS in Parallel
  6. Creating an OBS Foreign Table

Creating an OBS Foreign Table


  1. Based on the path planned in Planning Data Export, determine the value of the location parameter used for creating a foreign table.
  2. Set the access keys (AK and SK). To obtain access keys, log in to the management console, click the username in the upper right corner, choose My Credential from the drop-down list, and click Access Keys. Then, you can view existing access keys or click Add Access Key to create one.
  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 parameters specified above. For details about how to create a foreign table, see CREATE FOREIGN TABLE (for OBS Import and Export).


Create a foreign table in the 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 on.
    • Set delimiter to ,.
    • Set header (whether the exported data file contains the header row).

      Use the default value false, indicating that the first row of the exported data file is not the header. This parameter is valid only when the file format is CSV.

Based on the above settings, the foreign tables are created using the following statements:

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 
location 'obs://mybucket/output_data/',
encoding 'utf8',
header 'false',
ACCESS_KEY 'access_key_value_to_be_replaced',
SECRET_ACCESS_KEY 'secret_access_key_value_to_be_replaced'

If the following information is displayed, the foreign tables have been created: