hive-third-functions icon indicating copy to clipboard operation
hive-third-functions copied to clipboard

UDFArrayIntersect代码逻辑有问题,会出现数组越界异常或者出现错误返回值。

Open cceazj opened this issue 1 year ago • 0 comments

https://github.com/aaronshan/hive-third-functions/blame/f98fef86d328882c85ea40b69b14375d90d44201/src/main/java/com/github/aaronshan/functions/array/UDFArrayIntersect.java#L160 select default.array_intersect(array("39236600","38943350","39007633"),array("39236600","38943350","39007633","38593565","39165420","39119191","39223090","39273131","39113697","39264583","38643724","39243639","39273301","39153039","39152750","38422867","39194210")); 返回值应该是{"39236600","38943350","39007633"},但实际上只返回了一个。

查看了代码,发现compare方法逻辑错误,应修复为一下: private int compare(ListObjectInspector arrayOI, Object array, int[] positions, int position1, int position2) { ObjectInspector arrayElementOI = arrayOI.getListElementObjectInspector(); Object arrayElementTmp1 = arrayOI.getListElement(array, positions[position1]); Object arrayElementTmp2 = arrayOI.getListElement(array, positions[position2]); return ObjectInspectorUtils.compare(arrayElementTmp1, arrayElementOI, arrayElementTmp2, arrayElementOI); } 即参数中增加int[] positions,传递进来leftPositions或者rightPositions,相应方法调用出也需一并修改。

cceazj avatar Jul 10 '23 11:07 cceazj