Updated on 2026-11-06 GMT+08:00

Load Data

Function

LOAD DATA can be used to import data in CSV, Parquet, ORC, JSON, and Avro formats. The data is internally converted to the Parquet data format for storage.

Usage Restrictions

Datasource tables and Iceberg tables do not support the LOAD DATA operation.

Syntax

LOAD DATA INPATH 'folder_path' INTO TABLE [db_name.]table_name
   OPTIONS(property_name=property_value, ...);

Keywords

  • INPATH: Data path.
  • OPTIONS: A list of properties.

Parameters

Parameter

Mandatory

Description

folder_path

Yes

OBS path to the source data folder or file.

db_name

No

Database name. If not specified, the current database is used.

table_name

Yes

Name of the managed table into which data will be imported.

The following configuration options are available when importing data:

  • DATA_TYPE: Specifies the data type to import. Currently supports CSV, Parquet, ORC, JSON, and Avro types. The default value is CSV.

    Configuration: OPTIONS ('DATA_TYPE'='CSV')

    When importing CSV and JSON files, three modes are available:

    • PERMISSIVE: When a column's data type does not match the target table column's data type, the entire row is set to null.
    • DROPMALFORMED: When a column's data type does not match, the row is not imported.
    • FAILFAST: When a column's type does not match, an exception is thrown and the import fails.

    The mode can be set by adding OPTIONS('MODE'='PERMISSIVE') to the OPTIONS clause.

  • DELIMITER: Specifies the delimiter for the import command. The default value is ,.

    Configuration: OPTIONS('DELIMITER'=',')

    For CSV data, the following delimiters are supported:

    • Tab character, e.g., 'DELIMITER'='\t'.
    • Any binary character, e.g., 'DELIMITER'='\u0001(^A)'.
    • Single quote (`'`), which must be enclosed in double quotes (" "), e.g., 'DELIMITER'= "".
    • Managed tables also support \001 (^A) and \017 (^Q), e.g., 'DELIMITER'='\001(^A)', 'DELIMITER'='\017(^Q)'.
  • QUOTECHAR: Specifies the quote character for the import command. The default value is ".

    Configuration: OPTIONS('QUOTECHAR'='"')

  • COMMENTCHAR: Specifies the comment character for the import command. During the import operation, if a comment character is encountered at the beginning of a line, that line is treated as a comment and is not imported. The default value is #.

    Configuration: OPTIONS('COMMENTCHAR'='#')

  • HEADER: Indicates whether the source file has a header. Valid values are true and false. true means there is a header, and false means there is no header. The default value is false. If there is no header, the FILEHEADER parameter can be used in the import command to provide one.

    Configuration: OPTIONS('HEADER'='true')

  • FILEHEADER: If the source file does not have a header, a header can be provided in the LOAD DATA command.

    OPTIONS('FILEHEADER'='column1,column2')

  • ESCAPECHAR: If strict validation of escape characters on CSV is required, an escape character can be provided. The default value is \\.

    Configuration: OPTIONS('ESCAPECHAR'='\\')

    If ESCAPECHAR is entered in CSV data, it must be enclosed in double quotes (" "), e.g., "a\b".

  • MAXCOLUMNS: This optional parameter specifies the maximum number of columns the CSV parser parses in a single row.

    Configuration: OPTIONS('MAXCOLUMNS'='400')

    Table 1 MAXCOLUMNS parameters

    Optional Parameter Name

    Default Value

    Maximum Value

    MAXCOLUMNS

    2000

    20000

    After setting the MAXCOLUMNS option, importing data will impose memory requirements on the executor. Therefore, the import may fail due to insufficient executor memory.

  • DATEFORMAT: Specifies the date format for a column.

    OPTIONS('DATEFORMAT'='dateFormat')

    • The default value is yyyy-MM-dd.
    • The date format is specified by Java's date pattern string. In Java's date and time pattern strings, characters A to Z and a to z that are not enclosed in single quotes (') are interpreted as pattern characters, representing date or time string elements. If a pattern character is enclosed in single quotes ('), it is treated as literal text during parsing and is not interpreted. Refer to Table 2 for Java pattern character definitions.
    Table 2 Date and time pattern character definitions

    Pattern Character

    Date or Time Element

    Example

    G

    Era designator

    AD

    y

    Year

    1996; 96

    M

    Month in year

    July; Jul; 07

    w

    Week in year

    27 (27th week of the year)

    W

    Week in month

    2 (2nd week of the month)

    D

    Day in year

    189 (189th day of the year)

    d

    Day in month

    10 (10th day of the month)

    u

    Day number of week

    1 = Monday, ..., 7 = Sunday

    a

    Am/pm marker

    pm (12:00–24:00)

    H

    Hour in day (0–23)

    2

    h

    Hour in am/pm (1–12)

    12

    m

    Minute in hour

    30

    s

    Second in minute

    55

    S

    Millisecond

    978

    z

    Time zone

    Pacific Standard Time; PST; GMT-08:00

  • TIMESTAMPFORMAT: Specifies the timestamp format for a column.

    OPTIONS('TIMESTAMPFORMAT'='timestampFormat')

    • Default value: yyyy-MM-dd HH:mm:ss.
    • The timestamp format is specified by Java's time pattern string. Refer to Table 2 for Java time pattern string definitions.
  • Mode: Specifies the handling mode for error records during the import process. Three options are supported: PERMISSIVE, DROPMALFORMED, and FAILFAST.

    OPTIONS('MODE'='permissive')

    • PERMISSIVE (default): Parses bad records as much as possible. If a field cannot be converted, the entire row is set to null.
    • DROPMALFORMED: Ignores bad records that cannot be parsed.
    • FAILFAST: Throws an exception and causes the job to fail when encountering a record that cannot be parsed.
  • BADRECORDSPATH: Specifies the storage directory for error records during the import process.

    OPTIONS('BADRECORDSPATH'='obs://bucket/path')

    When this option is configured, MODE cannot be set and is fixed to DROPMALFORMED. Records that are successfully converted are imported into the target table, while records that fail conversion are stored in the specified error record storage directory.

Precautions

  • When importing into an OBS table, the path specified when creating the OBS table must be a folder. If the table creation path is a file, the data import will fail.
  • Only raw data located on an OBS path can be imported.
  • Concurrent data imports on the same table are not recommended, as there is a certain probability of concurrency conflicts leading to import failure.
  • Only one path can be specified when importing data. The path must not contain commas.
  • When a folder and a file have the same name in an OBS bucket directory, the data import will prioritize the file under that path over the folder.
  • When importing data in PARQUET, ORC, and JSON formats, the DATA_TYPE option must be specified. Otherwise, the data will be parsed in the default CSV format, resulting in incorrect data formatting.
  • When importing CSV and JSON data that includes date and time columns, the DATEFORMAT and TIMESTAMPFORMAT options must be specified. Otherwise, the default date and timestamp formats will be used for parsing.

Examples

  • The following statement can be used to import a CSV file into a managed table named t.
    LOAD DATA INPATH 'obs://aidatalake/data.csv' INTO TABLE t  
      OPTIONS('DELIMITER'=',' , 'QUOTECHAR'='"','COMMENTCHAR'='#','HEADER'='false');
  • The following statement can be used to import a JSON file into a managed table named jsontb.
    LOAD DATA INPATH 'obs://aidatalake/alltype.json' into table jsontb
      OPTIONS('DATA_TYPE'='json','DATEFORMAT'='yyyy/MM/dd','TIMESTAMPFORMAT'='yyyy/MM/dd HH:mm:ss');