【问题标题】:Storing hive query output in a shell script variable将 hive 查询输出存储在 shell 脚本变量中
【发布时间】:2017-11-03 06:47:18
【问题描述】:

当我尝试通过 shell 脚本执行以下 2 个查询时,我无法回显输出:

查询:

close_val=`hive -e "select count(1) from tst_db.dim_calendar where calendar_id =20171102"`
close_val=$(hive -S -e "USE cars_dev; select count(1) from dim_calendar where calendar_id =20171103")

echo $close_val

错误:

2017-11-03 00:55:11,505 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.input.dir.recursive 已弃用。相反,使用 mapreduce.input.fileinputformat.input.dir.recursive 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.max.split.size 是已弃用。相反,使用 mapreduce.input.fileinputformat.split.maxsize 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.min.split.size 已弃用。相反,使用 mapreduce.input.fileinputformat.split.minsize 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.min.split.size.per。机架已弃用。相反,使用 mapreduce.input.fileinputformat.split.minsize.per.rack 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.min.split。 size.per.node 已弃用。相反,使用 mapreduce.input.fileinputformat.split.minsize.per.node 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.reduce.tasks已弃用。相反,使用 mapreduce.job.reduces 2017-11-03 00:55:11,508 INFO [main] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(1011)) - mapred.reduce.tasks.speculative.execution 已弃用。相反,使用 mapreduce.reduce.speculative 2017-11-03 00:55:11,715 WARN [main] conf.HiveConf (HiveConf.java:initialize(1155)) - 已弃用:配置属性 hive.metastore.local 不再有任何效果.如果要连接到远程元存储,请确保为 hive.metastore.uris 提供有效值。 1 ./run_daily_jobs_night.sh:第 42 行:[:参数太多

【问题讨论】:

    标签: bash shell hadoop hiveql


    【解决方案1】:

    我不确定您期望对 close_val 值做什么,但在您的情况下,您似乎期望得到一个数字,但似乎 hive 中存在问题,而您得到的是堆栈跟踪。 收到的跟踪不是一个简单的字符串,而是被视为您的 echo 的几个参数,超出了它处理的数量。

    使用如下命令:

    $ # Notice the cut at the end of the command
    $ close_val=$(hive -S -e "USE cars_dev; select count(1) from dim_calendar where calendar_id =20171103" | cut -f 1)
    

    将确保您的 echo 命令能够正常工作,但在这里您真正的问题是您的 hive 命令失败了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      相关资源
      最近更新 更多