【问题标题】:How to load Hbase table with shell script如何使用 shell 脚本加载 Hbase 表
【发布时间】:2018-01-20 09:51:48
【问题描述】:

我是大数据的学习者,我正在尝试将文件加载到 Hbase 表中。文件内容看起来像 -

U100,A300&A301&A302    
U101,A301&A302    
U102,A302    
U103,A303&A301&A302

此文件存在于本地文件系统中。我想要的是将这些数据加载到 Hbase 表中,如下所示-

我正在尝试下面的脚本,但无法获得这个确切的输出-

echo "create 'uid-map', 'users'" | hbase shell
file="/home/abc/lookupfiles/uid.txt"
touch /home/abc/lookupfiles/uid1.txt
chmod 775 /home/abc/lookupfiles/uid1.txt
file1="/home/abc/lookupfiles/uid1.txt"
awk '$1=$1' FS="&" OFS=" " $file > $file1
num=1
while IFS= read -r line
do
 uid=`echo $line | cut -d',' -f1`
 users=`echo $line | cut -d'&' -f2`
 for row in $users
 do
 #artist= 'echo $row | cut -d',' -f$num
 echo "put 'uid-map', '$uid', 'users:artist$num', '$row'" | hbase shell
 let "num=num+1"
done
num=1
done <"$file"

我得到的输出是-

请让我知道我做错了什么。

【问题讨论】:

    标签: linux shell awk hbase bigdata


    【解决方案1】:

    单一Awk程序的优化解决方案:

    echo "create 'uid-map', 'users'" | hbase shell
    awk -F'[,&]' -v cmd="hbase shell" '{
            fmt="put \047uid-map\047, \047%s\047, \047users:artist%d\047, \047%s\047\n";
            for (i=2; i<=NF; i++) 
                printf(fmt, $1, ++c, $i ) | cmd; 
            c=0 
        }' "$file"
    

    将传递给hbase shell 的输出(每次调用... | cmd 一行):

    put 'uid-map', 'U100', 'users:artist1', 'A300'
    put 'uid-map', 'U100', 'users:artist2', 'A301'
    put 'uid-map', 'U100', 'users:artist3', 'A302'
    put 'uid-map', 'U101', 'users:artist1', 'A301'
    put 'uid-map', 'U101', 'users:artist2', 'A302'
    put 'uid-map', 'U102', 'users:artist1', 'A302'
    put 'uid-map', 'U103', 'users:artist1', 'A303'
    put 'uid-map', 'U103', 'users:artist2', 'A301'
    put 'uid-map', 'U103', 'users:artist3', 'A302'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多