写hive sql和shell脚本时遇到几个蛋疼的问题!

错误一:

Hive的where后不能用字段的别名,

 

错误二:

hive的groupby中不能用自己定义函数,否则报错(用嵌套select取代)

 

错误三:

运行:$ ./hive_game_operationstatis5.sh时,报错信息例如以下:

./hive_game_operationstatis5.sh:line 11: [: missing `]'
./hive_game_operationstatis5.sh:line 17: /tmp/statis_activitysourcestatis20141014/statis_activitysourcestatis120141014.txt:No such file or directory
./hive_game_operationstatis5.sh:line 36:/tmp/statis_activitysourcestatis20141014/statis_activitysourcestatis220141014.txt:No such file or directory
ERROR 2 (HY000) atline 1: File'/tmp/statis_activitysourcestatis20141014/statis_activitysourcestatis120141014.txt'not found (Errcode: 2)
ERROR 2 (HY000) atline 1: File'/tmp/statis_activitysourcestatis20141014/statis_activitysourcestatis220141014.txt'not found (Errcode: 2)

错误分析:

因为11行的创建文件夹代码没起作用,所以导致后边一系列找不到文件路径的错误。

 

报错时的代码:

if [ ! -d $output]
then
        mkdir -p $output
fi<span style="font-family: Arial, Helvetica, sans-serif;"> </span>

改动后的代码:

if [ ! -d $output]
then
        mkdir -p $output
fi

看到区别了没??$output与]之间应该有个空格!

 

错误四:date不能识别

运行./hive_game_operationstatis6.sh脚本时。报错例如以下:

./hive_game_operationstatis6.sh:line 12: [: /tmp/statis_suspendedwindowstatisdate: binary operator expected
./hive_game_operationstatis6.sh:line 21: $output/$file_name1: ambiguous redirect
./hive_game_operationstatis6.sh:line 39: $output/$file_name2: ambiguous redirect
./hive_game_operationstatis6.sh:line 56: $output/$file_name3: ambiguous redirect
./hive_game_operationstatis6.sh:line 73: $output/$file_name4: ambiguous redirect
./hive_game_operationstatis6.sh:line 90: $output/$file_name5: ambiguous redirect
 

分析:

在shell脚本中我是这样写:

output='/tmp/statis_suspendedwindowstatis'$date
file_name1='statis_suspendedwindowstatis1'$date'.txt'

错误显示是指调用时”模糊的重定向”!

 

单从错误提示上看不出个所以然来。请直接看出错代码:

 

改动之前代码:

date=’date +%Y%m%d’

改动此bug之后代码:

date=`date +%Y%m%d`

 

大家看到哪里出错了没??哈哈,是的,太坑啦!

shell要用键盘上1前边的‘撇’,而不能用双引號那个‘撇’儿。

假设一个变量后是字符串的话直接用回车左边那个’撇‘就能够,

对于我这个初次接触shell的人。简直头疼到了极点!

希望大家不要犯类似的错误。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值