前沿拓展:
insert into
D
歡迎訪問(wèn)我的GitHub
https://github.com/zq2599/blog_demos
內(nèi)容:所有原創(chuàng)文章分類(lèi)和匯總,及配套源碼,涉及Java、Docker、Kubernetes、DevOPS等;
關(guān)于hive學(xué)習(xí)筆記系列《hive學(xué)習(xí)筆記》系列保持了作者一貫的風(fēng)格,即通過(guò)實(shí)戰(zhàn)學(xué)習(xí)和了解;作為一個(gè)構(gòu)建在Hadoop上的數(shù)據(jù)倉(cāng)庫(kù)框架,hive被用來(lái)進(jìn)行數(shù)據(jù)提取、轉(zhuǎn)化、加載,這是一種可以存儲(chǔ)、查詢和分析存儲(chǔ)在Hadoop中的大規(guī)模數(shù)據(jù)的機(jī)制,hive數(shù)據(jù)倉(cāng)庫(kù)工具能將結(jié)構(gòu)化的數(shù)據(jù)文件映射為一張數(shù)據(jù)庫(kù)表,并提供SQL查詢功能,能將SQL語(yǔ)句轉(zhuǎn)變成MapReduce任務(wù)來(lái)執(zhí)行。(來(lái)自:《Hadoop應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)詳解(修訂版)》)架構(gòu)如下,可見(jiàn)最終還是在執(zhí)行MapReduce:
環(huán)境信息
本文對(duì)應(yīng)的環(huán)境信息如下:
CentOS Linux release 7.5.1804JDK:1.8.0_191hadoop:2.7.7hive:1.2.2關(guān)于hive的部署需要先部署hadoop環(huán)境,請(qǐng)參考《Linux部署hadoop2.7.7集群》hadoop部署成功后,安裝和體驗(yàn)hive其參考《安裝和體驗(yàn)hive》數(shù)據(jù)類(lèi)型簡(jiǎn)介
Hive支持基本和復(fù)雜數(shù)據(jù)類(lèi)型:
基本數(shù)據(jù)類(lèi)型:包括數(shù)值型、布爾型、字符串類(lèi)型和時(shí)間戳類(lèi)型;復(fù)雜數(shù)據(jù)類(lèi)型:數(shù)組、映射、結(jié)構(gòu);基本數(shù)據(jù)類(lèi)型通過(guò)思維導(dǎo)圖來(lái)分類(lèi)和理解:
下面通過(guò)列表說(shuō)明所有的基本數(shù)據(jù)類(lèi)型:
關(guān)于三種字符串類(lèi)型STRING,變長(zhǎng),無(wú)需最大長(zhǎng)度聲明,理論上能存儲(chǔ)2GB字符;VARCHAR,變長(zhǎng),需要聲明最大長(zhǎng)度(1到65535之間),例如VARCHAR(100);CHAR,定長(zhǎng),如CHAR(100);常用類(lèi)型綜合實(shí)戰(zhàn)啟動(dòng)hive,進(jìn)入交互模式,執(zhí)行以下語(yǔ)句建表,字段類(lèi)型是常用的幾種:create table t1(
int_field INT,
string_field STRING,
boolean_field BOOLEAN,
date_field DATE,
timestamp_field TIMESTAMP
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
STORED AS TEXTFILE;用insert語(yǔ)句新增一條記錄:insert into t1
values
(101, 'a101', true, '2020-01-01', '2020-03-01 00:00:00');使用函數(shù),在新增的記錄的時(shí)候,將timestamp_field字段設(shè)置為當(dāng)前時(shí)間,注意和前面的insert語(yǔ)句比較一下,使用函數(shù)時(shí)必須用到select XXX from XXX limit 1這樣的語(yǔ)法:insert into t1
select
103, 'a103', true, '2020-01-01', current_timestamp()
from t1 limit 1;看一下新增的兩條記錄:hive> select * from t1;
OK
101 a101 true 2020-01-01 2020-03-01 00:00:00
103 a103 true 2020-01-01 2020-10-27 20:42:35.729
Time taken: 0.062 seconds, Fetched: 2 row(s)查看當(dāng)前時(shí)間:select unix_timestamp();
響應(yīng):
hive> select unix_timestamp();
OK
1603802631
Time taken: 0.028 seconds, Fetched: 1 row(s)將DATE字段轉(zhuǎn)為T(mén)IMESTAMP:select cast(date_field as timestamp) from t1;
響應(yīng):
hive> select cast(date_field as timestamp) from t1;
OK
2020-01-01 00:00:00
2020-01-01 00:00:00
Time taken: 0.051 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為DATE:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為BIGINT:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)
至此,hive的基本數(shù)據(jù)類(lèi)型已經(jīng)了解,接下來(lái)的章節(jié)咱們一起學(xué)習(xí)了解復(fù)雜數(shù)據(jù)類(lèi)型;
參考文檔
https://stackoverflow.com/questions/37863194/insert-timestamp-into-hive/37868132
歡迎關(guān)注我的**:程序員欣宸
拓展知識(shí):
前沿拓展:
insert into
D
歡迎訪問(wèn)我的GitHub
https://github.com/zq2599/blog_demos
內(nèi)容:所有原創(chuàng)文章分類(lèi)和匯總,及配套源碼,涉及Java、Docker、Kubernetes、DevOPS等;
關(guān)于hive學(xué)習(xí)筆記系列《hive學(xué)習(xí)筆記》系列保持了作者一貫的風(fēng)格,即通過(guò)實(shí)戰(zhàn)學(xué)習(xí)和了解;作為一個(gè)構(gòu)建在Hadoop上的數(shù)據(jù)倉(cāng)庫(kù)框架,hive被用來(lái)進(jìn)行數(shù)據(jù)提取、轉(zhuǎn)化、加載,這是一種可以存儲(chǔ)、查詢和分析存儲(chǔ)在Hadoop中的大規(guī)模數(shù)據(jù)的機(jī)制,hive數(shù)據(jù)倉(cāng)庫(kù)工具能將結(jié)構(gòu)化的數(shù)據(jù)文件映射為一張數(shù)據(jù)庫(kù)表,并提供SQL查詢功能,能將SQL語(yǔ)句轉(zhuǎn)變成MapReduce任務(wù)來(lái)執(zhí)行。(來(lái)自:《Hadoop應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)詳解(修訂版)》)架構(gòu)如下,可見(jiàn)最終還是在執(zhí)行MapReduce:
環(huán)境信息
本文對(duì)應(yīng)的環(huán)境信息如下:
CentOS Linux release 7.5.1804JDK:1.8.0_191hadoop:2.7.7hive:1.2.2關(guān)于hive的部署需要先部署hadoop環(huán)境,請(qǐng)參考《Linux部署hadoop2.7.7集群》hadoop部署成功后,安裝和體驗(yàn)hive其參考《安裝和體驗(yàn)hive》數(shù)據(jù)類(lèi)型簡(jiǎn)介
Hive支持基本和復(fù)雜數(shù)據(jù)類(lèi)型:
基本數(shù)據(jù)類(lèi)型:包括數(shù)值型、布爾型、字符串類(lèi)型和時(shí)間戳類(lèi)型;復(fù)雜數(shù)據(jù)類(lèi)型:數(shù)組、映射、結(jié)構(gòu);基本數(shù)據(jù)類(lèi)型通過(guò)思維導(dǎo)圖來(lái)分類(lèi)和理解:
下面通過(guò)列表說(shuō)明所有的基本數(shù)據(jù)類(lèi)型:
關(guān)于三種字符串類(lèi)型STRING,變長(zhǎng),無(wú)需最大長(zhǎng)度聲明,理論上能存儲(chǔ)2GB字符;VARCHAR,變長(zhǎng),需要聲明最大長(zhǎng)度(1到65535之間),例如VARCHAR(100);CHAR,定長(zhǎng),如CHAR(100);常用類(lèi)型綜合實(shí)戰(zhàn)啟動(dòng)hive,進(jìn)入交互模式,執(zhí)行以下語(yǔ)句建表,字段類(lèi)型是常用的幾種:create table t1(
int_field INT,
string_field STRING,
boolean_field BOOLEAN,
date_field DATE,
timestamp_field TIMESTAMP
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
STORED AS TEXTFILE;用insert語(yǔ)句新增一條記錄:insert into t1
values
(101, 'a101', true, '2020-01-01', '2020-03-01 00:00:00');使用函數(shù),在新增的記錄的時(shí)候,將timestamp_field字段設(shè)置為當(dāng)前時(shí)間,注意和前面的insert語(yǔ)句比較一下,使用函數(shù)時(shí)必須用到select XXX from XXX limit 1這樣的語(yǔ)法:insert into t1
select
103, 'a103', true, '2020-01-01', current_timestamp()
from t1 limit 1;看一下新增的兩條記錄:hive> select * from t1;
OK
101 a101 true 2020-01-01 2020-03-01 00:00:00
103 a103 true 2020-01-01 2020-10-27 20:42:35.729
Time taken: 0.062 seconds, Fetched: 2 row(s)查看當(dāng)前時(shí)間:select unix_timestamp();
響應(yīng):
hive> select unix_timestamp();
OK
1603802631
Time taken: 0.028 seconds, Fetched: 1 row(s)將DATE字段轉(zhuǎn)為T(mén)IMESTAMP:select cast(date_field as timestamp) from t1;
響應(yīng):
hive> select cast(date_field as timestamp) from t1;
OK
2020-01-01 00:00:00
2020-01-01 00:00:00
Time taken: 0.051 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為DATE:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為BIGINT:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)
至此,hive的基本數(shù)據(jù)類(lèi)型已經(jīng)了解,接下來(lái)的章節(jié)咱們一起學(xué)習(xí)了解復(fù)雜數(shù)據(jù)類(lèi)型;
參考文檔
https://stackoverflow.com/questions/37863194/insert-timestamp-into-hive/37868132
歡迎關(guān)注我的**:程序員欣宸
拓展知識(shí):
前沿拓展:
insert into
D
歡迎訪問(wèn)我的GitHub
https://github.com/zq2599/blog_demos
內(nèi)容:所有原創(chuàng)文章分類(lèi)和匯總,及配套源碼,涉及Java、Docker、Kubernetes、DevOPS等;
關(guān)于hive學(xué)習(xí)筆記系列《hive學(xué)習(xí)筆記》系列保持了作者一貫的風(fēng)格,即通過(guò)實(shí)戰(zhàn)學(xué)習(xí)和了解;作為一個(gè)構(gòu)建在Hadoop上的數(shù)據(jù)倉(cāng)庫(kù)框架,hive被用來(lái)進(jìn)行數(shù)據(jù)提取、轉(zhuǎn)化、加載,這是一種可以存儲(chǔ)、查詢和分析存儲(chǔ)在Hadoop中的大規(guī)模數(shù)據(jù)的機(jī)制,hive數(shù)據(jù)倉(cāng)庫(kù)工具能將結(jié)構(gòu)化的數(shù)據(jù)文件映射為一張數(shù)據(jù)庫(kù)表,并提供SQL查詢功能,能將SQL語(yǔ)句轉(zhuǎn)變成MapReduce任務(wù)來(lái)執(zhí)行。(來(lái)自:《Hadoop應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)詳解(修訂版)》)架構(gòu)如下,可見(jiàn)最終還是在執(zhí)行MapReduce:
環(huán)境信息
本文對(duì)應(yīng)的環(huán)境信息如下:
CentOS Linux release 7.5.1804JDK:1.8.0_191hadoop:2.7.7hive:1.2.2關(guān)于hive的部署需要先部署hadoop環(huán)境,請(qǐng)參考《Linux部署hadoop2.7.7集群》hadoop部署成功后,安裝和體驗(yàn)hive其參考《安裝和體驗(yàn)hive》數(shù)據(jù)類(lèi)型簡(jiǎn)介
Hive支持基本和復(fù)雜數(shù)據(jù)類(lèi)型:
基本數(shù)據(jù)類(lèi)型:包括數(shù)值型、布爾型、字符串類(lèi)型和時(shí)間戳類(lèi)型;復(fù)雜數(shù)據(jù)類(lèi)型:數(shù)組、映射、結(jié)構(gòu);基本數(shù)據(jù)類(lèi)型通過(guò)思維導(dǎo)圖來(lái)分類(lèi)和理解:
下面通過(guò)列表說(shuō)明所有的基本數(shù)據(jù)類(lèi)型:
關(guān)于三種字符串類(lèi)型STRING,變長(zhǎng),無(wú)需最大長(zhǎng)度聲明,理論上能存儲(chǔ)2GB字符;VARCHAR,變長(zhǎng),需要聲明最大長(zhǎng)度(1到65535之間),例如VARCHAR(100);CHAR,定長(zhǎng),如CHAR(100);常用類(lèi)型綜合實(shí)戰(zhàn)啟動(dòng)hive,進(jìn)入交互模式,執(zhí)行以下語(yǔ)句建表,字段類(lèi)型是常用的幾種:create table t1(
int_field INT,
string_field STRING,
boolean_field BOOLEAN,
date_field DATE,
timestamp_field TIMESTAMP
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
STORED AS TEXTFILE;用insert語(yǔ)句新增一條記錄:insert into t1
values
(101, 'a101', true, '2020-01-01', '2020-03-01 00:00:00');使用函數(shù),在新增的記錄的時(shí)候,將timestamp_field字段設(shè)置為當(dāng)前時(shí)間,注意和前面的insert語(yǔ)句比較一下,使用函數(shù)時(shí)必須用到select XXX from XXX limit 1這樣的語(yǔ)法:insert into t1
select
103, 'a103', true, '2020-01-01', current_timestamp()
from t1 limit 1;看一下新增的兩條記錄:hive> select * from t1;
OK
101 a101 true 2020-01-01 2020-03-01 00:00:00
103 a103 true 2020-01-01 2020-10-27 20:42:35.729
Time taken: 0.062 seconds, Fetched: 2 row(s)查看當(dāng)前時(shí)間:select unix_timestamp();
響應(yīng):
hive> select unix_timestamp();
OK
1603802631
Time taken: 0.028 seconds, Fetched: 1 row(s)將DATE字段轉(zhuǎn)為T(mén)IMESTAMP:select cast(date_field as timestamp) from t1;
響應(yīng):
hive> select cast(date_field as timestamp) from t1;
OK
2020-01-01 00:00:00
2020-01-01 00:00:00
Time taken: 0.051 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為DATE:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為BIGINT:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)
至此,hive的基本數(shù)據(jù)類(lèi)型已經(jīng)了解,接下來(lái)的章節(jié)咱們一起學(xué)習(xí)了解復(fù)雜數(shù)據(jù)類(lèi)型;
參考文檔
https://stackoverflow.com/questions/37863194/insert-timestamp-into-hive/37868132
歡迎關(guān)注我的**:程序員欣宸
拓展知識(shí):
前沿拓展:
insert into
D
歡迎訪問(wèn)我的GitHub
https://github.com/zq2599/blog_demos
內(nèi)容:所有原創(chuàng)文章分類(lèi)和匯總,及配套源碼,涉及Java、Docker、Kubernetes、DevOPS等;
關(guān)于hive學(xué)習(xí)筆記系列《hive學(xué)習(xí)筆記》系列保持了作者一貫的風(fēng)格,即通過(guò)實(shí)戰(zhàn)學(xué)習(xí)和了解;作為一個(gè)構(gòu)建在Hadoop上的數(shù)據(jù)倉(cāng)庫(kù)框架,hive被用來(lái)進(jìn)行數(shù)據(jù)提取、轉(zhuǎn)化、加載,這是一種可以存儲(chǔ)、查詢和分析存儲(chǔ)在Hadoop中的大規(guī)模數(shù)據(jù)的機(jī)制,hive數(shù)據(jù)倉(cāng)庫(kù)工具能將結(jié)構(gòu)化的數(shù)據(jù)文件映射為一張數(shù)據(jù)庫(kù)表,并提供SQL查詢功能,能將SQL語(yǔ)句轉(zhuǎn)變成MapReduce任務(wù)來(lái)執(zhí)行。(來(lái)自:《Hadoop應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)詳解(修訂版)》)架構(gòu)如下,可見(jiàn)最終還是在執(zhí)行MapReduce:
環(huán)境信息
本文對(duì)應(yīng)的環(huán)境信息如下:
CentOS Linux release 7.5.1804JDK:1.8.0_191hadoop:2.7.7hive:1.2.2關(guān)于hive的部署需要先部署hadoop環(huán)境,請(qǐng)參考《Linux部署hadoop2.7.7集群》hadoop部署成功后,安裝和體驗(yàn)hive其參考《安裝和體驗(yàn)hive》數(shù)據(jù)類(lèi)型簡(jiǎn)介
Hive支持基本和復(fù)雜數(shù)據(jù)類(lèi)型:
基本數(shù)據(jù)類(lèi)型:包括數(shù)值型、布爾型、字符串類(lèi)型和時(shí)間戳類(lèi)型;復(fù)雜數(shù)據(jù)類(lèi)型:數(shù)組、映射、結(jié)構(gòu);基本數(shù)據(jù)類(lèi)型通過(guò)思維導(dǎo)圖來(lái)分類(lèi)和理解:
下面通過(guò)列表說(shuō)明所有的基本數(shù)據(jù)類(lèi)型:
關(guān)于三種字符串類(lèi)型STRING,變長(zhǎng),無(wú)需最大長(zhǎng)度聲明,理論上能存儲(chǔ)2GB字符;VARCHAR,變長(zhǎng),需要聲明最大長(zhǎng)度(1到65535之間),例如VARCHAR(100);CHAR,定長(zhǎng),如CHAR(100);常用類(lèi)型綜合實(shí)戰(zhàn)啟動(dòng)hive,進(jìn)入交互模式,執(zhí)行以下語(yǔ)句建表,字段類(lèi)型是常用的幾種:create table t1(
int_field INT,
string_field STRING,
boolean_field BOOLEAN,
date_field DATE,
timestamp_field TIMESTAMP
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
STORED AS TEXTFILE;用insert語(yǔ)句新增一條記錄:insert into t1
values
(101, 'a101', true, '2020-01-01', '2020-03-01 00:00:00');使用函數(shù),在新增的記錄的時(shí)候,將timestamp_field字段設(shè)置為當(dāng)前時(shí)間,注意和前面的insert語(yǔ)句比較一下,使用函數(shù)時(shí)必須用到select XXX from XXX limit 1這樣的語(yǔ)法:insert into t1
select
103, 'a103', true, '2020-01-01', current_timestamp()
from t1 limit 1;看一下新增的兩條記錄:hive> select * from t1;
OK
101 a101 true 2020-01-01 2020-03-01 00:00:00
103 a103 true 2020-01-01 2020-10-27 20:42:35.729
Time taken: 0.062 seconds, Fetched: 2 row(s)查看當(dāng)前時(shí)間:select unix_timestamp();
響應(yīng):
hive> select unix_timestamp();
OK
1603802631
Time taken: 0.028 seconds, Fetched: 1 row(s)將DATE字段轉(zhuǎn)為T(mén)IMESTAMP:select cast(date_field as timestamp) from t1;
響應(yīng):
hive> select cast(date_field as timestamp) from t1;
OK
2020-01-01 00:00:00
2020-01-01 00:00:00
Time taken: 0.051 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為DATE:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)將TIMESTAMP字段轉(zhuǎn)為BIGINT:select to_date(timestamp_field) from t1;
響應(yīng):
hive> select to_date(timestamp_field) from t1;
OK
2020-03-01
2020-10-27
Time taken: 0.063 seconds, Fetched: 2 row(s)
至此,hive的基本數(shù)據(jù)類(lèi)型已經(jīng)了解,接下來(lái)的章節(jié)咱們一起學(xué)習(xí)了解復(fù)雜數(shù)據(jù)類(lèi)型;
參考文檔
https://stackoverflow.com/questions/37863194/insert-timestamp-into-hive/37868132
歡迎關(guān)注我的**:程序員欣宸
拓展知識(shí):
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請(qǐng)注明出處:http://xiesong.cn/35819.html