hive基础操作

新建hive表

hive>

    >

    > create table xxx_result(

    > id string,

    > zzz int,

    > yyy string)

    > ROW FORMATDELIMITED

    > FIELDS TERMINATEDBY '\t'

    > STORED AS TEXTFILE;

 

hive> create table post_result(id string, zzz int, yyy string) ROW FORMAT DELIMITED FIELDSTERMINATED BY '\t' STORED AS TEXTFILE;

 

 

查询表结构

hive> show create table www;

 

复制表结构

hive> insert into table xxx_result select id,yyy,zzz from www;

 

hdfs copy数据到本地

hadoop dfs -get hdfs://ns15/... .

 

 

sqoop导入数据

sqoop export --connect jdbc:mysql://ip/mysql_database_name--username jnlu -P --table post_result --fields-terminated-by '\t'--export-dir "hdfs://ns15/..."


导入elasticsearch

#!/usr/bin/env bash


set -x
set -e


target_date=`date -d last-day +%Y-%m-%d`
echo "target_date = " $target_date


pig \
-useHCatalog \
-Dmapreduce.job.cache.archives='/user/mart_tbi/xxx/data/jnlu_data.zip#yyy_data' \
-Dmapreduce.job.acl-view-job=* \
-Dmapreduce.job.queuename=root.bdp_jmart_tbi_union.bdp_jmart_tbi_dev \
-Dmapred.create.symlink=yes \
-Dmapred.child.java.opts='-Xmx8192m ' \
-p start_date=$target_date \
-p target_date=$target_date \
es_recovery.pig 2>&1


echo 'DONE!'


REGISTER datafu-pig-incubating-1.3.1.jar;
REGISTER elasticsearch-hadoop-pig-5.4.1.jar;




DEFINE EsStorage org.elasticsearch.hadoop.pig.EsStorage (
    'es.http.timeout= 5m',
    'es.index.auto.create = true',
    'es.nodes = es ip',
    'es.mapping.id = id',
    'es.mapping.pig.tuple.use.field.names = true',
    'es.write.operation = upsert');
                                                                                            
raw_data = LOAD 'hivedb.hiveTable' USING org.apache.hive.hcatalog.pig.HCatLoader() As (
                 album_id:CHARARRAY,,
                 dt:CHARARRAY);


--DUMP raw_data;


es_data = FOREACH raw_data GENERATE (chararray)$7 as id,(int)$16 as popularity_new, (chararray)$17 as norm_name;




STORE es_data INTO ‘esIndex/esType’' USING EsStorage;


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值