Purpose
The
LOAD DATAstatement of OceanBase Database supports loading the following input files:Server-side (OBServer node) files: These files are located on the OBServer nodes of OceanBase Database. You can use the
LOAD DATA INFILEstatement or theLOAD DATA FROM URLstatement to load data from these server-side files into a database table.Client (local) files: Files are located in the client's local file system. You can use the
LOAD DATA LOCAL INFILEstatement or theLOAD DATA FROM URLstatement to load data from a local client file into a database table.Note
When you execute the
LOAD DATA LOCAL INFILEstatement in OceanBase Database, the system automatically adds theIGNOREoption.OSS files: Files located in the OSS file system. You can use the
LOAD DATA REMOTE_OSS INFILEstatement to load data from an OSS file into a database table.
LOAD DATA can currently import text files in CSV format. The entire import process can be divided into the following steps:
Parse the file: OceanBase Database reads the data from the file specified by the user and parses the data in parallel or serial mode based on the specified degree of parallelism.
Data distribution: As OceanBase is a distributed database, data in different partitions may be distributed across various OBServer nodes. The
LOAD DATAstatement calculates the data to be parsed and determines which OBServer node should receive the data.Insert data: After receiving the data, the target OBServer node executes an
INSERToperation locally to insert the data into the corresponding partition.
Considerations
The
LOAD DATAstatement is prohibited for tables with triggers.To import data from an external file, you must have the
FILEprivilege and the following settings:- When loading server-side files, you must set the system variable secure_file_priv in advance to configure the accessible path for import or export files.
- When loading a local client file, you must add the
--local-infile[=1]option when starting the MySQL/OBClient client to enable data loading from the local file system.
When using direct load for a specified partition, note that the target table cannot be a replicated table and must not contain auto-increment columns, identity columns, or global indexes.
To import data from an external file, you must have the FILE privilege. You can grant this privilege using the GRANT FILE ON *.* TO $user_name; statement, where $user_name is the user who will execute the LOAD DATA command.
Syntax
-- Import a regular file
LOAD DATA
[/*+ PARALLEL(N) [load_batch_size(M)] [APPEND | direct(bool, int, [load_mode])] | NO_DIRECT */]
[REMOTE_OSS | LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE table_name [PARTITION(PARTITION_OPTION)]
[COMPRESSION [=] {AUTO|NONE|GZIP|DEFLATE|ZSTD}]
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
[IGNORE number {LINES | ROWS}]
[(column_name_var
[, column_name_var] ...)]
load_mode:
'full'
| 'inc_replace'
PARTITION_OPTION:
partition_option_list
| subpartition_option_list
-- Import URL File
LOAD DATA
[/*+ PARALLEL(N) [load_batch_size(M)] [APPEND | direct(bool, int, [load_mode])] | NO_DIRECT */]
[REPLACE | IGNORE]
FROM { url_table_function_expr |
( SELECT expression_list FROM url_table_function_expr ) }
INTO TABLE table_name
[PARTITION(PARTITION_OPTION)]
[(column_name_var [, column_name_var] ...)]
[LOG ERRORS
[INTO 'logfile_string']
[REJECT LIMIT {integer | UNLIMITED}]
[BADFILE 'badfile_string']]
load_mode:
'full'
| 'inc_replace'
url_table_function_expr:
| FILES (
LOCATION = '<string>',
{
FORMAT = (
TYPE = 'CSV',
LINE_DELIMITER = '<string>' | <expr>,
FIELD_DELIMITER = '<string>' | <expr>,
PARSE_HEADER = { TRUE | FALSE },
ESCAPE = '<character>' | <expr>,
FIELD_OPTIONALLY_ENCLOSED_BY = '<character>' | <expr>,
ENCODING = 'charset',
NULL_IF = ('<string>' | <expr>, '<string>' | <expr> ...),
SKIP_HEADER = <int>,
SKIP_BLANK_LINES = { TRUE | FALSE },
TRIM_SPACE = { TRUE | FALSE },
EMPTY_FIELD_AS_NULL = { TRUE | FALSE }
)
| FORMAT = ( TYPE = 'PARQUET' | 'ORC' )
},
[PATTERN = '<regex_pattern>']
)
| SOURCE (
TYPE = 'ODPS',
ACCESSID = '<string>',
ACCESSKEY = '<string>',
ENDPOINT = '<string>',
TUNNEL_ENDPOINT = '<string>',
PROJECT_NAME = '<string>',
SCHEMA_NAME = '<string>',
TABLE_NAME = '<string>',
QUOTA_NAME = '<string>',
COMPRESSION_CODE = '<string>'
)
PARTITION_OPTION:
partition_option_list
| subpartition_option_list
Parameters
Parameter |
Description |
||
|---|---|---|---|
| parallel(N) | The degree of parallelism for loading data, which is 4 by default. | ||
| load_batch_size(M) | Specify the batch size for each insertion.MDefault:100. The recommended value range is [100, 1000]. |
||
| APPEND \ | direct() \ | NO_DIRECT | Use the hint to enable the direct load feature.
NoticeWe recommend that you do not upgrade OceanBase Database during a direct load task, as this may cause the task to fail.
LOAD DATA. |
| REMOTE_OSS \ | LOCAL | Optional. Valid values:
|
|
| file_name | Specifies the path and file name of the input file. The file_name format is as follows:
NoteWhen importing a file from OSS, ensure the following:
|
||
| table_name | The name of the table into which data is imported. Partitioned and non-partitioned tables are supported. | ||
| PARTITION_OPTION | The partition name for direct load of a specified partition:
NoteSpecifying partitions is only supported for direct load and not for regular LOAD DATA. That is, if you do not add a direct load hint or configure direct load parameters, specifying partitions will not take effect when executing LOAD DATA. |
||
| COMPRESSION | Specifies the compression file format. Valid values:
|
||
| FIELDS \ | COLUMNS | Specifies the format of the field.
|
|
| LINES STARTING BY | Specifies the line start character. | ||
| LINES TERMINATED BY | Specifies the line terminator. | ||
| IGNORE number { LINES \ | ROWS } | Ignore the first few lines,LINESindicates the first few lines of a file,ROWSIndicates the first few rows of data specified by the field separator. By default, each field in the input file is matched with a column in the table. If the input file does not contain all columns, the missing columns are filled in by default according to the following rules:
NoteThe behavior is similar to that of single-file import for multi-file import. |
|
| column_name_var | Optional. Specifies the column names to import. | ||
| LOG ERRORS | Optional. Specifies to enable error diagnostics during the import of external tables via URL. For more information, see log_errors. |
FILES
The FILES keyword consists of the LOCATION clause, the FORMAT clause, and the PATTERN clause.
The
LOCATIONclause specifies the path where the external table files are stored. Typically, the data files for an external table are placed in a single directory, which can contain subdirectories. When creating a table, the external table automatically collects all files in this directory.The local LOCATION format is
LOCATION = '[file://] local_file_path', wherelocal_file_pathcan be a relative or absolute path. If a relative path is provided, the current directory must be the installation directory of OceanBase Database.secure_file_privconfigures the file paths that OBServer nodes are authorized to access.local_file_pathcan only be a subpath of thesecure_file_privpath.The remote Location format is as follows:
LOCATION = '{oss|S3}://$ACCESS_ID:$ACCESS_KEY@$HOST:s3_region/remote_file_path', where$ACCESS_ID,$ACCESS_KEY, and$HOSTare the access information required for accessing OSS and S3, respectively.s3_regionis the region selected when using S3. This sensitive access information is stored encrypted in the database's system tables.LOCATION = 'hdfs://${hdfs_namenode_address}:${port}/PATH.localhost', whereportrefers to the HDFS port number, andPATHrefers to the directory path in HDFS.- With Kerberos authentication:
LOCATION = 'hdfs://localhost:port/user?principal=xxx&keytab=xxx&krb5conf=xxx&configs=xxx'. Where:principal: the user for login authentication.keytab: the path to the keytab file for user authentication.krb5conf: the path to the description file for the Kerberos environment used by the user.configs: specifies additional HDFS configuration parameters. Default is empty, but in a Kerberos environment, this parameter typically has a value and needs to be configured, for example:dfs.data.transfer.protection=authentication,privacy, specifying the data transfer protection level asauthenticationandprivacy.
- With Kerberos authentication:
Note
When using an object storage path, the parameters of the object storage path are separated by the
&symbol. Ensure your input parameter values contain only uppercase and lowercase letters, numbers,\/-_$+=, and wildcards. Entering characters other than those listed above may cause setting failure.
The
FORMATclause specifies attributes related to the file format to read, supporting CSV, PARQUET, and ORC formats.When TYPE = 'CSV', it includes the following fields:
LINE_DELIMITER: specifies the line delimiter for the CSV file. Default isLINE_DELIMITER='\n'.FIELD_DELIMITER: optional, specifies the column delimiter for the CSV file. Default isFIELD_DELIMITER='\t'.PARSE_HEADER: optional, specifies whether the first line of the CSV file is the column name for each column. Default isFALSE, meaning the first line of the CSV file is not designated as column names.ESCAPE: specifies the escape character for the CSV file, which must be one byte. Default isESCAPE ='\'.FIELD_OPTIONALLY_ENCLOSED_BY: optional, specifies the character that wraps field values in the CSV file. Default is empty. Using this option means only certain types of fields (such as CHAR, VARCHAR, TEXT, JSON, etc.) will have wrappers.ENCODING: specifies the character set encoding format of the file. If not specified, the default value isUTF8MB4.NULL_IF: specifies strings to be treated asNULL. Default value is empty.SKIP_HEADER: skips the file header and specifies the number of lines to skip.SKIP_BLANK_LINES: specifies whether to skip blank lines. Default value isFALSE, meaning blank lines are not skipped.TRIM_SPACE: specifies whether to remove leading and trailing spaces from fields in the file. Default value isFALSE, meaning spaces at the beginning and end of fields are not removed.EMPTY_FIELD_AS_NULL: specifies whether to treat empty strings asNULL. Default value isFALSE, meaning empty strings are not treated asNULL.
When TYPE = 'PARQUET/ORC', there are no additional fields.
The
PATTERNclause specifies a regular expression pattern string to filter files under theLOCATIONdirectory. For each file path under the LOCATION directory, if it matches this pattern string, the external table accesses the file; otherwise, it skips the file. If this parameter is not specified, access is allowed to all files under theLOCATIONdirectory by default.
SOURCE
The SOURCE keyword does not contain other clauses. In this case, TYPE = 'ODPS' and includes the following fields:
ACCESSID: the ID of the ODPS user.ACCESSKEY: The password of the ODPS user.ENDPOINT: the connection address of the ODPS service.TUNNEL_ENDPOINT: the connection address of the tunnel data transmission service.PROJECT_NAME: Specifies the project containing the table to be queried.SCHEMA_NAME: Optional. Specifies the schema of the table to be queried.TABLE_NAME: the name of the table to query.QUOTA_NAME: Optional. Specifies whether to use the specified quota.COMPRESSION_CODE: Optional. Specifies the compression format for the data source. Valid values areZLIB,ZSTD,LZ4, andODPS_LZ4. If not specified, compression is disabled.
log_errors
LOG ERRORS: Enables error diagnostics during the import process, allowing failed rows to be recorded instead of terminating the entire operation upon the first error. Combined with theREJECT LIMITclause, it controls the maximum number of erroneous rows allowed.INTO 'logfile_string': Optional. Specifies a file in the target directory to which error messages are written. If you do not specifyINTO 'logfile_string', error messages are recorded only in thewarning buffer, which can be viewed by using theshow warningsstatement.logfile_stringspecifies the directory for storing error messages. The format is as follows:Note
The
INTO 'logfile_string'parameter is supported starting from V4.4.0.When the error message is stored locally, the
logfile_stringformat is[file://] local_file_path, wherelocal_file_pathcan be a relative or absolute path. If a relative path is provided, the current directory must be the installation directory of OceanBase Database.secure_file_privis used to configure the file paths that OBServer nodes have permission to access.local_file_pathcan only be a subpath of thesecure_file_privpath.When the error message is stored remotely (refer to the Location section in the external table creation syntax), the
logfile_stringformat is as follows:{oss\|s3}://$ACCESS_ID:$ACCESS_KEY@$HOST:s3_region/remote_file_path, where$ACCESS_ID,$ACCESS_KEY, and$HOSTare the access information required to configure access to Alibaba Cloud OSS, AWS S3, and object storage compatible with the S3 protocol.s3_regionis the region information selected when using S3. This sensitive access information is stored in encrypted form in the database's system tables.hdfs://localhost:port/PATH, wherelocalhostis the HDFS address,portis the HDFS port number, and PATH is the directory path in HDFS. The address with Kerberos authentication is:hdfs://localhost:port/user?principal=xxx&keytab=xxx&krb5conf=xxx&configs=xxx.
OceanBase Database supports setting tenant parameters to configure the compression algorithm for diagnostic logs and the maximum size of a single diagnostic log file. For more information, see load_data_diagnosis_log_compression and load_data_diagnosis_log_max_size.
REJECT LIMIT: Optional. The maximum number of erroneous rows allowed:- The default value is 0, which means no error rows are allowed. The operation fails upon encountering the first error.
integer: The maximum number of erroneous rows allowed on a single server. For example, 10 indicates that a maximum of 10 erroneous rows are allowed on one server.UNLIMITED: Allows an unlimited number of erroneous rows.
BADFILE 'badfile_string': Specifies the path for storing the bad data file. The value format ofbadfile_stringis the same as that oflogfile_string.Note
The
BADFILE 'badfile_string'parameter is supported starting with V4.4.0.
Notice
- If the
LOG ERRORSclause is not specified, the behavior is the normal import behavior, which is to report an error immediately upon encountering the first error. - If the
LOG ERRORSclause is specified but theREJECT LIMITclause is not specified, it is equivalent to specifying a diagnosticLIMITof 0. The operation will fail upon encountering the first error, but the first encountered error will be logged, and the error code will also be a diagnostic error, namely "reject limit reached".View error logs
OceanBase Database supports the following SQL statement to view the exported error log information:
SELECT * FROM READ_ERROR_LOG('diagnosis_log_path');Here,
diagnosis_log_pathindicates the path of the error log. When executed, this SQL statement is equivalent to the following read URL external table statement:SELECT * FROM FILES ( LOCATION = 'diagnosis_log_path/' FORMAT( TYPE = 'csv' FIELD_DELIMITER = ',' FIELD_OPTIONALLY_ENCLOSED_BY = '\', PARSE_HEADER = true ) [, PATTERN = 'filename'] );Example:
When the specified log path results in a file name that does not end with
/.SELECT * FROM READ_ERROR_LOG('diagnosis/log/path/filename');The URL external table statement corresponding to this SQL statement is as follows (the file name will be used as a pattern to filter files):
SELECT * FROM FILES ( LOCATION = 'diagnosis/log/path/', FORMAT ( TYPE = 'csv' FIELD_DELIMITER = ',' FIELD_OPTIONALLY_ENCLOSED_BY = '\', PARSE_HEADER = true ), PATTERN = 'filename' );The specified log path results in a folder (ending with
/).SELECT * FROM READ_ERROR_LOG('diagnosis/log/path/');The corresponding URL external table statement for this SQL statement is as follows (pattern is not used):
SELECT * FROM FILES ( LOCATION = 'diagnosis/log/path/', FORMAT ( TYPE = 'csv' FIELD_DELIMITER = ',' FIELD_OPTIONALLY_ENCLOSED_BY = '\', PARSE_HEADER = true ) );
Rules for wildcards during multi-file direct load
To facilitate multi-file import, file wildcard functionality has been introduced. It applies to server-side and OSS file imports, but not to client-side file imports.
Server-side wildcard usage
Matching rules:
File name matching:
load data /*+ parallel(20) direct(true, 0) */ infile '/xxx/test.*.csv' replace into table t1 fields terminated by '|';Matching directory:
load data /*+ parallel(20) direct(true, 0) */ infile '/aaa*bb/test.1.csv' replace into table t1 fields terminated by '|';Matches both the directory and file name:
load data /*+ parallel(20) direct(true, 0) */ infile '/aaa*bb/test.*.csv' replace into table t1 fields terminated by '|';
Considerations:
There must be at least one matching file; otherwise, return error code 4027.
For the input of
load data /*+ parallel(20) direct(true, 0) */ infile '/xxx/test.1*.csv,/xxx/test.6*.csv' replace into table t1 fields terminated by '|';,/xxx/test.1*.csv,/xxx/test.6*.csvwill be considered a whole match. If no match is found, error 4027 will be reported.Only the POSIX GLOB function supports the following wildcards:
test.6*(6|0).csvandtest.6*({0.csv,6.csv}|.csv). Although these files can be found using thelscommand, the GLOB function cannot match them and returns error 4027.
Use wildcard characters in Cloud Object Storage Service (
OSS)Matching rules:
Match file name:
load data /*+ parallel(20) direct(true, 0) */ remote_oss infile 'oss://xxx/test.*.csv?host=xxx&access_id=xxx&access_key=xxx' replace into table t1 fields terminated by '|';Considerations:
Directory matching is not supported. For example, the statement
load data /*+ parallel(20) direct(true, 0) */ remote_oss infile 'oss://aa*bb/test.*.csv?host=xxx&access_id=xxx&access_key=xxx' replace into table t1 fields terminated by '|';will returnOB_NOT_SUPPORTED.File name wildcards only support
*and?. Other wildcards, although allowed, will not match anything.
Examples
Import data from a server-side (OBServer node) file
Example 1: Import data from a file on the server side.
Set the global security path.
Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.obclient> SET GLOBAL secure_file_priv = "/";Log off.
Note
secure_file_privis aGLOBALvariable. You must execute\qto exit and make it effective.obclinet> \qThe return result is as follows:
ByeAfter reconnecting to the database, use the
LOAD DATAstatement to import the data.Normal import.
obclient> LOAD DATA INFILE '/home/admin/test.csv' INTO TABLE t1;Use the
APPENDhint to enable direct load.LOAD DATA /*+ PARALLEL(4) APPEND */ INFILE '/home/admin/test.csv' INTO TABLE t1;
Example 2: Use the
APPENDhint to enable direct load.LOAD DATA /*+ PARALLEL(4) APPEND */ INFILE '/home/admin/a.csv' INTO TABLE t;Example 3: Import a CSV file.
Import all columns from the
test1.csvfile.load data /*+ direct(true,0) parallel(2)*/ from files( location = "data/csv", format = ( type = 'csv', field_delimiter = ',', parse_header = true, skip_blank_lines = true ), pattern = 'test1.csv') into table t1;Read columns
c1andc2from thetest1.csvfile located at thedata/csvpath, and import them into columnscol1andcol2of tablet1.load data /*+ direct(true,0) parallel(2)*/ from ( select c1, c2 from files( location = 'data/csv' format = ( type = 'csv', field_delimiter = ',', parse_header = true, skip_blank_lines = true ), pattern = 'test1.csv')) into table t1 (col1, col2);
Example 4: Import a PARQUET file.
load data /*+ direct(true,0) parallel(2)*/ from files( location = "data/parquet", format = ( type = 'PARQUET'), pattern = 'test1.parquet') into table t1;Example 5: Import an ORC file.
load data /*+ direct(true,0) parallel(2)*/ from files( location = "data/orc", format = ( type = 'ORC'), pattern = 'test1.orc') into table t1;Example 6: Import an ODPS file.
load data /*+ direct(true,0) parallel(2)*/ from source ( type = 'ODPS', accessid = '$ODPS_ACCESSID', accesskey = '******', endpoint= '$ODPS_ENDPOINT', project_name = 'example_project', schema_name = '', table_name = 'example_table', quota_name = '', compression_code = '') into table t1;Import data from a client (local) file
Example 1: Import data from a local file to a table in OceanBase Database.
Open a terminal or command prompt window and enter the following command to start the client.
obclient --local-infile -hxxx.xxx.xxx.xxx -P2881 -usys@oracle001 -p******The return result is as follows:
Welcome to the OceanBase. Commands end with ; or \g. Your OceanBase connection id is 3221548006 Server version: OceanBase 4.2.2.0 (r100000032024010510-75c47d4be18a399e13c5309de1a81da5caf4e7c0) (Built Jan 5 2024 10:17:55) Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient [SYS]>Notice
To use the
LOAD DATA LOCAL INFILEfeature, please use the OBClient client of version 2.2.4 or later.On the client, execute the
LOAD DATA LOCAL INFILEstatement to load the local data file.obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/test_data/tbl1.csv' INTO TABLE tbl1 FIELDS TERMINATED BY ',';The return result is as follows:
Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0
Example 2: Import a compressed file directly by setting COMPRESSION.
LOAD DATA LOCAL INFILE '/your/file/lineitem.tbl.gz' INTO TABLE lineitem COMPRESSION GZIP FIELDS TERMINATED BY '|';Example 3: Direct load by partition using the PARTITION clause.
- Specify direct load for a partition
load data /*+ direct(true,0) parallel(2) load_batch_size(100) */ infile "$FILE_PATH" into table t1 partition(p0, p1) fields terminated by '|' enclosed by '' lines starting by '' terminated by '\n';- Specify direct load for subpartition
load data /*+ direct(true,0) parallel(2) load_batch_size(100) */ infile "$FILE_PATH" into table t1 partition(p0sp0, p1sp1) fields terminated by '|' enclosed by '' lines starting by '' terminated by '\n';Import data from an OSS file
Example 1: Use the
direct(bool, int)hint to enable direct load. The direct load file can be stored on OSS.LOAD DATA /*+ direct(true,1024) parallel(16) */ REMOTE_OSS INFILE 'oss://antsys-oceanbasebackup/backup_rd/xiaotao.ht/lineitem2.tbl?host=***.oss-cdn.***&access_id=***&access_key=***' INTO TABLE tbl1 FIELDS TERMINATED BY ',';Import data from a server-side file as a URL external table
Notice
The IP addresses in the example have been masked. When verifying, you must enter your own real IP address.
The following example shows how to create an external table on a server (OBServer node) and in Oracle-compatible mode of OceanBase Database based on the location of the external file. The procedure is as follows:
Create directories on the OBServer node. The
/home/admin/test_csvdirectory stores external data, the/home/admin/test_intodirectory stores error messages, and the/home/admin/test_badfiledirectory stores bad data files.[admin@xxx /home/admin]# mkdir -p /home/admin/{test_csv,test_into,test_badfile}Prepare an external file. Create a file named
type_cast.csvin the/home/admin/test_csvdirectory.[admin@xxx /home/admin/test_csv]# vi type_cast.csvThe content of the file is as follows:
1,2,3 2,4,af 3,4,5 ds,6,32 4,5,6 5,2,3 6,v4,af 7,4,5 kj,a6,32 8,5,6Set the import file path.
Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.Run the following command to log in to the server where the OBServer node is located.
ssh admin@10.10.10.1Run the following command to connect to the
oracle001tenant using a local Unix socket connection.obclient -S /home/admin/oceanbase/run/sql.sock -usys@oracle001 -p******Execute the following SQL statement to set import and export limits to unlimited.
SET GLOBAL secure_file_priv = "/";
Reconnect to the
oracle001tenant.Example:
obclient -h10.10.10.1 -P2881 -usys@oracle001 -p****** -ACreate the table
test_tbl1.CREATE TABLE test_tbl1(col1 INT, col2 INT, col3 INT);Set the compression algorithm for diagnostic logs to
AUTO.ALTER SYSTEM SET load_data_diagnosis_log_compression = 'AUTO';For more information about setting the compression algorithm used by diagnostic logs, see load_data_diagnosis_log_compression.
Set the maximum log file size to 1 KB. When the size of the exported log exceeds 1 KB, a second file is automatically generated and the export continues.
ALTER SYSTEM SET load_data_diagnosis_log_max_size = '1K';For more information about setting the maximum size of a single diagnostic log file, see load_data_diagnosis_log_max_size.
Use the
LOAD DATAstatement to import data into tabletest_tbl1from an external URL table, specifying error diagnostics, the directory for storing error logs as/home/admin/test_into/, and the directory for storing error data files as/home/admin/test_badfile/.LOAD DATA FROM FILES( LOCATION = '/home/admin/test_csv/', FORMAT = ( TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'type_cast.csv') INTO TABLE test_tbl1 LOG ERRORS INTO '/home/admin/test_into/' REJECT LIMIT UNLIMITED BADFILE '/home/admin/test_badfile/';The return result is as follows:
Query OK, 6 rows affected, 4 warnings Records: 6 Deleted: 0 Skipped: 0 Warnings: 4Use the
read_error_logstatement to view the contents of the error log.SELECT * FROM READ_ERROR_LOG('/home/admin/test_into');The return result is as follows:
+------------+---------------+-------------+-------------------------------------------------------------------------------------------------------+ | ERROR CODE | FILE NAME | LINE NUMBER | ERROR MESSAGE | +------------+---------------+-------------+-------------------------------------------------------------------------------------------------------+ | -5114 | type_cast.csv | 4 | fail to scan file type_cast.csv at line 4 for column "SYS"."TEST_TBL1"."COL1", error: Invalid numeric | | -5114 | type_cast.csv | 9 | fail to scan file type_cast.csv at line 9 for column "SYS"."TEST_TBL1"."COL1", error: Invalid numeric | | -5114 | type_cast.csv | 7 | fail to scan file type_cast.csv at line 7 for column "SYS"."TEST_TBL1"."COL2", error: Invalid numeric | | -5114 | type_cast.csv | 2 | fail to scan file type_cast.csv at line 2 for column "SYS"."TEST_TBL1"."COL3", error: Invalid numeric | +------------+---------------+-------------+-------------------------------------------------------------------------------------------------------+ 4 rows in setView the data in the
test_tbl1table.SELECT * FROM test_tbl1;The return result is as follows:
+------+------+------+ | COL1 | COL2 | COL3 | +------+------+------+ | 1 | 2 | 3 | | 3 | 4 | 5 | | 4 | 5 | 6 | | 5 | 2 | 3 | | 7 | 4 | 5 | | 8 | 5 | 6 | +------+------+------+ 6 rows in setView the content of the bad file through the URL external table.
SELECT * FROM FILES ( LOCATION = '/home/admin/test_badfile', FORMAT ( TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'data.bad');The return result is as follows:
+------+------+------+ | C1 | C2 | C3 | +------+------+------+ | ds | 6 | 32 | | kj | a6 | 32 | | 6 | v4 | af | | 2 | 4 | af | +------+------+------+ 4 rows in set
References
- For more examples of using the
LOAD DATAstatement, see Import data by using the LOAD DATA statement.
