目錄
正文
Command Description
quit Use quit or exit to leave the interactive shell.
set key=value Use this to set value of particular configuration variable. One thing to note here is that if you misspell the variable name, cli will not show an error.
set This will print a list of configuration variables that are overridden by user or hive.
set -v This will print all hadoop and hive configuration variables.
add FILE [file] [file]* Adds a file to the list of resources
add jar jarname
list FILE list all the files added to the distributed cache
list FILE [file]* Check if given resources are already added to distributed cache
! [cmd] Executes a shell command from the hive shell
dfs [dfs cmd] Executes a dfs command from the hive shell
[query] Executes a hive query and prints results to standard out
source FILE Used to execute a script file inside the CLI.
hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e query-string>] [-S]
說明:
1、-i 從文件初始化 HQL
2、-e 從命令行執(zhí)行指定的 HQL
3、-f 執(zhí)行 HQL 腳本
4、-v 輸出執(zhí)行的 HQL 語句到控制臺
5、-p connect to Hive Server on port number
6、-hiveconf x=y(Use this to set hive/hadoop configuration variables)
7、-S:表示以不打印日志的形式執(zhí)行命名操作
[hadoop@hadoop3 ~]$ hive -e "select * from cookie.cookie1;"
編寫hive.sql文件
運行編寫的文件
從配置文件啟動 hive,并加載配置文件當中的配置參數(shù)
https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties
開發(fā) Hive 應用時,不可避免地需要設定 Hive 的參數(shù)。設定 Hive 的參數(shù)可以調優(yōu) HQL 代碼 的執(zhí)行效率,或幫助定位問題。然而實踐中經(jīng)常遇到的一個問題是,為什么設定的參數(shù)沒有 起作用?這通常是錯誤的設定方式導致的
對于一般參數(shù),有以下三種設定方式:
1、配置文件 (全局有效)
2、命令行參數(shù)(對 hive 啟動實例有效)
3、參數(shù)聲明 (對 hive 的連接 session 有效)
Hive 的配置文件包括:
A. 用戶自定義配置文件:$HIVE_CONF_DIR/hive-site.xml
B. 默認配置文件:$HIVE_CONF_DIR/hive-default.xml
用戶自定義配置會覆蓋默認配置。
另外,Hive 也會讀入 Hadoop 的配置,因為 Hive 是作為 Hadoop 的客戶端啟動的,Hive 的配 置會覆蓋 Hadoop 的配置。
配置文件的設定對本機啟動的所有 Hive 進程都有效。
啟動 Hive(客戶端或 Server 方式)時,可以在命令行添加-hiveconf param=value 來設定參數(shù),例如:
這一設定對本次啟動的 session(對于 server 方式啟動,則是所有請求的 session)有效。
可以在 HQL 中使用 SET 關鍵字設定參數(shù),例如:
這一設定的作用域也是 session 級的。
set hive.exec.reducers.bytes.per.reducer= 每個 reduce task 的平均負載數(shù)據(jù)量 Hive 會估算總數(shù)據(jù)量,然后用該值除以上述參數(shù)值,就能得出需要運行的 reduceTask 數(shù)
set hive.exec.reducers.max= 設置 reduce task 數(shù)量的上限
set mapreduce.job.reduces= 指定固定的 reduce task 數(shù)量
但是,這個參數(shù)在必要時<業(yè)務邏輯決定只能用一個 reduce task> hive 會忽略,比如在設置 了 set mapreduce.job.reduces = 3,但是 HQL 語句當中使用了 order by 的話,那么就會忽略該參數(shù)的設置。
上述三種設定方式的優(yōu)先級依次遞增。即參數(shù)聲明覆蓋命令行參數(shù),命令行參數(shù)覆蓋配置 文件設定。注意某些系統(tǒng)級的參數(shù),例如 log4j 相關的設定,必須用前兩種方式設定,因為 那些參數(shù)的讀取在 session 建立以前已經(jīng)完成了。