Skip to main content

CSV

Load CSV files with Stream Load, Broker Load, Routine Load, MySQL Load, or a table-valued function. Configure delimiters, quoting, escaping, header handling, and compression to match your source files.

Before you start​

Create or select the target database, and use a warehouse SQL user with the required table and load permissions. Copy the Stream Load request URL from Connection Methods. Replace <endpoint> with its scheme, host, and port, and preserve HTTPS when it is required. Replace <username> with your warehouse SQL username. The curl commands prompt for your password.

For object storage, HDFS, or Kafka, confirm that your warehouse can reach the source and use its supported authentication settings. HDFS and private-network access depend on your deployment. Each SQL snippet is a separate example. Replace source paths, connection properties, and job labels before running it.

Quick navigation​

Before you start, choose an appropriate import method based on your data source and timeliness requirements, then refer to the parameters and examples in the corresponding section:

  • Small local files, HTTP push: use Stream Load
  • Large batches of files in object storage / HDFS: use Broker Load
  • Real-time data streams from Kafka: use Routine Load
  • Local files via the MySQL client: use MySQL Load
  • Querying or loading external storage files directly via SQL: use S3 TVF or HDFS TVF

Supported import methods​

VeloDB Cloud provides the following methods for importing CSV-format data:

Import methodApplicable scenarioEntry point
Stream LoadPush local files or program data via HTTPStream Load
Broker LoadBatch import from remote storage such as S3 / HDFSBroker Load
Routine LoadContinuously subscribe to and import from KafkaRoutine Load
MySQL LoadImport local files via the MySQL protocolMySQL Load
INSERT INTO FROM S3 TVFRead S3 files directly and insert into a tableS3 TVF
INSERT INTO FROM HDFS TVFRead HDFS files directly and insert into a tableHDFS TVF

CSV format parameters​

Parameter support matrix across import methods​

The following table summarizes the support and corresponding syntax of CSV format parameters across different import methods:

ParameterDefaultStream LoadBroker LoadRoutine LoadMySQL LoadTVF
Line delimiter\nline_delimiterLINES TERMINATED BYNot supportedLINES TERMINATED BYline_delimiter
Column separator\tcolumn_separatorCOLUMNS TERMINATED BYCOLUMNS TERMINATED BYCOLUMNS TERMINATED BYcolumn_separator
EncloseNoneenclosePROPERTIES.enclosePROPERTIES.enclosePROPERTIES.encloseenclose
EscapeNoneescapePROPERTIES.escapePROPERTIES.escapePROPERTIES.escapeescape
Skip lines0skip_linesPROPERTIES.skip_linesNot supportedIGNORE LINESskip_lines
Trim double quotesfalsetrim_double_quotesNot supportedPROPERTIES.trim_double_quotesNot supportedtrim_double_quotes
Compression formatInterface-dependent or inferredcompress_typePROPERTIES.compress_typeNot supportedNot supportedcompress_type

Tip:

Parameter syntax for each import method

  1. Stream Load: parameters are specified directly via HTTP headers, for example: -H "line_delimiter:\n"
  2. Broker Load: parameters are specified via SQL statements:
    • Delimiters are specified via COLUMNS TERMINATED BY and LINES TERMINATED BY
    • Other parameters are specified via PROPERTIES, for example: PROPERTIES("compress_type"="gz")
  3. Routine Load: parameters are specified via SQL statements:
    • Delimiters are specified via COLUMNS TERMINATED BY
    • Other parameters are specified via PROPERTIES, for example: PROPERTIES("enclose"="\"")
  4. MySQL Load: parameters are specified via SQL statements:
    • Delimiters are specified via LINES TERMINATED BY and COLUMNS TERMINATED BY
    • Other parameters are specified via PROPERTIES, for example: PROPERTIES("escape"="\\")
  5. TVF: parameters are specified in the TVF statement, for example: S3("line_delimiter"="\n")

Parameter details​

Line delimiter (line_delimiter)​

  • Purpose: specifies the line break character in the file to import
  • Default: \n
  • Characteristics: supports a combination of multiple characters as the line delimiter

