zoukankan      html  css  js  c++  java
  • hive

    hive包:hive-2.1.0

    安装:

    1、解压缩

    2、重命名hive-default.xml.template 为hive-default.xml

    3、./schematool -initSchema -dbType derby初始化数据

    进入hive命令行:

    ./bin/hive
    

    显示数据库

    show databases;
    

    创建数据库

     create database test;
    

    使用数据库:

    use test;
    

    显示数据库中的表

    show tables;
    

    创建表

    CREATE TABLE pokes (foo INT, bar STRING);
    

    创建分区表

    CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);
    

    通过正则表达式查看表

    SHOW TABLES '.*s';
    

    查看表的结构

    describe pokes;
    

    更新表的名称

     alter table pokes rename to pokes2;
    

    给表添加一列 

     alter table pokes2 add columns (new_col int);
    

    给表添加一列,并对列添加注释

    alter table pokes2 add columns (new_col_2 int comment "new column");
    

    删除表:

    drop table pokes2;
    

    为了后面的测试先创建一个表:create table test(name string, age int);

     加载本地数据到表中:

    load data local inpath './1.txt' into table test; 
    local代表加载本地数据,如果没有则代表加载HDFS的数据
    加载本地数据到表中并覆盖原来的数据:
    load data local inpath './1.txt' overwrite into table test;
    

     overwrite表示覆盖原来的数据

    创建一个分区表: create table p_test(name string, age int) partitioned by (year string);

    加载数据到分区表:

    load data local inpath './1.txt' overwrite into table test partition (year='2016');
    

    查询某一分区的数据(where)

    select * from p_test where year = '2016';
    

    查询数据:

    select name from test;
    

    把查询的结果存储在HDFS上:

    insert overwrite  directory '/2.txt' select * from test;
    
  • 相关阅读:
    subprocess
    bytes(str_, encoding="utf8")
    按文件生成时间 排序 批量与生成同步上传文件
    async
    http trigger 事件源是事件的生产者,函数是事件的处理者
    分片上传
    使用 FFmpeg 处理高质量 GIF 图片
    兴趣 主题 字段 二值化 多值并列属性 拆分 二值化
    打开 回收站
    shell如何查看单个或多个文件的行数或总行数
  • 原文地址:https://www.cnblogs.com/heml/p/6004745.html
Copyright © 2011-2022 走看看