Java Hive GUDF自定义解压功能测试用例失败,出现错误“0”;B不能强制转换为org.apache.hadoop.io.BytesWritable“;
我正在为通用UDF自定义解压求值函数编写测试用例,该函数用于解压zip文件。此jar用于Hivequery。 这里是测试用例的代码Java Hive GUDF自定义解压功能测试用例失败,出现错误“0”;B不能强制转换为org.apache.hadoop.io.BytesWritable“;,java,hadoop,hive,hiveql,Java,Hadoop,Hive,Hiveql,我正在为通用UDF自定义解压求值函数编写测试用例,该函数用于解压zip文件。此jar用于Hivequery。 这里是测试用例的代码 public void testEvaluate() throws HiveException, IOException { Unzip unzip = new Unzip(); File resourcesDirectory = new File("src/test/resources/test.zip"); byte[
public void testEvaluate() throws HiveException, IOException {
Unzip unzip = new Unzip();
File resourcesDirectory = new File("src/test/resources/test.zip");
byte[] bytes = Files.readAllBytes( resourcesDirectory.toPath() );
ObjectInspector binaryOI = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
ObjectInspector[] arguments = {binaryOI};
unzip.initialize(arguments);
GenericUDF.DeferredObject valueObj0 = new GenericUDF.DeferredJavaObject(bytes);
GenericUDF.DeferredObject[] args = { valueObj0 };
unzip.evaluate(args );}
我得到如下错误
java.lang.ClassCastException: [B cannot be cast to org.apache.hadoop.io.BytesWritable
at org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableBinaryObjectInspector.getPrimitiveJavaObject(WritableBinaryObjectInspector.java:49)
at Unzip.evaluate(Unzip.java:32)
at UnzipTest.testEvaluate(UnzipTest.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
从延迟对象[]args读取字节时,第行出现错误,
- byte[] input = elementOI.getPrimitiveJavaObject( arg[0].get() );
PS:test.zip包含一个压缩到test.zip的文本文件(带有测试字符串)。在您的情况下,您需要使用Hive可以使用的可写文件来包装
字节[]
。BytesWritable
。如你所见 尝试而不是
GenericUDF.DeferredObject valueObj0=新的GenericUDF.DeferredJavaObject(字节);
请执行以下操作:
GenericUDF.DeferredObject valueObj0=new GenericUDF.DeferredJavaObject(new byteswriteable(bytes));
在本地复制您的案例时,我能够成功地在UDF
evaluate
方法中检索到byte[]
。谢谢,在转换为bytes writable之后,它就工作了。我后来找到了它。