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