Help Center/ AI DataLake/ Spark reference/ Export Query Results
Updated on 2026-11-06 GMT+08:00

Export Query Results

Function

INSERT OVERWRITE DIRECTORY is used to write query results directly to a specified directory. It supports storage in CSV, Parquet, ORC, JSON, and Avro formats.

Syntax

INSERT OVERWRITE DIRECTORY path
   USING file_format
   [OPTIONS(key1=value1)]
   select_statement; 

Keywords

  • USING: Specifies the storage format.
  • OPTIONS: A list of properties for the export, optional.

Parameters

Table 1 INSERT OVERWRITE DIRECTORY parameter descriptions

Parameter

Description

path

The OBS path to which the query results will be written.

file_format

The file format for writing. Supports CSV, Parquet, ORC, JSON, and Avro formats.

Precautions

  • By configuring the spark.sql.shuffle.partitions parameter, the number of files inserted into an OBS bucket for non-managed tables can be set. Additionally, to avoid data skew, distribute by rand() can be added after the INSERT statement to increase the concurrency of the processing job. For example:
    insert overwrite directory 'obs://bucket/dir' using csv select * from table_source distribute by cast(rand() * N as int);
  • When the configuration is OPTIONS('DELIMITER'=','), the delimiter can be specified. The default value is ,.

    For CSV data, the following delimiters are supported:

    • Tab character, e.g., 'DELIMITER'='\t'.
    • Specifying a delimiter using a Unicode encoding, e.g., 'DELIMITER'='\u0001'.
    • Single quote (`'`), which must be enclosed in double quotes (" "), e.g., 'DELIMITER'= "".

Examples

INSERT OVERWRITE DIRECTORY 'obs://bucket/dir'
  USING csv
  OPTIONS(key1=value1)
  select * from db1.tb1;