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
On this page

Show all

Creating an OBS Foreign Table

Updated on 2022-08-16 GMT+08:00

Procedure

  1. Set location of the foreign table based on the path planned in Uploading Data to OBS.
  2. Obtain the access keys (AK and SK) to access OBS. To obtain access keys, log in to the management console, click the username in the upper right corner, and select My Credentials from the menu. Then choose Access Keys in the navigation tree on the left. On the Access Keys page, you can view the existing AKs or click Add Access Key to create an AK/SK pair.
  3. Set data format parameters for the foreign table based on the formats of data to be imported. You need to collect the following source data information:

    • format: format of the source data file in the foreign table. OBS foreign tables support CSV and TEXT formats. The default value is TEXT.
    • header: Whether the data file contains a table header. Only CSV files can have headers.
    • delimiter: Delimiter specified to separate data fields in a file. If no delimiter is specified, the default one will be used.
    • For more parameters used for foreign tables, see data format parameters.

  4. Plan the error tolerance of parallel import to specify how errors are handled during the import.

    • fill_missing_fields: When the last column in a row of the source data file is empty, this parameter specifies whether to report an error or set this field in the row to NULL.
    • ignore_extra_data: When the number of columns in the source data file is greater than that specified in the foreign table, this parameter specifies whether to report an error or ignore the extra columns.
    • per node reject limit: This parameter specifies the number of data format errors allowed on each DN. If the number of errors recorded in the error table on a DN exceeds the specified value, the import fails and an error message will be reported. This parameter is optional.
    • compatible_illegal_chars: When an illegal character is encountered, this parameter specifies whether to import an error, or convert it and proceed with the import.

      The following describes the rules for converting an invalid character:

      • \0 is converted to a space.
      • Other invalid characters are converted to question marks (?).
      • If NULL, DELIMITER, QUOTE, or ESCAPE is also set to a space or question mark, an error message such as "illegal chars conversion may confuse COPY escape 0x20" is displayed, prompting you to modify parameter settings that may cause import errors.
    • error_table_name: This parameter specifies the name of the table that records data format errors. After the parallel import, you can query this table for error details.
    • For details about the parameters, see error tolerance parameters.

  5. 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).

Example

Create a foreign table in the GaussDB(DWS) database. Parameters are described as follows:

  • Data format parameter access keys (AK and SK)
    • Set access_key to the AK you have obtained.
    • Set secret_access_key to the SK you have obtained.
    NOTE:

    The values of access_key and secret_access_key are examples only.

  • Set data format parameters.
    • Set format to CSV.
    • Set encoding to UTF-8.
    • Configure encrypt. Its default value is off.
    • Set delimiter to ,.
    • Retain the default value (double quotation marks) of quote.
    • Set null (null value in a source data file) to a null string without quotation marks.
    • Set header (whether the exported data file contains the header row) to the default value false. If the first row of the data file is not a header, retain the default value.
      NOTE:

      When exporting data from OBS, this parameter cannot be set to true. Use the default value false.

  • Set fault-tolerant parameters for data import.
    • Set PER NODE REJECT LIMIT to 'unlimited', indicating that all data format errors detected during data import are allowed.
    • Set LOG INTO to product_info_err, indicating that the data format errors detected during data import are recorded in the product_info_err table.
    • If fill_missing_fields is set to true and the last column of a data row in a source data file is lost, the column is replaced with NULL and no error message will be generated.
    • If ignore_extra_data is set to true and the number of columns of the source data file is greater than that defined for the foreign table, the extra columns at the end of the row are ignored and no error message will be generated.

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
27
28
29
30
31
32
DROP FOREIGN TABLE product_info_ext;

CREATE FOREIGN TABLE product_info_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/input_data/product_info | obs://mybucket02/input_data/product_info',
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',
fill_missing_fields 'true',
ignore_extra_data 'true'
)
READ ONLY 
LOG INTO product_info_err 
PER NODE REJECT LIMIT 'unlimited';

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

1
CREATE FOREIGN TABLE

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