Typical scenarios:

  • Linux/Unix files:

    Data file:
    Zhang San, 25\n
    Li Si, 30\n

    Parameter setting:
    line_delimiter: \n (default value, can be omitted)
  • Windows files:

    Data file:
    Zhang San, 25\r\n
    Li Si, 30\r\n

    Parameter setting:
    line_delimiter: \r\n
  • Files generated by special programs:

    Data file:
    Zhang San, 25\r
    Li Si, 30\r

    Parameter setting:
    line_delimiter: \r
  • Custom multi-character delimiter:

    Data file:
    Zhang San, 25||
    Li Si, 30||

    Parameter setting:
    line_delimiter: ||

Column separator (column_separator)​

  • Purpose: specifies the column separator in the file to import
  • Default: \t (tab)
  • Characteristics:
    • Supports both visible and invisible characters
    • Supports multi-character combinations
    • Invisible characters must be represented in hexadecimal with the \x prefix
  • MySQL protocol special handling:
    • Invisible characters require an additional backslash
    • For example, Hive's \x01 must be written as \\x01 in Broker Load

Typical scenarios:

  • Common visible characters:

    Data file:
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

    Parameter setting:
    column_separator: ,
  • Tab (default):

    Data file:
    Zhang San 25 Beijing
    Li Si 30 Shanghai

    Parameter setting:
    column_separator: \t (default value, can be omitted)
  • Hive files (Stream Load):

    Data file:
    Zhang San\x0125\x01 Beijing
    Li Si\x0130\x01 Shanghai

    Parameter setting:
    column_separator: \x01
  • Hive files (Broker Load):

    Data file:
    Zhang San\x0125\x01 Beijing
    Li Si\x0130\x01 Shanghai

    Parameter setting:
    COLUMNS TERMINATED BY "\\x01"
  • Multi-character delimiter:

    Data file:
    Zhang San||25||Beijing
    Li Si||30||Shanghai

    Parameter setting:
    column_separator: ||

Enclose (enclose)​

  • Purpose: protects fields that contain special characters from being parsed incorrectly
  • Limitation: only single-byte characters are supported
  • Common characters:
    • Single quote: '
    • Double quote: "

Typical scenarios:

  • Field contains the column separator:

    Data: a,'b,c',d
    Column separator: ,
    Enclose: '
    Parsing result: 3 fields [a] [b,c] [d]
  • Field contains the line delimiter:

    Data: a,'b\nc',d
    Column separator: ,
    Enclose: '
    Parsing result: 3 fields [a] [b\nc] [d]
  • Field contains both the column separator and the line delimiter:

    Data: a,'b,c\nd,e',f
    Column separator: ,
    Enclose: '
    Parsing result: 3 fields [a] [b,c\nd,e] [f]

Escape (escape)​

  • Purpose: escapes characters in a field that are the same as the enclosing character
  • Limitation: only single-byte characters are supported. Set escape explicitly when the file uses an escape character

