【问题标题】:hive udf execution via shell script通过 shell 脚本执行 hive udf
【发布时间】:2016-05-13 11:31:35
【问题描述】:

我有一个在 hive 终端中运行良好的 Hive Udf,我想要通过 shell 脚本执行它。 在蜂巢终端上,我可以执行以下命令:

use mashery_db;
add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';

但是当我在 shell 脚本中添加上述代码时

hive -e "use mashery_db;"
hive -e "add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;"
hive -e "add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;"
hive -e "CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

第一个“hive -e”运行良好并添加了 jar,但最后一个创建临时函数不起作用。我收到以下错误:

FAILED: ParseException line 1:35 mismatched input 'com' expecting StringLiteral near 'AS' in create function statement

我也试过用单引号

hive -e "CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

然后我得到FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask

FAILED: Class com.mashery.nextdata.hive.udf.GeoIPGenericUDF not found

hive Udf 是否支持 shell 脚本,如果它做错了我在做什么。提前致谢

【问题讨论】:

  • 尝试导入 jar 并在一次调用 hive 中创建函数。即hive -e "add jar path_to_jar/foo.jar; create temporary function foo as 'com.package.UDF';"
  • @GoBrewers14 谢谢它对我有用 :-)

标签: shell hive udf


【解决方案1】:

hive -e 的每次调用都会产生一个新进程,该进程带有一个新的 hive shell,它不记得前一个做了什么,所以 hive '忘记' UDF 在哪里...... 一种解决方案是将它们链接在一个命令中,但最好将所有配置单元命令放在一个文件中(例如“commands.hql”)并使用hive -f commands.hql 而不是 -e .

文件看起来像这样:

use mashery_db;
add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"

【讨论】:

    【解决方案2】:

    您可以使用hive -ehive -f

    hive -e "use mashery_db;
    add jar hdfs://nameservice1/tmp/nextdata_aggregations/custom_jar/readerCheck.jar;
    add file hdfs://nameservice1/tmp/GeoLite2-City.mmdb;
    CREATE TEMPORARY FUNCTION geoip AS 'com.mashery.nextdata.hive.udf.GeoIPGenericUDF';"
    

    将它们创建为文件并使用hive -f hive_file.hql 也可以。

    【讨论】:

      猜你喜欢
      • 2014-10-06
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2015-11-01
      • 2018-02-19
      • 1970-01-01
      相关资源
      最近更新 更多