INSERT OVERWRITE DIRECTORY with Hive formatINSERT OVERWRITE DIRECTORY with Hive format

通过 Hive SerDe,使用新值覆盖目录中的现有数据。Overwrites the existing data in the directory with the new values using Hive SerDe. 必须启用 Hive 支持才能使用此命令。Hive support must be enabled to use this command. 通过值表达式或查询的结果指定插入的行。You specify the inserted rows by value expressions or the result of a query.

语法Syntax

INSERT OVERWRITE [ LOCAL ] DIRECTORY directory_path
    [ ROW FORMAT row_format ] [ STORED AS file_format ]
    { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query }

参数Parameters

  • directory_pathdirectory_path

    目标目录。The destination directory. LOCAL 关键字指定此目录位于本地文件系统上。The LOCAL keyword specifies that the directory is on the local file system.

  • row_formatrow_format

    此插入的行格式。The row format for this insert. 有效选项是 SERDE 子句和 DELIMITED 子句。Valid options are SERDE clause and DELIMITED clause. SERDE 子句可用于为此插入指定自定义 SerDeSERDE clause can be used to specify a custom SerDe for this insert. 或者,可以使用 DELIMITED 子句来指定原生 SerDe,并指明分隔符、转义字符和空字符等。Alternatively, DELIMITED clause can be used to specify the native SerDe and state the delimiter, escape character, null character, and so on.

  • file_formatfile_format

    此插入的文件格式。The file format for this insert. 有效选项为 TEXTFILESEQUENCEFILERCFILEORCPARQUETAVROValid options are TEXTFILE, SEQUENCEFILE, RCFILE, ORC, PARQUET, and AVRO. 还可以使用 INPUTFORMATOUTPUTFORMAT 指定你自己的输入和输出格式。You can also specify your own input and output format using INPUTFORMAT and OUTPUTFORMAT. ROW FORMAT SERDE 只能与 TEXTFILESEQUENCEFILERCFILE 一起使用,而 ROW FORMAT DELIMITED 只能与 TEXTFILE 一起使用。ROW FORMAT SERDE can only be used with TEXTFILE, SEQUENCEFILE, or RCFILE, while ROW FORMAT DELIMITED can only be used with TEXTFILE.

  • VALUES ( { value | NULL } [ , … ] ) [ , ( … ) ]VALUES ( { value | NULL } [ , … ] ) [ , ( … ) ]

    要插入的值。The values to be inserted. 可以插入显式指定的值或 NULL。Either an explicitly specified value or a NULL can be inserted. 必须使用逗号分隔子句中的每个值。A comma must be used to separate each value in the clause. 可以指定多个值集以插入多行。More than one set of values can be specified to insert multiple rows.

  • 查询query

    生成要插入的行的查询。A query that produces the rows to be inserted. 可采用以下格式之一:One of following formats:

    • SELECT 语句A SELECT statement
    • TABLE 语句A TABLE statement
    • FROM 语句A FROM statement

示例Examples

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination'
    STORED AS orc
    SELECT * FROM test_table;

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination'
    ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
    SELECT * FROM test_table;