Typical scenarios:

  • Field contains the enclosing character:

    Data: a,'b,\'c',d
    Column separator: ,
    Enclose: '
    Escape: \
    Parsing result: 3 fields [a] [b,'c] [d]
  • Field contains multiple enclosing characters:

    Data: a,"b,\"c\"d",e
    Column separator: ,
    Enclose: "
    Escape: \
    Parsing result: 3 fields [a] [b,"c"d] [e]
  • Field contains the escape character itself:

    Data: a,'b\\c',d
    Column separator: ,
    Enclose: '
    Escape: \
    Parsing result: 3 fields [a] [b\c] [d]

Skip lines (skip_lines)​

  • Purpose: skips the first N lines of the CSV file
  • Type: integer
  • Default: 0
  • Special notes:
    • When format is csv_with_names, the system automatically skips the first line (column names) and ignores the skip_lines parameter
    • When format is csv_with_names_and_types, the system automatically skips the first two lines (column names and types) and ignores the skip_lines parameter

Typical scenarios:

  • Skip the header line:

    Data file:
    Name, Age, City
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

    Parameter setting:
    skip_lines: 1
    Result: skip the header line and import the subsequent data
  • Skip comment lines:

    Data file:
    # User information table
    # Created at: 2024-01-01
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

    Parameter setting:
    skip_lines: 2
    Result: skip the comment lines and import the subsequent data
  • Use the csv_with_names format:

    Data file:
    name,age,city
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

    Parameter setting:
    format: csv_with_names
    Result: the system automatically skips the first line of column names
  • Use the csv_with_names_and_types format:

    Data file:
    name,age,city
    string,int,string
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

    Parameter setting:
    format: csv_with_names_and_types
    Result: the system automatically skips the first two lines of column names and types

Trim double quotes (trim_double_quotes)​

  • Purpose: trims the outermost double quotes from each field in the CSV file
  • Type: boolean
  • Default: false

Typical scenarios:

  • Trim double quotes:

    Data file:
    "Zhang San","25","Beijing"
    "Li Si","30","Shanghai"

    Parameter setting:
    trim_double_quotes: true
    Result:
    Zhang San, 25, Beijing
    Li Si, 30, Shanghai

Compression format (compress_type)​

  • Purpose: specifies the compression format of the file to import

  • Type: string, case-insensitive

  • Default: Stream Load expects uncompressed input when the header is omitted. File-based readers can infer compression from the file suffix. Set compress_type explicitly for compressed Stream Load input or an ambiguous suffix.

  • Supported compression formats:

    Stream Load header valueBroker Load / TVF valueDescription
    Omit compress_typeplainUncompressed input
    bz2bz2BZIP2 compression
    deflatedeflateDEFLATE compression
    gzgzGZIP compression
    lz4 or lz4framelz4 or lz4frameLZ4 Frame compression
    lz4_blocklz4blockLZ4 Block compression
    lzolzoLZO input handled by the LZOP reader
    lzoplzopLZOP compression
    snappy_blocksnappyblockSNAPPY Block compression
    zstdzstdZstandard compression
  • Notes:

    • tar is a file packaging format, not a compression format, so .tar files are not supported
    • To use a tar-packaged file, unpack it first and then import

Examples​

This section shows the three most common operations for each import method: specifying delimiters, handling quoted data, and importing compressed files.

Stream Load​

# Specify delimiters
curl --location-trusted -u "<username>" \
-H "column_separator:," \
-H "line_delimiter:\n" \
-T example.csv \
"<endpoint>/api/test_db/test_table/_stream_load"

# Handle quoted data
curl --location-trusted -u "<username>" \
-H "column_separator:," \
-H "enclose:\"" \
-H "escape:\\" \
-T example.csv \
"<endpoint>/api/test_db/test_table/_stream_load"

# Import a compressed file
curl --location-trusted -u "<username>" \
-H "compress_type:gz" \
-T example.csv.gz \
"<endpoint>/api/test_db/test_table/_stream_load"

Broker Load​

-- Specify delimiters
LOAD LABEL test_db.test_label
(
DATA INFILE("s3://bucket/example.csv")
INTO TABLE test_table
COLUMNS TERMINATED BY ","
LINES TERMINATED BY "\n"
)
WITH S3
(
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

-- Handle quoted data
LOAD LABEL test_db.test_label
(
DATA INFILE("s3://bucket/example.csv")
INTO TABLE test_table
PROPERTIES
(
"enclose" = "\"",
"escape" = "\\"
)
)
WITH S3
(
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

-- Import a compressed file
LOAD LABEL test_db.test_label
(
DATA INFILE("s3://bucket/example.csv.gz")
INTO TABLE test_table
PROPERTIES
(
"compress_type" = "gz"
)
)
WITH S3
(
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

Routine Load​

-- Specify delimiters
CREATE ROUTINE LOAD test_db.test_job ON test_table
COLUMNS TERMINATED BY ","
FROM KAFKA
(
"kafka_broker_list" = "<broker>:<port>",
"kafka_topic" = "<topic>",
"property.group.id" = "<consumer-group>"
);

-- Handle quoted data
CREATE ROUTINE LOAD test_db.test_job ON test_table
COLUMNS TERMINATED BY ","
PROPERTIES
(
"enclose" = "\"",
"escape" = "\\"
)
FROM KAFKA
(
"kafka_broker_list" = "<broker>:<port>",
"kafka_topic" = "<topic>",
"property.group.id" = "<consumer-group>"
);

MySQL Load​

-- Specify delimiters
LOAD DATA LOCAL INFILE 'example.csv'
INTO TABLE test_table
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n';

-- Handle quoted data
LOAD DATA LOCAL INFILE 'example.csv'
INTO TABLE test_table
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
PROPERTIES
(
"enclose" = "\"",
"escape" = "\\"
);

-- Skip the header
LOAD DATA LOCAL INFILE 'example.csv'
INTO TABLE test_table
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

TVF​

-- Specify delimiters
INSERT INTO test_table
SELECT *
FROM S3
(
"uri" = "s3://bucket/example.csv",
"format" = "csv",
"column_separator" = ",",
"line_delimiter" = "\n",
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

-- Handle quoted data
INSERT INTO test_table
SELECT *
FROM S3
(
"uri" = "s3://bucket/example.csv",
"format" = "csv",
"column_separator" = ",",
"enclose" = "\"",
"escape" = "\\",
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

-- Import a compressed file
INSERT INTO test_table
SELECT *
FROM S3
(
"uri" = "s3://bucket/example.csv.gz",
"format" = "csv",
"compress_type" = "gz",
"s3.endpoint" = "https://<s3-endpoint>",
"s3.region" = "<region>",
"s3.access_key" = "<access-key>",
"s3.secret_key" = "<secret-key>"
);

FAQ​

Q1: Hive's default \x01 column separator does not work in Broker Load. Why?

Under the MySQL protocol, invisible characters require an additional backslash and must be written as \\x01, for example COLUMNS TERMINATED BY "\\x01". When specified via the HTTP header in Stream Load, \x01 is sufficient.

Q2: Does Routine Load support a custom line delimiter?

No. Each message consumed by Routine Load from Kafka naturally corresponds to a single line, so the line_delimiter parameter is neither needed nor supported.

Q3: The first line of the CSV file is the header. How do I skip it during import?

  • Stream Load / Broker Load / TVF: use skip_lines=1
  • MySQL Load: use IGNORE 1 LINES
  • If the file also follows the name1,name2,... header convention, set format to csv_with_names and the system automatically skips the first line. Set it to csv_with_names_and_types to automatically skip the first two lines (column names + types)

Q4: Can I import a .tar or .tar.gz file directly?

No. tar is a packaging format, not a compression format. VeloDB Cloud only supports the compression formats listed under compress_type. Unpack .tar or .tar.gz files first and then import them.

Q5: A field contains both the column separator and a line break. How should I handle it?

Set enclose for that field. For example, with single quotes as the enclosing character, a,'b,c\nd,e',f is correctly parsed into 3 fields [a], [b,c\nd,e], [f] when the column separator is , and the enclose is '. If the field also contains the enclosing character itself, combine it with escape.

Q6: How do I remove the outermost double quotes when importing fields wrapped in double quotes?

Set trim_double_quotes to true, and VeloDB Cloud automatically trims the outermost double quotes from each field after parsing. This parameter is supported in Stream Load, Routine Load, and TVF, but not in Broker Load or MySQL Load.

Common errors​

  • Authentication or connection failure: Check the generated warehouse endpoint, TLS requirements, SQL user permissions, and network access. For remote files, also check source credentials and reachability.
  • Filtered rows or parsing errors: Check the input format, delimiters, field mappings, and target column types. Inspect the returned load error before retrying. Raising the filter tolerance can discard data.
  • Unexpected duplicate rows: These examples use independent loads. Check the table model and existing rows before rerunning a sample.

See also​