Skip to content

HIVE-27482 - Minor issues in array_intersect udf - #4469

Merged
saihemanth-cloudera merged 2 commits into
apache:masterfrom
tarak271:tarak-HIVE-27482
Jul 12, 2023
Merged

HIVE-27482 - Minor issues in array_intersect udf#4469
saihemanth-cloudera merged 2 commits into
apache:masterfrom
tarak271:tarak-HIVE-27482

Conversation

@tarak271

@tarak271 tarak271 commented Jul 5, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

  1. SELECT array(1,2,3),array_intersect(array(1, 2, 3),array(1,3,4)); gives wrong output

[1,3] [1,3]

instead of 

[1,2,3][1,3]

2.  SELECT array_intersect(array(),array()); should give empty array instead of NULL

3.  Error handling when elements of array are not comparable

These fixes were already present on array_except udf whose implementation is identical to array_intersect, Ref: #4090

Why are the changes needed?

Does this PR introduce any user-facing change?

No

Is the change a dependency upgrade?

No

How was this patch tested?

Added qtest files as well as junit test cases

@okumin okumin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I confirmed all test cases generate the same result as Spark SQL. Thanks for the follow-up! It's really helpful.
We need an approval of a committer because I'm not a committer.

ObjectInspector defaultOI = super.initialize(arguments);
checkArgCategory(arguments, ARRAY2_IDX, ObjectInspector.Category.LIST, FUNC_NAME,
org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME); //Array1 is already getting validated in Parent class
if (!ObjectInspectorUtils.compareTypes(arrayOI.getListElementObjectInspector(), ((ListObjectInspector) arguments[ARRAY2_IDX]).getListElementObjectInspector())) { // check if elements of arrays are comparable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: We should add a line break if one line has 120 characters.

@okumin

okumin commented Jul 6, 2023

Copy link
Copy Markdown
Contributor

It'll be good to rerun CI. I guess the failure is unrelated to this change.

@aturoczy aturoczy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change request


Object array = arguments[ARRAY_IDX].get();
Object array2 = arguments[ARRAY2_IDX].get();
if (array == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change it for if (array == null || array2 == null) { } I don't see the value to have separate IF statement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as recommended

return null;
}

List<?> retArray3 = ((ListObjectInspector) argumentOIs[ARRAY_IDX]).getList(array);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you already touch this code I would suggest to change the retArray3 to resultArray or just simple result I think it would be more expressive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed variable names to match their usage

@saihemanth-cloudera saihemanth-cloudera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1. Pending green Ptests. Will approve this PR once it is green.

@aturoczy

aturoczy commented Jul 10, 2023

Copy link
Copy Markdown
Contributor

There is a test failure, but as I see it should be unrelated.

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@saihemanth-cloudera
saihemanth-cloudera merged commit bd02abc into apache:master Jul 12, 2023
yeahyung pushed a commit to yeahyung/hive that referenced this pull request Jul 20, 2023
…a Rama Rao Lethavadla, reviewed by Okumin, Attila Turoczy, Sai Hemanth Gantasala)
tarak271 added a commit to tarak271/hive-1 that referenced this pull request Dec 19, 2023
…a Rama Rao Lethavadla, reviewed by Okumin, Attila Turoczy, Sai Hemanth Gantasala)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants