操屁眼的视频在线免费看,日本在线综合一区二区,久久在线观看免费视频,欧美日韩精品久久综

新聞資訊

    新朋友點(diǎn)擊藍(lán)字關(guān)注我哦

    你好,我是巡山貓!

    今天我們來講講Hive中常用的表格操作指令及相關(guān)效果。

    Hive系列文章預(yù)計10-20篇,主要講數(shù)據(jù)分析中最基礎(chǔ)的SQL技能。每周定期更新,歡迎關(guān)注公眾號。

    hive 建表_三張表 建一個中間表_hive 用中間表

    01-最基礎(chǔ)的建表語句

    Hive建表的全部建表語法如下:

    CREATE [EXTERNAL] TABLE [IF NOT EXISTS] 表名(列名 data_type [COMMENT 列注釋], ...)[COMMENT 表注釋][PARTITIONED BY (列名 data_type [COMMENT 列注釋], ...)][CLUSTERED BY (列名, 列名, ...) [SORTED ,BY (列名 [ASC|DESC], ...)] INTO num_buckets BUCKETS][ROW FORMAT row_format][STORED AS file_format][LOCATION?hdfs_path]

    所有[ ]中的內(nèi)容都是可選項,即可有可無,下面我們分別詳細(xì)介紹。

    [] TABLE [IF NOT ] 表名

    三張表 建一個中間表_hive 建表_hive 用中間表

    (列名 )

    是建表語句必須有的,舉個例子,我們要建立一個用戶啟動表:

    CREATE TABLE t_od_use_cnt (      date_8 INT      ,platform string      ,app_version string      ,user_id BIGINT      ,use_cnt INT      ,is_active TINYINT??????);

    首先我們建一個庫app,然后使用并在其中建表,執(zhí)行效果如下:

    hive> create database app;OKTime taken: 0.899 secondshive> use app;OKTime taken: 0.03 secondshive> create table t_od_use_cnt(    >       date_8 int    >       ,platform string    >       ,app_version string    >       ,user_id bigint    >       ,use_cnt int    >       ,is_active tinyint    >       );OKTime?taken:?0.389?seconds

    三張表 建一個中間表_hive 用中間表_hive 建表

    備注:Hive中的關(guān)鍵字大小寫是不區(qū)分的,所有關(guān)鍵字均可使用小寫。

    02-查看表結(jié)構(gòu)執(zhí)行語句:

    DESC?表名;

    查詢上一步新建表的字段及字段對應(yīng)的數(shù)據(jù)類型,運(yùn)行效果如下:

    hive> desc t_od_use_cnt;OKdate_8 int platform string app_version string user_id bigint use_cnt int is_active tinyint Time?taken:?0.28?seconds,?Fetched:?6?row(s)

    hive 建表_三張表 建一個中間表_hive 用中間表

    03-刪除表

    刪除表的語句和刪除庫的類似,只是把換成了table,都是使用drop關(guān)鍵字進(jìn)行刪除操作,慎重操作:

    DROP?TABLE?表名;

    04-建分區(qū)表Hive中有分區(qū)表的概念,分區(qū)表改變了Hive對數(shù)據(jù)存儲的組織方式。查詢時如果我們限定了分區(qū)范圍,Hive就可以直接去相應(yīng)的目錄下查詢數(shù)據(jù),而不需要掃描整個表,所以當(dāng)數(shù)據(jù)量很大時可以顯著提高查詢性能。

    建立分區(qū)表要使用關(guān)鍵字[ BY ( [ ], ...)] ,注意分區(qū)的字段不可在普通字段中重復(fù)出現(xiàn)。分區(qū)表在工作中十分常見,一般來說公司所有的表都會以日期進(jìn)行分區(qū)hive 用中間表,以便提高查詢效率。

    hive 建表_三張表 建一個中間表_hive 用中間表

    我們還是以為例hive 用中間表,建表語句如下:

    CREATE TABLE t_od_use_cnt ( platform string comment '平臺 android,ios' ,app_version string comment 'app版本' ,user_id BIGINT comment '用戶id' ,use_cnt INT comment '當(dāng)日使用次數(shù)' ,is_active TINYINT comment '是否活躍'??????)?partitioned?BY?(date_8?INT?comment?'日期');

    05-查詢既有建表語句在公司中需要查詢既有表的建表格式時使用以下語句即可:

    show?create?table?tablename;

    查詢上文已建表格效果如下:

    hive> show create table t_od_use_cnt;OKCREATE TABLE `t_od_use_cnt`( `platform` string COMMENT '平臺 android,ios', ??`app_version`?string?COMMENT?'app版本,',???`user_id`?bigint?COMMENT?'用戶id',???`use_cnt`?int?COMMENT?'當(dāng)日使用次數(shù)',???`is_active`?tinyint?COMMENT?'是否活躍')PARTITIONED BY ( ??`date_8`?int?COMMENT?'日期')ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'LOCATION 'hdfs://hadoop:9000/usr/hive/warehouse/t_od_use_cnt'TBLPROPERTIES (??'transient_lastDdlTime'='1556161316')

網(wǎng)站首頁   |    關(guān)于我們   |    公司新聞   |    產(chǎn)品方案   |    用戶案例   |    售后服務(wù)   |    合作伙伴   |    人才招聘   |   

友情鏈接: 餐飲加盟

地址:北京市海淀區(qū)    電話:010-     郵箱:@126.com

備案號:冀ICP備2024067069號-3 北京科技有限公司版權(quán)所有