gpt4 book ai didi

java - 失败:SemanticException [错误10014]:行1:21错误的参数 'stock_price_high':

转载 作者:行者123 更新时间:2023-12-02 20:47:07 25 4
gpt4 key购买 nike

我是Hive的新手,我正在尝试在Hive命令行中创建和使用UDF。

我创建了一个Java代码来根据样本NYSE数据集计算股票的协方差。以下是Java中的代码:

package udf;

import org.apache.hadoop.hive.ql.exec.UDF;

public class CoVariance extends UDF {
public Double covariance (Double stockpricex, Double stockpricey, Double avgstockpricex, Double avgstockpricey, int tuplecount) {

if (stockpricex == null|| stockpricey == null || avgstockpricex == null || avgstockpricey == null || tuplecount == 0 ) {
return null;
} //check for invalid parameters

Double covar = ((stockpricex-avgstockpricex)*(stockpricey-avgstockpricey)/(tuplecount - 1));

return covar.doubleValue();
} // return the final co-variance of the stocks

} // end of class

将jar文件添加到配置单元 shell 后,我创建了一个名为“cv”的临时函数并传递了参数。
select stock_symbol, cv(stock_price_high, stock_price_low, avg(stock_price_high), avg(stock_price_low), count(stock_price_high)) from nyse group by stock_symbol, stock_price_high, stock_price_low;

我得到以下错误:

FAILED: SemanticException [Error 10014]: Line 1:21 Wrong arguments 'stock_price_high': No matching method for class udf.CoVariance with (double, double, double, double, bigint). Possible choices:



这是怎么了?您的帮助将不胜感激。

最佳答案

不清楚如何注册UDF,但是JavaDoc表示

Requirements for all classes extending this UDF are:
- Implement one or more methods named evaluate which will be called by Hive



您的方法 covariance应该重命名为 evaluate
根据Hive错误, int tuplecount应该是 longBigInteger

关于java - 失败:SemanticException [错误10014]:行1:21错误的参数 'stock_price_high':,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47520736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com