1. 程式人生 > >HIVE---DML操作

HIVE---DML操作

資料載入

方式一:從檔案載入資料

LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]

指定LOCAL:

  1. 指HiveServer2例項上的本地路徑;
  2. 執行資料拷貝copy動作;

不指定LOCAL:

  1. 最終使用完整的URI路徑,scheme沒指定時使用hadoop預設配置fs.default.name; 相對路徑轉為絕對路徑,基礎路徑為/user/;
  2. 執行資料移動
    move動作;

方式二:從SELECT語句載入資料

INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) [IF NOT EXISTS]] select_statement1 FROM from_statement;
INSERT INTO TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement;

區別: INSERT OVERWRITE 進行資料覆蓋;INSERT INTO 進行資料追加;

方式三:顯式插入資料

INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2] ...)] VALUES values_row [, values_row ...]

注意: 不支援複雜資料型別(array, map, struct, union)

資料更新

UPDATE tablename SET column = value [, column = value ...] [WHERE expression]

注意:列值可以是算術表示式、UDF等等,但是不支援子查詢;

The value assigned must be an expression that Hive supports in the select clause. Thus arithmetic operators, UDFs, casts, literals, etc. are supported. Subqueries are not supported.

資料刪除

DELETE FROM tablename [WHERE expression]

參考:

  1. 官網:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Delete;