国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

ps做網(wǎng)站登陸界面建站公司

ps做網(wǎng)站登陸界面,建站公司,網(wǎng)站流量超了,外貿(mào)seo網(wǎng)站推廣公司一Hive 庫(kù)的基本操作 1.1 建庫(kù) 1.默認(rèn)路徑是/user/hive/warehouse 例如 我輸入命令 create database text1 則text1出現(xiàn)在 warehouse目錄下 2.指定位置創(chuàng)建數(shù)據(jù)庫(kù) create database text2 location /bigdata29/bigdata29db 后面的路徑是hdfs的路徑 3.最終寫法 加上if n…

一Hive 庫(kù)的基本操作

1.1 建庫(kù)

1.默認(rèn)路徑是/user/hive/warehouse

例如 我輸入命令 create database text1

則text1出現(xiàn)在?warehouse目錄下

?2.指定位置創(chuàng)建數(shù)據(jù)庫(kù)

create database text2 location '/bigdata29/bigdata29db'

后面的路徑是hdfs的路徑
?

?3.最終寫法

加上if not exists 可以判斷該數(shù)據(jù)庫(kù)存不存在

create database if not exists bigdata29_test1 location '/bigdata29/huangdadadb';

1.2 修改數(shù)據(jù)庫(kù)

1.一般創(chuàng)建好的數(shù)據(jù)庫(kù)都不會(huì)去修改數(shù)據(jù)庫(kù),如果要修改數(shù)據(jù)庫(kù)也是修改創(chuàng)建的時(shí)間

alter database dept set dbproperties('createtime'='20220531');

1.3 數(shù)據(jù)庫(kù)詳細(xì)信息

1.3.1 顯示數(shù)據(jù)庫(kù)

1.show databases;

1.3.2?可以通過(guò)like進(jìn)行過(guò)濾

show databases like 't*';

1.3.3 查看詳情

desc database 數(shù)據(jù)庫(kù)名;

1.3.4 切換數(shù)據(jù)庫(kù)

use 數(shù)據(jù)庫(kù)名;

1.3.5 刪除數(shù)據(jù)庫(kù)

drop database if exists 數(shù)據(jù)庫(kù)名;

如果數(shù)據(jù)庫(kù)不為空,使用cascade命令進(jìn)行強(qiáng)制刪除。報(bào)錯(cuò)信息如下FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. InvalidOperationException(message:Database db_hive is not empty. One or more tables exist.)

drop database if exists 數(shù)據(jù)庫(kù)名?cascade;

二 Hive的數(shù)據(jù)類型

2.1 基本數(shù)據(jù)類型

?2.2 復(fù)雜數(shù)據(jù)類型

?三 Hive 表的基本操作

3.1 默認(rèn)建表

1.簡(jiǎn)單數(shù)據(jù)

