zoukankan      html  css  js  c++  java
  • data audit on hadoop fs

    最近项目中遇到了存储在HDFS上的数据格式不对,是由于数据中带有
    的字符,程序处理的时候没有考虑到这些情况。历史数据大概有一年的时间,需要把错误的数据或者重复的数据给删除了,保留正确的数据,项目中使用Pig来进行数据处理,所以我写了一个UDF的JAVA类去过滤
    那些错误的数据,把错误的数据和正确的数据分别存了一份,然后写了以下脚本统计数据的Schema和条数,记录下来,以后项目可以参考。

    #!/bin/sh curDir=`cd "$(dirname $0)";pwd` summary(){ files="" printf "job totalQueries goodQueries badQueries " > $2 while read job do if [ -z files ]; then files="$job/par*" else files="$files $job/par*" fi totalQueries=`hadoop fs -text $job/par* | wc -l` goodQueries=`hadoop fs -text /user/chran/txt$job/par* |wc -l` badQueries=`hadoop fs -text /user/chran/txt/error$job/par* | wc -l` #distinctQueries=`hadoop fs -text $job/par* | awk -F 'a' '{ print NF }' | sort | uniq` printf "$job $totalQueries $goodQueries $badQueries " >> $2 done < $1 } check(){ tempDir=$curDir/temp if [ ! -d $tempDir ]; then mkdir -p $tempDir fi #clean up result files output=$tempDir/$2 rm $output if ! hadoop fs -test -d $1 ; then echo "$1 in HDFS doesn't exist" exit -1 fi #list all sub folders folderList=$tempDir/$2.folderlist.temp #hadoop fs -ls $1 | awk '{ print $NF }' | uniq | sort > $folderList hadoop fs -lsr $1 | grep "/[0-9][0-9]$" | grep "00$" | awk '{ print $NF }' | uniq | sort > $folderList summary $folderList $output rm $folderList }
    check "/apps/risk/ars/social/raw/SOCIAL_FACEBOOK_RAW" "check_facebook.output.txt"
  • 相关阅读:
    常见RGB透明度对照表在这
    Android节假日图标动态替换方案
    用两个栈实现队列
    从头到尾打印链表 (链表/栈)
    MySQL常用函数
    找出数组中重复的数字
    两数之和
    java的list的几种排序写法整理(sort的用法)
    Java知识目录
    通过关键词来推荐话题
  • 原文地址:https://www.cnblogs.com/hugeshi/p/3853286.html
Copyright © 2011-2022 走看看