• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. Data Export
  5. Using GDS to Export Data to a Remote Server
  6. Examples

Examples

Example: Exporting Data in Remote Mode

A data server resides on the same intranet as the cluster, the IP address of the data server is 192.168.0.90, and data files are in CSV format. In this scenario, data is concurrently exported in Remote mode.

To concurrently export data in Remote mode, perform the following operations:

  1. Log in to the GDS data server as user root, create the /output_data directory for storing data files, and create user gds_user and its user group.
    mkdir -p /output_data
  2. (Optional) Create a user and the user group it belongs to. The user is used to start GDS. If the user and user group already exist, skip this step.
    groupadd gdsgrp
    useradd -g gdsgrp gds_user
  3. Change the owner of the /output_data directory on the data server to gds_user.
    chown -R gds_user:gdsgrp /output_data 
  4. Log in to the data server as user gds_user and start GDS.
    The GDS installation path is /opt/bin/gds. The directory for storing data files is /output_data/. The IP address of the data server is 192.168.0.90. The GDS listening port is 5000. GDS runs in daemon mode.
    /opt/bin/gds/gds -d /output_data -p 192.168.0.90:5000 -H 10.10.0.1/24 -D
  5. In the database, create the foreign table foreign_tpcds_reasons for receiving data from the data server.

    Data export mode settings are as follows:

    • The directory for storing exported files is /output_data/ and the GDS monitoring port number is 5000 while GDS is started. The export directory created above is also /output_data/. Therefore, the location parameter is set to gsfs://192.168.0.90:5000/.

    Data format parameter settings are as follows:

    • format is set to CSV.
    • encoding is set to UTF-8.
    • delimiter is set to E'\x08'.
    • quote is set to 0x1b.
    • null is set to an empty string without quotation marks.
    • escape is set to a double quotation mark.
    • header is set to false, indicating that the first row is identified as a data row in an exported file.

    Based on the above settings, the foreign table is created using the following statement:

    CREATE FOREIGN TABLE foreign_tpcds_reasons
    (
      r_reason_sk    integer        not null,
      r_reason_id    char(16)       not null,
      r_reason_desc  char(100)
    ) SERVER gsmpp_server OPTIONS (LOCATION 'gsfs://192.168.0.90:5000/', FORMAT 'CSV',ENCODING 'utf8',DELIMITER E'\x08', QUOTE E'\x1b', NULL '') WRITE ONLY;
  6. In the database, export data to data files through the foreign table foreign_tpcds_reasons.
    INSERT INTO foreign_tpcds_reasons SELECT * FROM reasons;
  7. After data export is complete, log in to the data server as user gds_user and stop GDS.
    The GDS process ID is 128954.
    ps -ef|grep gds
    gds_user 128954      1  0 15:03 ?        00:00:00 gds -d /output_data -p 192.168.0.90:5000 -D
    gds_user 129003 118723  0 15:04 pts/0    00:00:00 grep gds
    kill -9 128954

Example: Exporting Data Using Multiple Threads

A data server resides on the same intranet as the cluster, the IP address of the data server is 192.168.0.90, and source data files are in CSV format. In this scenario, data is concurrently exported from two tables using multiple threads in Remote mode.

To concurrently export data using multiple threads in Remote mode, perform the following operations:

  1. Log in to the GDS data server as user root, create the /output_data directory for storing data files, and create the database user and its user group.
    mkdir -p /output_data
    groupadd gdsgrp
    useradd -g gdsgrp gds_user
  2. Change the owner of the /output_data directory on the data server to gds_user.
    chown -R gds_user:gdsgrp /output_data 
  3. Log in to the data server as user gds_user and start GDS.
    The GDS installation path is /opt/bin/gds. The directory for storing data files is /output_data/. The IP address of the data server is 192.168.0.90. The GDS listening port is 5000. GDS runs in daemon mode. The degree of parallelism is 2.
    /opt/bin/gds/gds -d /output_data -p 192.168.0.90:5000 -H 10.10.0.1/24 -D -t 2 
  4. In DWS, create the foreign tables foreign_tpcds_reasons1 and foreign_tpcds_reasons2 for receiving data from the data server.
    • Data export mode settings are as follows:
      • The directory for storing exported files is /output_data/ and the GDS monitoring port number is 5000 while GDS is started. The export directory created above is also /output_data/. Therefore, the location parameter is set to gsfs://192.168.0.90:5000/.
    • Data format parameter settings are as follows:
      • format is set to CSV.
      • encoding is set to UTF-8.
      • delimiter is set to E'\x08'.
      • quote is set to 0x1b.
      • null is set to an empty string without quotation marks.
      • escape is set to a double quotation mark.
      • header is set to false, indicating that the first row is identified as a data row in an exported file.

    Based on the preceding settings, the foreign table foreign_tpcds_reasons1 is created using the following statement:

    CREATE FOREIGN TABLE foreign_tpcds_reasons1
    (  
      r_reason_sk    integer     not null,
      r_reason_id    char(16)    not null,
      r_reason_desc  char(100)
    ) SERVER gsmpp_server OPTIONS (LOCATION 'gsfs://192.168.0.90:5000/', FORMAT 'CSV',ENCODING 'utf8', DELIMITER E'\x08', QUOTE E'\x1b', NULL '') WRITE ONLY;

    Based on the above settings, the foreign table foreign_tpcds_reasons2 is created using the following statement:

    CREATE FOREIGN TABLE foreign_tpcds_reasons2
    (  
      r_reason_sk    integer     not null,
      r_reason_id    char(16)    not null,
      r_reason_desc  char(100)
    ) SERVER gsmpp_server OPTIONS (LOCATION 'gsfs://192.168.0.90:5000/', FORMAT 'CSV', DELIMITER E'\x08', QUOTE E'\x1b', NULL '') WRITE ONLY;
  5. In the database, export data from table reasons1 through the foreign table foreign_tpcds_reasons1 and from table reasons2 through the foreign table foreign_tpcds_reasons2 to /output_data.
    INSERT INTO foreign_tpcds_reasons1 SELECT * FROM reasons1;
    INSERT INTO foreign_tpcds_reasons2 SELECT * FROM reasons2;
  6. After data export is complete, log in to the data server as user gds_user and stop GDS.
    The GDS process ID is 128954.
    ps -ef|grep gds
    gds_user 128954      1  0 15:03 ?        00:00:00 gds -d /output_data -p 192.168.0.90:5000 -D -t 2 
    gds_user 129003 118723  0 15:04 pts/0    00:00:00 grep gds
    kill -9 128954