-
Hive的Lode語句的使用
查看全部 -
hive的表生成函數
explode
select explode(map(1,'tom',2,'marry',3,'mike'));
1? ?tom
2? ?marry
3? ?mike
查看全部 -
hive的收集函數
size(map(<key,value>,<key,value>))
select size(map(1,'tom',2,'mary'))
2
hive的轉換函數
cast
select cast(1 as bigint);
1
select cast(1 as float);
1.0
select cast('2015-04-10' as date);
2015-04-10
查看全部 -
hive字符函數
lpad:左填充
rpad:右填充
select lpad('abcd',10,'*')
******abcd
select rpad('abcd',10,'*')
abcd******
查看全部 -
hive內置函數
查看全部 -
hive中order by使用字段序號排序配置參數
set hive.groupby.orderby.position.alias=true;
查看全部 -
hive的HQL語言區分字符串的大小寫
模糊查詢:查詢名字含有下劃線的員工
select empno,ename,sal from emp where ename like '%\\_%'
查看全部 -
簡單查詢使用 Fetch Task功能 不生成MapReduce任務
配置方式
set hive.fetch.task.conversion=more;
hive --hiveconf hive.fetch.task.conversion=more
修改hive-site.xml文件
<configuration>????<property> <name>hive.fetch.task.conversion</name> <value>more</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.56.101:3306/hive</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>password</value> </property>????<property>????????<name>hive.hwi.listen.host</name>????????<value>0.0.0.0</value>????????<description>This?is?the?host?address?the?Hive?Web?Interface?will?listen?on</description>????</property>?????????<property>????????<name>hive.hwi.listen.port</name>????????<value>9999</value>????????<description>This?is?the?port?the?Hive?Web?Interface?will?listen?on</description>????</property>?????????<property>????????<name>hive.hwi.war.file</name>????????<value>${HIVE_HOME}/lib/hive-hwi-<version>.war</value>????????<description>This?is?the?WAR?file?with?the?jsp?content?for?Hive?Web?Interface</description>????</property> </configuration>
<configuration>
? ? <property>
<name>hive.fetch.task.conversion</name>
<value>more</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.56.101:3306/hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>password</value>
</property>
? ? <property>
? ? ? ? <name>hive.hwi.listen.host</name>
? ? ? ? <value>0.0.0.0</value>
? ? ? ? <description>This is the host address the Hive Web Interface will listen on</description>
? ? </property>
? ? ?
? ? <property>
? ? ? ? <name>hive.hwi.listen.port</name>
? ? ? ? <value>9999</value>
? ? ? ? <description>This is the port the Hive Web Interface will listen on</description>
? ? </property>
? ? ?
? ? <property>
? ? ? ? <name>hive.hwi.war.file</name>
? ? ? ? <value>${HIVE_HOME}/lib/hive-hwi-<version>.war</value>
? ? ? ? <description>This is the WAR file with the jsp content for Hive Web Interface</description>
? ? </property>
</configuration>
查看全部 -
sqoop進行數據導入
使用sqoop導入oracle數據到hdfs中
./sqoop import --connect? jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger --table emp --columns 'empno,ename,job,sal,deptno' -m 1 --target-dir '/sqoop/emp'
使用sqoop導入Oracle數據到hive中
./sqoop import --hive-import --connect?jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger --table emp -m 1 --columns 'empno,ename,job,sal,deptno'
使用sqoop導入oracle數據到hive中,并指定表名
./sqoop import --hive-import --connect?jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger --table emp -m 1 --columns 'empno,ename,job,sal,deptno' --hive-table emp1
使用sqoop導入oracle數據到hive中,并使用where條件
./sqoop import --hive-import --connect?jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger --table emp -m 1 --columns 'empno,ename,job,sal,deptno' --hive-table emp2 --where 'deptno=10'
使用sqoop導入oracle數據到hive中,并使用查詢語句
./sqoop import --hive-import --connect?jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger? -m 1 --query 'select * from emp where sal<2000 and $CONDITIONS' --hive-table emp3 --target-dir '/sqoop/emp3'
使用sqoop將hive中的數據導出到oracle中
./sqoop export?--connect?jdbc:oracle:thin:@192.168.56.101:1521:orcl --username scott --password tiger? -m 1 --table myemp --export-dir 'hdfs文件路徑'
查看全部 -
hive數據的導入
適用load語句
語法
LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE]
INTO TABLE tablename [PARTITION (partcol1=val1,partcol2=val2 ...)]
其中
[LOCAL] 表示從操作系統目錄上選取文件導入,如果不寫從hdfs目錄上選取文件導入
INPATH表示導入文件的路徑
[OVERWRITE]表示是否覆蓋表中記錄
[PARTITION]表示指明導入的分區名字和條件
將student01.txt數據導入到t3
load data local inpath '/root/data/student01.txt' into table t3;
將/root/data下的所有數據文件導入t3表中,并且覆蓋原來的數據
load data local inpath '/root/data/' overwrite into table t3;
將hdfs中/input/student01.txt導入到t3
load data inpath '/input/student01.txt' overwrite into table t3;
導入分區表
load data local inpath '/root/data/data1.txt' into table
partition_table partition (gender='M')
load data local inpath '/root/data/data2.txt' into table
partition_table partition (gender='F')
查看全部 -
本地數據導入到表格
HDFS數據導入到表格
本地數據導入到分區表格
查看全部 -
,需要實現evaluate函數,evaluate函數支持重載 創建好自定義函數后,我們需要把程序打成jar包,放到linux的hive服務器上
查看全部 -
子查詢的空值問題:使用no in的時候括號里面返回的值不能為null;但是in是可以返回為null
查看全部 -
HIVE子查詢 hive只支持from和where子查詢 select e.ename from emp e where e.deptno in (select e.deptno from dept d where d.dname='SALES' or d.dname='ACCOUNTING');
查看全部 -
自連接的核心:通過表的別名將同一張表視為多張表
查看全部
舉報