Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cceazj opened this issue Jul 10, 2023 · 0 comments

Comments

@cceazj
Copy link

cceazj commented Jul 10, 2023

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 cceazj changed the title UDFArrayIntersect代码存在bug,会出现数组越界异常或者出现错误返回值。 UDFArrayIntersect代码逻辑有问题,会出现数组越界异常或者出现错误返回值。 Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant