插入具有 Hive 格式的覆盖目录INSERT OVERWRITE DIRECTORY with Hive format

INSERT OVERWRITE DIRECTORYWith hive 格式使用 hive 将目录中的现有数据覆盖为新值 SerDeThe INSERT OVERWRITE DIRECTORY with Hive format overwrites the existing data in the directory with the new values using Hive SerDe. 必须启用 Hive 支持才能使用此命令。Hive support must be enabled to use this command. 插入的行可通过值表达式或查询的结果指定。The inserted rows can be specified by value expressions or result from 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

    指定目标目录。Specifies the destination directory. LOCAL关键字用于指定目录位于本地文件系统中。The LOCAL keyword is used to specify that the directory is on the local file system.

  • row_formatrow_format

    指定此插入的行格式。Specifies 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

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

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

    指定要插入的值。Specifies 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. 它可以采用以下格式之一:It can be in 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;