Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 配置单元UDF:配置单元未向UDF发送正确的参数_Java_Hadoop_Hive_Hiveql - Fatal编程技术网

Java 配置单元UDF:配置单元未向UDF发送正确的参数

Java 配置单元UDF:配置单元未向UDF发送正确的参数,java,hadoop,hive,hiveql,Java,Hadoop,Hive,Hiveql,这是我的蜂箱桌 CREATE TABLE `dum`(`val` map<string,array<string>>); insert into dum select map('A',array('1','2','3'),'B',array('4','5','6')); 我正在尝试创建一个简单的UDF,它可以将上面映射的值中的所有项合并到一个列表中。这是我想看的 select modudf(val) from dum; ["1","2&qu

这是我的蜂箱桌

CREATE TABLE `dum`(`val` map<string,array<string>>);
insert into dum select map('A',array('1','2','3'),'B',array('4','5','6'));
我正在尝试创建一个简单的UDF,它可以将上面映射的值中的所有项合并到一个列表中。这是我想看的

select modudf(val) from dum;
["1","2","3","4","5","6"]
所以我创造了

package some.package;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.udf.UDFType;
import java.util.ArrayList;

import java.util.List;
import java.util.Map;

@UDFType(deterministic = true)
public class CustomUDF extends UDF {

public List<String> evaluate(Map<String, String[]> inMap) {

            ArrayList<String> res = new ArrayList<String>();
                for(Map.Entry<String, String[]> ent : inMap.entrySet()){
                    for(String item : ent.getValue())
                        res.add(item);
            }
        return res;
   }
}
我明白了

但我还是会

hive> add jar /path/to/my/jar;
Added [/path/to/my/jar] to class path
Added resources: [/path/to/my/jar]
hive> CREATE TEMPORARY FUNCTION modudf AS 'some.package.CustomUDF';
hive> desc dum;
OK
val                     map<string,array<string>>
Time taken: 0.094 seconds, Fetched: 1 row(s)
hive> select val from dum;
Query ID = root_20200629170147_80b5248f-4519-4dae-a070-3c5185f742ea
Total jobs = 1
Launching Job 1 out of 1
Status: Running (Executing on YARN cluster with App id application_1593449512239_0001)

----------------------------------------------------------------------------------------------
        VERTICES      MODE        STATUS  TOTAL  COMPLETED  RUNNING  PENDING  FAILED  KILLED
----------------------------------------------------------------------------------------------
Map 1 .......... container     SUCCEEDED      1          1        0        0       0       0
----------------------------------------------------------------------------------------------
VERTICES: 01/01  [==========================>>] 100%  ELAPSED TIME: 6.12 s
----------------------------------------------------------------------------------------------
OK
{"A":["1","2","3"],"B":["4","5","6"]}
Time taken: 10.631 seconds, Fetched: 1 row(s)
hive> select modudf(val) from dum;
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'val': No matching method for class com.walmart.labs.search.sib.gcp.ModularTransformUDF with (map<string,array<string>>). Possible choices: _FUNC_(map<struct<>,array<struct<>>>)
参见以下引文:

请注意,配置单元阵列在配置单元中表示为列表。因此,数组列将作为列表传入


因此,您应该使用evaluateMap inMap签名,而不是evaluateMap inMap。

谢谢您的建议。请查看更新。我还是会犯同样的错误你有没有试着用这个签名:public List evaluateMap inMap?因为将字符串更改为CharSequence对我来说毫无意义嘿,这很有效!由于其他一些代码依赖性,我使用了Charsequence,但我不必这样做。谢谢
add jar /path/to/my/jar;
CREATE TEMPORARY FUNCTION modudf AS 'some.package.CustomUDF';
select modudf(val) from dum;
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'val': No matching method for class some.package.CustomUDF with (map<string,array<string>>). Possible choices: _FUNC_(map<struct<>,struct<>>)
public List<CharSequence> evaluate(Map<CharSequence, List<CharSequence>> inMap) {

        modLogger.info(inMap);
            ArrayList<CharSequence> res = new ArrayList<CharSequence>();
                for(Map.Entry<CharSequence, List<CharSequence>> ent : inMap.entrySet()){
                    for(CharSequence item : ent.getValue())
                        res.add(item);
            }
        return res;
   }
}
hive> add jar /path/to/my/jar;
Added [/path/to/my/jar] to class path
Added resources: [/path/to/my/jar]
hive> CREATE TEMPORARY FUNCTION modudf AS 'some.package.CustomUDF';
hive> desc dum;
OK
val                     map<string,array<string>>
Time taken: 0.094 seconds, Fetched: 1 row(s)
hive> select val from dum;
Query ID = root_20200629170147_80b5248f-4519-4dae-a070-3c5185f742ea
Total jobs = 1
Launching Job 1 out of 1
Status: Running (Executing on YARN cluster with App id application_1593449512239_0001)

----------------------------------------------------------------------------------------------
        VERTICES      MODE        STATUS  TOTAL  COMPLETED  RUNNING  PENDING  FAILED  KILLED
----------------------------------------------------------------------------------------------
Map 1 .......... container     SUCCEEDED      1          1        0        0       0       0
----------------------------------------------------------------------------------------------
VERTICES: 01/01  [==========================>>] 100%  ELAPSED TIME: 6.12 s
----------------------------------------------------------------------------------------------
OK
{"A":["1","2","3"],"B":["4","5","6"]}
Time taken: 10.631 seconds, Fetched: 1 row(s)
hive> select modudf(val) from dum;
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments 'val': No matching method for class com.walmart.labs.search.sib.gcp.ModularTransformUDF with (map<string,array<string>>). Possible choices: _FUNC_(map<struct<>,array<struct<>>>)