相关显示参数设置

  • 显示参数设置
set hive.cli.print.header=true;  // 打印列名
set hive.cli.print.row.to.vertical=true; // 开启行转列功能, 前提必须开启打印列名功能
set hive.cli.print.row.to.vertical.num=1; // 设置每行显示的列数
  • 动态分区参数设置
set hive.exec.dynamic.partition=true;使用动态分区
set hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.max.dynamic.partitions=100000;设置允许最大动态分区的数量
SET hive.exec.max.dynamic.partitions.pernode=100000;

创建数据库

CREATE DATABASE [IF NOT EXISTS] userdb;

建表

  • 普通建表:
create table user_summary_with_tel (
bill_time string comment '订单时间',
tel string comment '订购号码',
bill_addr string comment '配送地址',
county string comment '区县',
street string comment '街道',
community string comment '社区',
campus string comment '校园',
company string comment '公司',
building string comment '大厦',
residential_district string comment '住宅小区',
industrial_district string comment '工业区',
city_village string comment '城中村',
address string comment '地址名称',
attribute string comment '属性',
return_address string comment '返回地址',
ordermonth string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
  • 分区表
create table tb_class_info
(id int,
createtime timestamp ,
modifytime timestamp)
PARTITIONED BY (day string, class_name string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE;
  • 临时表
CREATE TABLE use_resident(
tel string,
bill_addr string,
address string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;

本地数据写入hive表

load data local inpath '/data/use_resident.csv' overwrite into table use_resident;

load data local inpath '/home/hadoop/tbclass.txt' overwrite into table tb_class_info partition(day='2017-06-01', class_name=val2);

查询结果存储

  • 查询结果写入普通表
insert overwrite table tel_imsi_9551 select distinct(tel, imsi) from sgs_data_partition where tac='9551';
  • 查询结果写入分区表
INSERT INTO TABLE sgs_data_part
PARTITION (day, tac)
SELECT tel, imsi, time, tac_cid day, tac
FROM sgs_data_src;
  • 查询结果写入本地文件
hive -e "user sgs;select a.imsi, b.tel_num, a.summary from user_summary a left outer join imsi_tel_9551 b on a.imsi=b.imsi;" >> user_summary.txt

hive调用python的udf

udf文件

# encoding: utf-8
'''
@author: zcc
@license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
@contact: ********@163.com
@software: pycharm
@file: hive_udf.py
@time: 8/25/17 9:00 AM
@desc:自定义hive函数处理合并后的用户信息
''' import sys
from collections import Counter
for line in sys.stdin:
imsi, tac_cids = line.strip().split('\t')
tac_cids = tac_cids.split('|')
# 单个用户16天内累计SGSIMSIAatach和SGSIMSIDetach次数小于10则剔除该用户
if len(tac_cids) < 8: continue tac_cid_count = Counter(tac_cids) tac_cid_elements = list() for key, value in tac_cid_count.iteritems():
if value <= 1: continue
tac_cid_elements.append("{0}:{1}".format(key, value)) print '%s\t%s' % (imsi, ','.join(tac_cid_elements))
add file /home/hadoop/hive_udf.py;
insert overwrite table user_summary select transform(*) using 'python hive_udf.py' as (imsi, tac_cids) from user_info_merge_9551;

清空表

truncate table tel_imsi_9551;

删除表

DROP TABLE [IF EXISTS] table_name;

删除数据库

 DROP DATABASE IF EXISTS userdb;

更改表的字段属性

ALTER TABLE table_one CHANGE old_name new_name net_type_name;

删除表的一个指定分区

alter table table_name drop partition (day=partition_name);

查询结果写入一张新表

CREATE TABLE table_name STORED AS SEQUENCEFILE SELECT * FROM src_table_name;

hive常用操作的更多相关文章

  1. hive 常用操作

    参考:https://www.cnblogs.com/jonban/p/10779938.html Hive 启动:hive 退出:hive>quit; show databases; use  ...

  2. Hive常用操作之数据导入导出

    一.Hive数据导入导出 1.hive数据导出 很多时候,我们在hive中执行select语句,希望将最终的结果保存到本地文件或者保存到hdfs系统中或者保存到一个新的表中,hive提供了方便的关键词 ...

  3. 入门大数据---Hive常用DML操作

    Hive 常用DML操作 一.加载文件数据到表 1.1 语法 LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename ...

  4. Hive 常用命令和语句

    示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...

  5. Hive 时间操作

    Hive 时间转换 UNIX时间戳概念:因为UNIX时间戳只是一个秒数,一个UNIX时间戳在不同时区看来,时间是不同的.如UNIX时间戳0,在0时区看来是1970-01-01 00:00:00,在东八 ...

  6. 【三】用Markdown写blog的常用操作

    本系列有五篇:分别是 [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面 [二]jekyll 的使用 :主要是jekyll的配置 [三]Markdown+ ...

  7. php模拟数据库常用操作效果

    test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...

  8. Mac OS X常用操作入门指南

    前两天入手一个Macbook air,在装软件过程中摸索了一些基本操作,现就常用操作进行总结, 1关于触控板: 按下(不区分左右)            =鼠标左键 control+按下        ...

  9. mysql常用操作语句

    mysql常用操作语句 1.mysql -u root -p   2.mysql -h localhost -u root -p database_name 2.列出数据库: 1.show datab ...

随机推荐

  1. 复旦大学2017--2018学年第二学期高等代数II期末考试情况分析

    一.期末考试成绩班级前十名 张菲诺(95).刘宇其(95).魏一鸣(93).郭宇城(92).程梓兼(91).葛珈玮(90).汪子怡(90).余张伟(90).张昰昊(89).朱柏青(89) 二.总成绩计 ...

  2. 在CAcUiTabChildDialog中使用点取或者(拾取)时卡住的问题

    问题描述:在Tab的对话框中,其子对话框CAcUiTabChildDialog中用点取或者(拾取)时卡住的问题 在子对话框中: BeginEditorCommand(); CompleteEditor ...

  3. 关于spring boot中的pageHelper的mybatis插件使用

    先引入pageHelper依赖: <dependency>            <groupId>com.github.pagehelper</groupId>  ...

  4. lambda 委托 匿名方法

    委托: delegate是C#中的一种类型,它实际上是一个能够持有对某个方法的引用的类.与其它的类不同,delegate类能够拥有一个签名(signature),并且它只能持有与它的签名相匹配的方法的 ...

  5. vue--mixins

    混入(mixins) 是一种分发Vue 组件中可复用功能的非常灵活的方式 mixins主要用在以下两个方面: 当做完一个项目,想好好放松的时候,突然有新需求 为了不污染完美的构造函数,在构造函数外面定 ...

  6. Python入门(一)数据类型、循环语句

    脚本语言类型: 1.编译型语言:写完代码不能执行,需要先编译     eg:c.c++.c# 2.解释性语言:不需要编译 直接执行                      eg:python.jav ...

  7. 自动生成CHANGELOG.md

    $ npm install -g conventional-changelog-cli $ cd my-project $ conventional-changelog -p angular -i C ...

  8. 怎么将GitHub上的项目下载到本地,并运行

    第一步:首页的有项目的地址才能下载 第二步:使用git 下载  命令:git clone 项目地址 第三步:npm install  下载依赖 第四步:npm run dev 运行项目

  9. [GXOI/GZOI2019]旧词

    很像LNOI 2014 LCA那道题. 同样的套路,离线以后直接扫描线. k=1的话就是原题. 考虑一般情况. 原本的做法是对x到根的这条链做一下区间+1操作,目的是为了是的在深度为i的位置得到的贡献 ...

  10. xshell6 同时操作多个终端

    当我们使用Xshell的时候,有时候需要同时建立多个会话,连接不同的服务器或者不同的用户,如何同时向所有会话发送同一指令呢?方法如下: 1.依次点击  查看 ---> 撰写 ---> 撰写 ...