zoukankan      html  css  js  c++  java
  • Hive使用

    CREATE TABLE A (X STRING);
     
    CREATE TABLE () 语句已经定义完成。数据库定义完成。进行直接解释
     
    select找一张表的流程
    表所在的库--->在库下找所在的表
     
    HIVE CREATE TABLE A (wangxiaojia int);
     
    MYSQL INERT INTO HIVE.TBLS values (db_num,A,timestamp,col).....
     
    HIVE的连接模式== 本地连接模式 直接启动hive命令
    HIVE的远程连接 这里要启动HIVE的服务 thirft进行编写
    hiveserver2 ---- > 前台启动 后台启动
    前台启动 hiveserver2
    后台启动 hiveserver2 &
     
    beeline
    !connect jdbc:hive2://192.168.16.100:10000
     
    beeline -u jdbc:hive2://192.168.16.100:10000 -n root
     
    两种删除数据的方法:
     
    delete
     
    truncate HIVE中删除数据 truncate是删除表中所有的数据
     
    HIVE的分区表
     
    create table test (id int, name string,tel string) partitioned by (age int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE;
     
    create table test1 (id int, name string,tel string,age int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE;
     
    HIVE中的分区表
    HIVE数据库是支持分区表的,但是这里我们注意的是两点
     
    一 分区表中的分区列 必须单列出来
    二 分区列存放数据的位置和其他数据不在一起 在一个单独的目录下
     
    静态分区插入数据:
    insert overwrite table test PARTITION (age=25) select id, name, tel from test3;
     
    动态分区插入数据:
    set hive.exec.mode.local.auto=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    insert overwrite table test PARTITION (age) select id, name, tel, age from test3;
     
     
    6 bsr2 134535353535 22
    7 bsr3 132453535353 24
    8 bsr4 154243434355 25
    1 bsr 13188888888888 25
    2 test 13888888888888 27
    3 zs 899314121 29
     
     
     
     
    create table test_buk (id int, name string,tel string,age int)
    clustered by(id) sorted by(age) into 2 buckets
    row format delimited fields terminated by ' ';
     
    set hive.enforce.bucketing = true;
    load data local inpath '/root/student.txt' into test_buk;
     
     
    insert overwrite table test_buk
    select id,name,tel,age from test3 distribute by(id) sort by(age);
     
    能力测试
    create table test_cou (id int, name string,tel string)
    partitioned by (age int)
    clustered by(id) sorted by(tel) into 2 buckets
    row format delimited fields terminated by ' ';
     
    第一满足动态分区 第二分桶不能出错
     
    set hive.exec.mode.local.auto=true;
    set hive.exec.dynamic.partition.mode=nonstrict;
    set hive.enforce.bucketing = true;
    insert overwrite table test_cou PARTITION (age)
    select id, name, tel, age from test3 distribute by(id) sort by(tel);
     
     
     
  • 相关阅读:
    【hihocoder 1477】闰秒
    【codeforces 768F】Barrels and boxes
    【codeforces 767E】Change-free
    【codeforces 810A】Straight «A»
    【codeforces 810B】Summer sell-off
    【codeforces 810C】Do you want a date?
    【codeforces 757E】Bash Plays with Functions
    【codeforces 749D】Leaving Auction
    Java数据结构与算法(5)
    使用Xshell远程连接管理Linux实践
  • 原文地址:https://www.cnblogs.com/dasiji/p/11245520.html
Copyright © 2011-2022 走看看