create table IF NOT EXISTS 表名
(

數(shù)據(jù)名 數(shù)據(jù)類型
? ? id bigint,??
? ? name string,
? ? age int,
? ? gender string,
? ? clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';? --> 以逗號(hào)做為分隔符

2.復(fù)雜數(shù)據(jù)

create table IF NOT EXISTS t_person(
name string,
friends array<string>,
children map<string,int>,
address struct<street:string ,city:string>
)
row format delimited fields terminated by ',' -- 列與列之間的分隔符
collection items terminated by '_' -- 元素與元素之間分隔符
map keys terminated by ':' -- Map數(shù)據(jù)類型鍵與值之間的分隔符
lines terminated by '\n'; ?-- 行與行之間的換行符

3.2 指定存儲(chǔ)格式

3.2.1 相關(guān)文件格式

平時(shí)學(xué)習(xí)用TextFile,工作使用orc

3.2.2建表語(yǔ)法

create table IF NOT EXISTS 表名
(
? ? id bigint,
? ? name string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS ORC -->存儲(chǔ)文件的格式

3.3 查詢結(jié)果作為表

1.表沒有的情況下

create table 表名 as 查詢語(yǔ)句;

2.有表的情況下 添加數(shù)據(jù)

insert into 表名 查詢語(yǔ)句;

?3.4 模仿其他表的結(jié)構(gòu)

create table 表名 like 已經(jīng)存在的表名;

3.5 顯示表

show tables;
show tables like 'u*';
desc t_person;
desc formatted students; // 更加詳細(xì)

3.6 加載數(shù)據(jù)

3.6.1 使用hdfs的put或者cp命令

1.將linux文件使用 put的命令放在?hive表對(duì)應(yīng)的HDFS目錄下

例如:

hadoop fs -put ./students.csv /bigdata29/bigdata29db/students/

?2.如果hdfs中 有數(shù)據(jù)的文件,那么將這個(gè)文件復(fù)制一份到 hive表對(duì)應(yīng)的hdfs目錄下

例如:

hadoop fs -cp /bigdata29/students.csv?/bigdata29/bigdata29db/students/

3.6.2 location 或者是load data

1.location 這個(gè)是創(chuàng)建表的時(shí)候后面加的數(shù)據(jù)。(先有數(shù)據(jù)后有表)

例如?create table IF NOT EXISTS students3
(
? ? id bigint,
? ? name string,
? ? age int,
? ? gender string,
? ? clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/bigdata29/shuju/';

主要保證data目錄下只能有一個(gè)數(shù)據(jù)?

這個(gè)表存儲(chǔ)在shuju目錄下

?2.location 這個(gè)是先創(chuàng)建表的時(shí)候后面添加數(shù)據(jù)。(先有表后有數(shù)據(jù))

create table IF NOT EXISTS students4(id bigint,name string,age int,gender string,clazz string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/bigdata29/aaa/bbb/ccc';

先在/bigdata29/aaa/bbb/ccc這個(gè)目錄下創(chuàng)建一個(gè)表 再將數(shù)據(jù)放到這個(gè)目錄下

?3.load data 這個(gè)是移動(dòng)hdfs中文件

先創(chuàng)建一個(gè)新表 不加location的話默認(rèn)在創(chuàng)建數(shù)據(jù)庫(kù)的那個(gè)目錄下

create table IF NOT EXISTS students5
(
? ? id bigint,
? ? name string,
? ? age int,
? ? gender string,
? ? clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

再輸入?load data inpath '/bigdata29/data/students.csv' into table students5;即可

但是bigdata29/data/students.csv文件沒有了

4.load data local 是上傳Linux的文件

create table IF NOT EXISTS students6
(
? ? id bigint,
? ? name string,
? ? age int,
? ? gender string,
? ? clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

再輸入 load data local inpath '/usr/local/soft/bigdata29/students.csv'? into table students5;

這里的文件不會(huì)消失

into 改成 overwrite就是覆蓋

3.6.2 查詢語(yǔ)句加載數(shù)據(jù)

1.表沒有的情況下

create table 表名 as 查詢語(yǔ)句;

2.有表的情況下 添加數(shù)據(jù)

insert into 表名 查詢語(yǔ)句;

3.6.3普通的插入

insert into 表名 values ('數(shù)據(jù)');

3.7 修改表

3.7.1 添加列

alter table 表名 add columns (數(shù)據(jù)名 數(shù)據(jù)類型);

3.7.2修改列名或者數(shù)據(jù)類型

alter table 表名 change 之前的數(shù)據(jù)名 更改過(guò)后的數(shù)據(jù)名?數(shù)據(jù)類型;

四 內(nèi)外部表

4.1內(nèi)部表

1.我們默認(rèn)創(chuàng)建的就是內(nèi)部表

2.當(dāng)設(shè)置表路徑的時(shí)候,如果直接指向一個(gè)已有的路徑,可以直接去使用文件夾中的數(shù)據(jù)

當(dāng)load數(shù)據(jù)的時(shí)候,就會(huì)將數(shù)據(jù)文件存放到表對(duì)應(yīng)的文件夾中

而且數(shù)據(jù)一旦被load,就不能被修改

我們查詢數(shù)據(jù)也是查詢文件中的文件,這些數(shù)據(jù)最終都會(huì)存放到HDFS

當(dāng)我們刪除表的時(shí)候,表對(duì)應(yīng)的文件夾會(huì)被刪除,同時(shí)數(shù)據(jù)也會(huì)被刪除

4.2外部表

1.創(chuàng)建表的時(shí)候加個(gè)關(guān)鍵字

create external table 表名

2.一般用的外部表比較多

3.外部表因?yàn)槭侵付ㄆ渌膆dfs路徑的數(shù)據(jù)加載到表中來(lái),所以hive會(huì)認(rèn)為自己不完全獨(dú)占這份數(shù)據(jù)

4.刪除hive表的時(shí)候,數(shù)據(jù)仍然保存在hdfs中,不會(huì)刪除。

五 導(dǎo)出數(shù)據(jù)

5.1 放入Linux中

1.insert overwrite local directory 'Linux路徑' 查詢語(yǔ)句;

例如:?

insert overwrite local directory '/usr/local/soft/bigdata29/person_data' select * from t_person;

2.按照指定的方式將數(shù)據(jù)輸出到本地

insert overwrite local directory '/usr/local/soft/shujia/person'?
ROW FORMAT DELIMITED fields terminated by ','?
collection items terminated by '-'?
map keys terminated by ':'?
lines terminated by '\n'?
select * from t_person;

5.2? 放入hdfs中

1.insert overwrite directory 'hdfs路徑' 查詢語(yǔ)句;

2.export table t_person to 'hdfs路徑';,但是這個(gè)路徑提前存在

六 Hive的分區(qū)

6.1靜態(tài)分區(qū) SP

借助于物理的文件夾分區(qū),實(shí)現(xiàn)快速檢索的目的。

一般對(duì)于查詢比較頻繁的列設(shè)置為分區(qū)列。

分區(qū)查詢的時(shí)候直接把對(duì)應(yīng)分區(qū)中所有數(shù)據(jù)放到對(duì)應(yīng)的文件夾中。

6.1.1 單分區(qū)

1.創(chuàng)建表語(yǔ)法:

CREATE TABLE IF NOT EXISTS t_student (
sno int,
sname string
) partitioned by(grade int)
row format delimited fields terminated by ',';

2.加載數(shù)據(jù)

先數(shù)據(jù)在Linux創(chuàng)建文件,再上傳到hdfs的表目錄下

load data local inpath '/usr/local/soft/bigdata29/grade2.txt' into table t_student partition(grade=2);

3.加載數(shù)據(jù)的時(shí)候一定要把分區(qū)要確定好,不能不是這個(gè)分區(qū)的內(nèi)容加入到這個(gè)分區(qū)里面

6.1.2 多分區(qū)

1.創(chuàng)建表語(yǔ)法

CREATE TABLE IF NOT EXISTS t_teacher (
tno int,
tname string
) partitioned by(grade int,clazz int)
row format delimited fields terminated by ',';

2.加載數(shù)據(jù)

在Linux創(chuàng)建數(shù)據(jù)文件,再上傳到hdfs的表目錄下

load data local inpath '/usr/local/soft/bigdata29/grade22.txt' into table t_teacher partition(grade=2,clazz=2);

3.分區(qū)的字段不能少于2個(gè),比如說(shuō)男生女生就沒必要分區(qū)了

6.1.3 查看分區(qū)

show partitions 表名r;

6.1.4 添加分區(qū)

?alter table 表名 add partition (字段名);

alter table 表名 add partition (字段名) location '指定數(shù)據(jù)文件的路徑';

例如:

alter table t_teacher add partition (grade=3,clazz=1) location '/user/hive/warehouse/bigdata29.db/t_teacher/grade=3/clazz=1';

6.1.5 刪除分區(qū)

alter table 表名 drop partition (字段名);

6.2 動(dòng)態(tài)分區(qū)

  • 動(dòng)態(tài)分區(qū)(DP)dynamic partition

  • 靜態(tài)分區(qū)與動(dòng)態(tài)分區(qū)的主要區(qū)別在于靜態(tài)分區(qū)是手動(dòng)指定,而動(dòng)態(tài)分區(qū)是通過(guò)數(shù)據(jù)來(lái)進(jìn)行判斷。

  • 詳細(xì)來(lái)說(shuō),靜態(tài)分區(qū)的列是在編譯時(shí)期通過(guò)用戶傳遞來(lái)決定的;動(dòng)態(tài)分區(qū)只有在SQL執(zhí)行時(shí)才能決定。

6.2.1 開啟動(dòng)態(tài)分區(qū)

1.先創(chuàng)建分區(qū)表

CREATE TABLE IF NOT EXISTS t_student_d (
sno int,
sname string
) partitioned by (grade int,clazz int)
row format delimited fields terminated by ',';

2.創(chuàng)建原始數(shù)據(jù)表(外部)

CREATE EXTERNAL TABLE IF NOT EXISTS t_student_e (
sno int,
sname string,
grade int,
clazz int
)?
row format delimited fields terminated by ','
location "/bigdata29/teachers";

3.在本地創(chuàng)建文件 然后將數(shù)據(jù)導(dǎo)入t_student_e表中

4.insert overwrite table t_student_d partition (grade,clazz) select * from t_student_e;

6.3 分區(qū)的優(yōu)缺點(diǎn)

1.優(yōu)點(diǎn):

避免全盤掃描,加快查詢速度

2.缺點(diǎn)

可能產(chǎn)生大量小文件

數(shù)據(jù)傾斜問題

七 Hive分桶

7.1 概念

數(shù)據(jù)分桶的適用場(chǎng)景: 分區(qū)提供了一個(gè)隔離數(shù)據(jù)和優(yōu)化查詢的便利方式,不過(guò)并非所有的數(shù)據(jù)都可形成合理的分區(qū),尤其是需要確定合適大小的分區(qū)劃分方式 不合理的數(shù)據(jù)分區(qū)劃分方式可能導(dǎo)致有的分區(qū)數(shù)據(jù)過(guò)多,而某些分區(qū)沒有什么數(shù)據(jù)的尷尬情況 分桶是將數(shù)據(jù)集分解為更容易管理的若干部分的另一種技術(shù)。 分桶就是將數(shù)據(jù)按照字段進(jìn)行劃分,可以將數(shù)據(jù)按照字段劃分到多個(gè)文件當(dāng)中去。(都各不相同)

7.2 原理

Hive采用對(duì)列值哈希,然后除以桶的個(gè)數(shù)求余的方式?jīng)Q定該條記錄存放在哪個(gè)桶當(dāng)中。

  • bucket num = hash_function(bucketing_column) mod num_buckets

  • 列的值做哈希取余 決定數(shù)據(jù)應(yīng)該存儲(chǔ)到哪個(gè)桶

7.3 作用

方便抽樣

使取樣(sampling)更高效。在處理大規(guī)模數(shù)據(jù)集時(shí),在開發(fā)和修改查詢的階段,如果能在數(shù)據(jù)集的一小部分?jǐn)?shù)據(jù)上試運(yùn)行查詢,會(huì)帶來(lái)很多方便

提高join查詢效率

獲得更高的查詢處理效率。桶為表加上了額外的結(jié)構(gòu),Hive 在處理有些查詢時(shí)能利用這個(gè)結(jié)構(gòu)。具體而言,連接兩個(gè)在(包含連接列的)相同列上劃分了桶的表,可以使用 Map 端連接 (Map-side join)高效的實(shí)現(xiàn)。比如JOIN操作。對(duì)于JOIN操作兩個(gè)表有一個(gè)相同的列,如果對(duì)這兩個(gè)表都進(jìn)行了桶操作。那么將保存相同列值的桶進(jìn)行JOIN操作就可以,可以大大較少JOIN的數(shù)據(jù)量。

7.4 實(shí)例

1.先創(chuàng)建數(shù)據(jù)

2.創(chuàng)建普通的表

create table person
(
id int,
name string,
age int
)
row format delimited
fields terminated by ',';

3.加載數(shù)據(jù)到普通的表中

4.創(chuàng)建分桶表

create table psn_bucket
(
id int,
name string,
age int
)
clustered by(age) into 4 buckets
row format delimited fields terminated by ',';

這里使用clustered by對(duì)表中的列名分桶,后面的4表示分成4個(gè)

5.將數(shù)據(jù)加載到分桶表中

insert into psn_bucket select * from person;

后面是普通表的查詢語(yǔ)句

7.5 分桶于分區(qū)的區(qū)別

1.分區(qū)用的是partitioned by 關(guān)鍵字聲明的,分桶是clustered by 和into?buckets 分成幾個(gè)桶的關(guān)鍵字聲明的

2.分區(qū)的在hdfs上面表示的是一個(gè)文件夾,分桶表示的是一個(gè)文件

3.分區(qū)的依據(jù)是通過(guò)指定分區(qū)的字段的值來(lái)進(jìn)行分區(qū)的,分桶是指定分桶的字段的哈希值除以桶的個(gè)數(shù)取余來(lái)進(jìn)行分桶的

八 Idea連接Hive

package com.shujia.jcbc;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;public class JcbcHive {public static void main(String[] args) throws Exception {//加載驅(qū)動(dòng)Class.forName("org.apache.hive.jdbc.HiveDriver");//創(chuàng)建與hive的連接對(duì)象Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/bigdata29");//創(chuàng)建操作hive的對(duì)象Statement state = conn.createStatement();ResultSet resultSet = state.executeQuery("select * from emp ");while (resultSet.next()){String empno = resultSet.getString(1);String hiredate = resultSet.getString(2);String sal = resultSet.getString(3);String deptno = resultSet.getString(4);System.out.println(empno+", "+hiredate+", "+sal+", "+deptno);}//釋放資源conn.close();}
}

http://m.aloenet.com.cn/news/33821.html

相關(guān)文章:

  • 電子商務(wù)的網(wǎng)站建設(shè)分析網(wǎng)絡(luò)營(yíng)銷的特點(diǎn)不包括
  • 免費(fèi)做網(wǎng)站模板在哪里做營(yíng)銷公司排名
  • 百度 新網(wǎng)站 重定向過(guò)多成都seo學(xué)徒
  • 網(wǎng)站改版需要多少錢網(wǎng)頁(yè)設(shè)計(jì)參考網(wǎng)站
  • 幫人做網(wǎng)站的公司嗶哩嗶哩推廣網(wǎng)站
  • c做的網(wǎng)站購(gòu)物網(wǎng)站
  • 臨西網(wǎng)站建設(shè)住房和城鄉(xiāng)建設(shè)部官網(wǎng)
  • 電子商務(wù)的網(wǎng)站怎么做谷歌google中文登錄入口
  • 免費(fèi)網(wǎng)站建設(shè)公司推薦跨境電商平臺(tái)注冊(cè)開店流程
  • 網(wǎng)站開發(fā)教程免費(fèi)成功營(yíng)銷案例分享
  • 網(wǎng)站建設(shè)公司有多少家百度上怎么免費(fèi)開店
  • 網(wǎng)站國(guó)外推廣淘寶店鋪如何推廣
  • 西寧微網(wǎng)站建設(shè)多少錢各大網(wǎng)站提交入口
  • 深圳疫情防控形勢(shì)seo技術(shù)培訓(xùn)寧波
  • 做水果蔬菜生意網(wǎng)站鄭州網(wǎng)站優(yōu)化推廣
  • 公司企業(yè)網(wǎng)站制作教程最佳磁力引擎吧
  • 桔子建站是什么平臺(tái)國(guó)外新聞最新消息
  • 萬(wàn)網(wǎng)域名備案網(wǎng)站網(wǎng)推拉新app推廣平臺(tái)
  • 做自媒體可以參考的外國(guó)網(wǎng)站軟件開發(fā)需要學(xué)什么
  • 南寧網(wǎng)站備案域名查詢seo
  • 小說(shuō)網(wǎng)站自動(dòng)采集圖片百度搜索
  • 免費(fèi)網(wǎng)站管理軟件seo整站優(yōu)化更能準(zhǔn)確獲得客戶
  • 宣傳冊(cè)設(shè)計(jì)及網(wǎng)站建設(shè)福建seo
  • idc網(wǎng)站模版營(yíng)銷戰(zhàn)略有哪些內(nèi)容
  • 房地產(chǎn)電子商務(wù)的網(wǎng)站建設(shè)網(wǎng)頁(yè)做推廣
  • 網(wǎng)站如何創(chuàng)建全網(wǎng)營(yíng)銷
  • 消費(fèi)者聯(lián)盟網(wǎng)站怎么做站內(nèi)推廣和站外推廣的區(qū)別
  • 計(jì)算機(jī)程序網(wǎng)站開發(fā)是什么發(fā)帖子的網(wǎng)站
  • 成品網(wǎng)站源碼多少錢百度付費(fèi)推廣
  • 餐廳網(wǎng)站設(shè)計(jì)模板下載企業(yè)網(wǎng)站的網(wǎng)絡(luò)營(yíng)銷功能