-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/cc/shanruifeng/functions/array/UDFArrayIntersectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cc.shanruifeng.functions.array; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Iterables; | ||
import org.apache.hadoop.hive.ql.metadata.HiveException; | ||
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author ruifeng.shan | ||
* @date 2018-07-18 | ||
* @time 13:00 | ||
*/ | ||
public class UDFArrayIntersectTest { | ||
@Test | ||
public void testArrayIntersect() throws HiveException { | ||
UDFArrayIntersect udf = new UDFArrayIntersect(); | ||
|
||
ObjectInspector leftArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaIntObjectInspector); | ||
ObjectInspector rightArrayOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaIntObjectInspector); | ||
ObjectInspector[] arguments = {leftArrayOI, rightArrayOI}; | ||
|
||
udf.initialize(arguments); | ||
|
||
assertTrue(Iterables.elementsEqual(ImmutableList.of(1,2,5), evaluate(ImmutableList.of(0,1,2,3,4,5), ImmutableList.of(1,1,2,2,5,5), udf))); | ||
assertTrue(Iterables.elementsEqual(ImmutableList.of(1,2,3,4), evaluate(ImmutableList.of(0,1,2,3,4,4), ImmutableList.of(1,1,2,2,3,4), udf))); | ||
assertTrue(Iterables.elementsEqual(ImmutableList.of(1,2,3,4), evaluate(ImmutableList.of(0,1,1,2,3,4,4), ImmutableList.of(1,1,2,2,3,4), udf))); | ||
} | ||
|
||
private ArrayList<Object> evaluate(List<Integer> leftArray, List<Integer> rightArray, UDFArrayIntersect udf) throws HiveException { | ||
GenericUDF.DeferredObject leftArrayObj = new GenericUDF.DeferredJavaObject(leftArray); | ||
GenericUDF.DeferredObject rightArrayObj = new GenericUDF.DeferredJavaObject(rightArray); | ||
GenericUDF.DeferredObject[] args = {leftArrayObj, rightArrayObj}; | ||
ArrayList<Object> output = (ArrayList<Object>) udf.evaluate(args); | ||
return output; | ||
} | ||
} |
277be74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我也update一下.