`
duming115
  • 浏览: 113176 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hive 创建表

阅读更多
1. Hive 创建表时正则表达式与java代码中一致,RegexSerDe 中用\\来表示反转码
create table inst_cn_3 (
  ip string,
  time string,
  mac string,
  lan string,
  ver string,
  lc string,
  pn string,
  reg string,
  vrf string,
  line string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
  "input.regex" = "- *([\\d\\.]+) *\\[([\\d]{2}/[\\w]+/[\\d]{4}:[\\d]{2}:[\\d]{2}:[\\d]{2}\\s+\\+[\\d]+)\\] *GET */mx3/inst/([0-9a-f]{12})/ver=([\\.\\d]+),lan=(0x[\\w]+)(?:,lc=([\\w]+))(?:,pn=([\\w]+))(?:,reg=([0-1]))(?:,vrf=([\\w]+))?.*"
)
STORED AS TEXTFILE;

alter table inst_cn_3 add columns(line string);
ALTER TABLE inst_cn_3 SET SERDEPROPERTIES (
  "input.regex" = "- ([\\d\\.]+) \\[([\\d]{2}/[\\w]+/[\\d]{4}:[\\d]{2}:[\\d]{2}:[\\d]{2}\\s+\\+[\\d]+)\\] GET /mx3/inst/([0-9a-f]{12})/ver=([\\.\\d]+),lan=(0x[\\w]+)(?:,lc=([\\w]+))(?:,pn=([\\w]+))(?:,reg=([0-1]))(?:,vrf=([\\w]+))?.*|(.*)"
);
select * from inst_cn_3 limit 100;

select
  line
from inst_cn_3
where
  1=1
   and mac is null
   and line is not null
   and  !(line rlike '.*unknowuser00.*')
  ;

hadoop fs -cp /mnt/nfs/log/statcn/inst/inst_cn_3.*.txt /hive/warehouse/inst_cn_3/

2011.06.09 hive时间处理
1.select
  from_unixtime(unix_timestamp('02/May/2011:00:00:00 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss') ,
  from_unixtime(unix_timestamp('02/May/2011:23:59:59 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss')  ,
  from_unixtime(unix_timestamp('03/May/2011:00:00:00 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss') ,
  from_unixtime(unix_timestamp('03/May/2011:23:59:59 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss') 
from
  stat_c_log
where
  1=1
  and partkey = '20110503'
  and logType = 'inst_cn_3'
  and url rlike '/mx3/inst/.*'
limit
  10
;

2.
select
  from_unixtime(unix_timestamp('02/May/2011:00:00:00 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss') ,
  from_unixtime(unix_timestamp('02/May/2011:23:59:59 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss')  ,
  from_unixtime(unix_timestamp('03/May/2011:00:00:00 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss') ,
  from_unixtime(unix_timestamp('03/May/2011:23:59:59 +0800','dd/MMMMM/yyyy:HH:mm:ss Z'),'yyyy-MM-dd HH:mm:ss')  ,
  round((unix_timestamp('02/May/2011:00:00:00 +0800','dd/MMMMM/yyyy:HH:mm:ss Z')-4*3600)/(3600*24))*(3600*24*1000),
  round((unix_timestamp('02/May/2011:23:59:59 +0800','dd/MMMMM/yyyy:HH:mm:ss Z')-4*3600)/(3600*24))*(3600*24*1000)
from
  stat_c_log
where
  1=1
  and partkey = '20110503'
  and logType = 'inst_cn_3'
  and url rlike '/mx3/inst/.*'
limit
  10
;

2012.03.01
  1. Hive 方法注册类 FunctionRegistry
2012.06.14
  1. set hive.cli.print.header=true; 可以设置hive shell的输出.
2012.06.26
  1. hive cdh4b2 使用arichive 对表归档后, 使用select line 对归档后的partition查询时, 报FileNotFoundException 异常。
   https://issues.apache.org/jira/browse/MAPREDUCE-2704 是因为CombineFileInputFormat constructs new Path objects by converting an existing path to a URI, and then only pulling out the "path" part of it. This drops the scheme and host, which makes CombineFileInputFormat fail if the paths are on a filesystem other than the default one.
2012.07.16
  1. EXPLAIN EXTENDED hive_query; 查看运行.
2012.07.29
  1. DESCRIBE FORMATTED mock; 显示columns, location, params等.
  2. /src/ql/src/test/queries/clientpositive/
分享到:
评论

相关推荐

    hive 创建表语法.docx

    hive 创建表语法使用等

    hive练习数据和练习题及答案

    hive练习数据和hive练习题包含了hive练习数据,hive数据的建表ddl和hive练习题,非常适合做hive练习,新手培训,快速入门等; 包含以下练习: hive的group by 和集合函数 hive的Order By/Sort By/Distribute By Join...

    HIVE创建库创建表.docx

    在数据集目录中选取2个数据文件内部表创建表,选取2个数据文件创建外部表。 使用美国疫情数据创建分区表 疫情数据实现静态和动态加载数据到分区表 自己构建疫情数据实现多重分区表 使用美国疫情数据实现桶表 修改...

    hive外部表创建

    SparkSQL通过Hive创建DataFrame

    SparkSQL通过Hive创建DataFrame问题分析 问题一 Caused by: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: Table or view 'stu' not found in database 'default'; 分析:确实没有临时表View,...

    sql同步自动生成hive建表语句及注释

    基于oracle或者mysql生成自动建表同步源数据表结构及注释

    hive建表语句

    hive建表语句hive建表语句hive建表语句hive建表语句hive建表语句hive建表语句

    Hive使用手册Hive使用手册

    3 Hive创建/删除数据库 3 3.1创建数据库: 3 3.2 删除数据库: 3 4 Hive 表相关语句 3 4.1 Hive 建表: 3 4.1.1使用LIKE关键字创建一个与已有表模式相同的新表: 4 4.2 Hive 修改表 4 4.2.1 Hive 新增一个字段: 4 ...

    hive开启权限后不能创建数据库问题

    背景:由于Hive需要开启权限管理,安装网上教程,开启权限配置,重启集群后。 使用root用户登录,进入Hive命令行界面。 执行 create database test; 发现报错: Authorization failed:No privilege 'Create' found ...

    hive根据excel批量生成建表语句

    根据excel中表的字段清单,批量生成建表语句; 打开工具,按格式填入表名、字段、类型等内容,点击“视图”-->“宏”-->“查看宏”-->“执行”

    hive分区表分通表建表语句详解和例子

    详细描述了hive分桶表,分区表的创建,附带详细建表语句,包含一级静态分区,二级静态分区,一级动态分区,二级动态分区,分区的查询,删除,添加,数据的导入

    Hive内部表和外部表

    创建表时使用关键字external创建的表就是外部表,没有使用该关键字创建的表就是内部表。 删除表时(drop table)内部表会删除hdfs对应路径,而外部表不会删除hdfs对应的路径, 删除表无论是内部表和外部表都会删除元...

    excel动态创建hive表语句模板.xlsx

    excel 根据字段创建 hive表

    13-Hive基本操作1

    2. 以上简单创建了一个DB库,但是这条HQL可以更进一步的优化,我们可以加上if not exists 3. 查看数据仓库DB的信息及路径 4. 删除名为DB

    hive搭建及使用入门简介(内含PPT、各种表创建sql及hive搭建使用笔记)

    适用人群:hive学习童鞋,hive方面从业人员 从hive的搭建 到 hive的分区表/内部表/外部表/分桶等sql讲解

    利用Hive进行复杂用户行为大数据分析及优化案例

    07_复杂日志分析-字段提取及临时表的创建 08_复杂日志分析-指标结果的分析实现 09_Hive中数据文件的存储格式介绍及对比 10_常见的压缩格式及MapReduce的压缩介绍 11_Hadoop中编译配置Snappy压缩 12_Hadoop及Hive配置...

    HIVE-分桶表的详解和创建实例.docx

    HIVE-分桶表的详解和创建实例.docx

    hive 创建自定义函数 和 hive加载说明

    NULL 博文链接:https://chengjianxiaoxue.iteye.com/blog/2235666

    大数据实验六实验报告:熟悉Hive的基本操作

    “大数据技术原理与应用”课程实验报告 题目:实验六:熟悉Hive的基本操作 姓名:小猪猪 日期:2022/5/15 1、实验环境: ...1.创建一个内部表 stocks,字段分隔符为英文逗号,表结构如下所示: stocks 表结构:

    Hive管理表和外部表的区别

    关于Hive数据仓库的管理表(MANAGED_TABLE)和外部表(EXTERNAL_TABLE)的区别,在创表的时候,如果不指定,则默认创建管理表。如果不知道此表是什么类型的表的话,可以在hive的命令行里打desc formatted table_name...

Global site tag (gtag.js) - Google Analytics