Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Example of Importing Data Using GDS

Updated on 2023-03-17 GMT+08:00

Example: Parallel Import from Multiple Data Servers

The data servers reside on the same intranet as the cluster. Their IP addresses are 192.168.0.90 and 192.168.0.91. Source data files are in CSV format.

  1. Create the target table tpcds.reasons.
    1
    2
    3
    4
    5
    6
    CREATE TABLE tpcds.reasons
    (
      r_reason_sk integer not null,
      r_reason_id char(16) not null,
      r_reason_desc char(100)
    );
    
  2. Log in to each GDS data server as user root and create the /input_data directory for storing data files on the servers. The following takes the data server whose IP address is 192.168.0.90 as an example. Operations on the other server are the same.
    mkdir -p /input_data
  3. (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
  4. Evenly distribute source data files to the /input_data directories on the data servers.
  5. Change the owners of source data files and the /input_data directory on each data server to gds_user. The data server with the IP address 192.168.0.90 is used as an example.
    chown -R gds_user:gdsgrp /input_data 
  6. Log in to each data server as user gds_user and start GDS.

    The GDS installation path is /opt/bin/dws/gds. Source data files are stored in /input_data/. The IP addresses of the data servers are 192.168.0.90 and 192.168.0.91. The GDS listening port is 5000. GDS runs in daemon mode.

    Start GDS on the data server whose IP address is 192.168.0.90.
    /opt/bin/dws/gds/gds -d /input_data -p 192.168.0.90:5000 -H 10.10.0.1/24 -D

    Start GDS on the data server whose IP address is 192.168.0.91.

    /opt/bin/dws/gds/gds -d /input_data -p 192.168.0.91:5000 -H 10.10.0.1/24  -D
  7. Create the foreign table tpcds.foreign_tpcds_reasons for the source data.

    Set import mode parameters as follows:

    • Set the import mode to Normal.
    • When GDS is started, the source data file directory is /input_data and the GDS listening port is 5000. Therefore, set location to gsfs://192.168.0.90:5000/* | gsfs://192.168.0.91:5000/*.

    Information about the data format is set based on data format parameters specified during data export. The 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 the same value as that of quote by default.
    • header is set to false, indicating that the first row is regarded as a data row when a file is imported.

    Set import error tolerance parameters as follows:

    • Set PER NODE REJECT LIMIT (number of allowed data format errors) to unlimited. In this case, all the data format errors detected during data import will be tolerated.
    • Set LOG INTO to err_tpcds_reasons. The data format errors detected during data import will be recorded in the err_tpcds_reasons table.

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

    1
    2
    3
    4
    5
    6
    7
    CREATE FOREIGN TABLE tpcds.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/* | gsfs://192.168.0.91:5000/*', format 'CSV',mode 'Normal', encoding 'utf8', delimiter E'\x08', quote E'\x1b', null '', fill_missing_fields 'false') LOG INTO err_tpcds_reasons PER NODE REJECT LIMIT 'unlimited';
    
  8. Import data through the foreign table tpcds.foreign_tpcds_reasons to the target table tpcds.reasons.
    1
    INSERT INTO tpcds.reasons SELECT * FROM tpcds.foreign_tpcds_reasons;
    
  9. Query data import errors in the err_tpcds_reasons table and rectify the errors (if any). For details, see Handling Import Errors.
    1
    SELECT * FROM err_tpcds_reasons;
    
  10. After data import is complete, log in to each data server as user gds_user and stop GDS.
    The data server with the IP address 192.168.0.90 is used as an example. The GDS process ID is 128954.
    ps -ef|grep gds
    gds_user 128954      1  0 15:03 ?        00:00:00 gds -d /input_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: Data Import Using Multiple Threads

The data server resides on the same intranet as the cluster. The server IP address is 192.168.0.90. Source data files are in CSV format. Data will be imported to two tables using multiple threads in Normal mode.

  1. In the database, create the target tables tpcds.reasons1 and tpcds.reasons2.
    1
    2
    3
    4
    5
    6
    CREATE TABLE tpcds.reasons1
    (
      r_reason_sk integer not null,
      r_reason_id char(16) not null,
      r_reason_desc char(100)
    ) ;
    
    1
    2
    3
    4
    5
    6
    CREATE TABLE tpcds.reasons2
    (
      r_reason_sk integer not null,
      r_reason_id char(16) not null,
      r_reason_desc char(100)
    ) ;
    
  2. Log in to the GDS data server as user root, and then create the data file directory /input_data and its sub-directories /input_data/import1/ and /input_data/import2/.
    mkdir -p /input_data
  3. Store the source data files of the target table tpcds.reasons1 in /input_data/import1/ and the source data files of the target table tpcds.reasons2 in /input_data/import2/.
  4. (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
  5. Change the owners of source data files and the /input_data directory on the data server to gds_user.
    chown -R gds_user:gdsgrp /input_data 
  6. Log in to the data server as user gds_user and start GDS.
    The GDS installation path is /gds. Source data files are stored in /input_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. A recursive directory is specified.
    /gds/gds -d /input_data -p 192.168.0.90:5000 -H 10.10.0.1/24  -D -t 2 -r
  7. In the database, create the foreign tables tpcds.foreign_tpcds_reasons1 and tpcds.foreign_tpcds_reasons2 for the source data.

    The foreign table tpcds.foreign_tpcds_reasons1 is used as an example to describe how to configure parameters in a foreign table.

    Set import mode parameters as follows:

    • Set the import mode to Normal.
    • When GDS is started, the configured source data file directory is /input_data and the GDS listening port is 5000. However, source data files are actually stored in /input_data/import1/. Therefore, set location to gsfs://192.168.0.90:5000/import1/*.

    Information about the data format is set based on data format parameters specified during data export. The 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 the same value as that of quote by default.
    • header is set to false, indicating that the first row is regarded as a data row when a file is imported.

    Set import error tolerance parameters as follows:

    • Set PER NODE REJECT LIMIT (number of allowed data format errors) to unlimited. In this case, all the data format errors detected during data import will be tolerated.
    • Set LOG INTO to err_tpcds_reasons1. The data format errors detected during data import will be recorded in the err_tpcds_reasons1 table.
    • If the last column (fill_missing_fields) in a source data file is missing, the NULL column will be automatically added to the target file.

    Based on the preceding settings, the foreign table tpcds.foreign_tpcds_reasons1 is created as follows:

    1
    2
    3
    4
    5
    6
    CREATE FOREIGN TABLE tpcds.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/import1/*', format 'CSV',mode 'Normal', encoding 'utf8', delimiter E'\x08', quote E'\x1b', null '',fill_missing_fields 'on')LOG INTO err_tpcds_reasons1 PER NODE REJECT LIMIT 'unlimited';
    

    Based on the preceding settings, the foreign table tpcds.foreign_tpcds_reasons2 is created as follows:

    1
    2
    3
    4
    5
    6
    CREATE FOREIGN TABLE tpcds.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/import2/*', format 'CSV',mode 'Normal', encoding 'utf8', delimiter E'\x08', quote E'\x1b', null '',fill_missing_fields 'on')LOG INTO err_tpcds_reasons2 PER NODE REJECT LIMIT 'unlimited';
    
  8. Import data to tpcds.reasons1 using the foreign table tpcds.foreign_tpcds_reasons1, and to tpcds.reasons2 using the foreign table tpcds.foreign_tpcds_reasons2.
    1
    INSERT INTO tpcds.reasons1 SELECT * FROM tpcds.foreign_tpcds_reasons1;
    
    1
    INSERT INTO tpcds.reasons2 SELECT * FROM tpcds.foreign_tpcds_reasons2;
    
  9. Query data import errors in the err_tpcds_reasons1 and err_tpcds_reasons2 tables and rectify the errors (if any). For details, see Handling Import Errors.
    1
    2
    SELECT * FROM err_tpcds_reasons1;
    SELECT * FROM err_tpcds_reasons2;
    
  10. After data import 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 /input_data -p 192.168.0.90:5000 -D -t 2 -r
    gds_user 129003 118723  0 15:04 pts/0    00:00:00 grep gds
    kill -9 128954

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback