hive
hive案例
1、基站掉线率统计 需求 统计出掉线率最高的前10基站 数据 record_time:通话时间 imei:基站编号 cell:手机编号 drop_num:掉话的秒数 duration:通话持续总秒数 步骤 建表 注意字段类型和rowformat 根据需求生成相应的结果表 load数据 写sql,找出掉线率最高的基站 2、wordcount 建表 原始表 create table docs(line string); 结果表 create table wc(word string, totalword int); 加载数据 load data local inpath '/tmp/wc' into table docs; 统计数据 查询结果
hive参数
hive当中的参数、变量,都是以命名空间开头 通过${}方式进行引用,其中system、env下的变量必须以前缀开头 hive 参数设置方式 修改配置文件 加载数据 修改配置文件 ${HIVE_HOME}/conf/hive-site.xml key-value 启动hive cli时,通过--hiveconf key=value的方式进行设置 使用set命令 进入cli之后,通过使用set命令设置 hive set命令 在hive CLI控制台可以通过set对hive中的参数进行查询、设置 set设置: set hive.cli.print.header=true; set查看 set hive.cli.print.header hive参数初始化配置 当前用户家目录下的.hiverc文件 如: ~/.hiverc 如果没有,可直接创建该文件,将需要设置的参数写到该文件中,hive启动运行时,会加载改文件中的配置。 hive历史操作命令集 ~/.hivehistory
动态分区
开启支持动态分区 set hive.exec.dynamic.partition=true; 默认:false set hive.exec.dynamic.partition.mode=nostrict; 默认:strict(至少有一个分区列是静态分区) 严格模式 相关参数 set hive.exec.max.dynamic.partitions.pernode; 每一个执行mr节点上,允许创建的动态分区的最大数量(100) set hive.exec.max.dynamic.partitions; 所有执行mr节点上,允许创建的所有动态分区的最大数量(1000) set hive.exec.max.created.files; 所有的mr job允许创建的文件的最大数量(100000) 加载数据 from psn21 insert overwrite table psn22 partition(age, sex) select id, name, likes, address, age, sex distribute by age, sex;
hive分桶
什么是hive分桶 分桶表是对列值取哈希值的方式,将不同数据