Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyongyongyong committed Apr 14, 2023
1 parent f1bf0df commit b4cbcba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions readme/array/udf/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ create temporary function array_intersect as "org.thomas.hive.udf.ArrayIntersect
-- select array_intersect(`array`(5,1,2,8),`array`(2,3,5,7),`array`(5,8)); -- array 交集
-- [5]
create temporary function array_index_of as "org.thomas.hive.udf.ArrayIndexOfUDF";
-- select array_index_of(`array`(11,22,33,44),33); -- 返回指定元素在数组列中的index. index从0开始. 不存在则返回 -1
-- 2
create temporary function array_position as "org.thomas.hive.udf.ArrayIndexOfUDF";
-- select array_position(`array`(11,22,33,44),33); -- 返回指定元素在数组列中的index. index从0开始. 不存在则返回 -1
-- 3
create temporary function array_remove as 'org.thomas.hive.udf.ArrayRemove';
-- select array_remove(`array`(11,22,33,22,100),22,100);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/thomas/hive/udf/ArrayIndexOfUDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public Object evaluate(DeferredObject[] arguments) throws HiveException {
Object listElement = arrayOI.getListElement(array, i);
if (listElement != null) {
if (ObjectInspectorUtils.compare(value, valueOI, listElement, arrayElementOI) == 0) {
result.set(i);
// 这里和spark同名函数保持一致逻辑 返回的index从1开始
result.set(i+1);
break;
}
}
Expand All @@ -94,6 +95,6 @@ public Object evaluate(DeferredObject[] arguments) throws HiveException {
@Override
public String getDisplayString(String[] children) {
assert (children.length == ARG_COUNT);
return "array_index_of(" + children[ARRAY_IDX] + ", " + children[VALUE_IDX] + ")";
return "array_position(" + children[ARRAY_IDX] + ", " + children[VALUE_IDX] + ")";
}
}

0 comments on commit b4cbcba

Please sign in to comment.