Skip to content

HIVE-28196: Preserve column stats when applying UDF upper/lower - #5191

Merged
deniskuzZ merged 3 commits into
apache:masterfrom
ngsg:HIVE-28196-Preserve-column-stats-after-upper-lower
Apr 29, 2024
Merged

HIVE-28196: Preserve column stats when applying UDF upper/lower#5191
deniskuzZ merged 3 commits into
apache:masterfrom
ngsg:HIVE-28196-Preserve-column-stats-after-upper-lower

Conversation

@ngsg

@ngsg ngsg commented Apr 11, 2024

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This patch preserves column stats when applying UDF upper/lower on a column.

Why are the changes needed?

Current Hive re-estimates column stats when it encounters UDF. UDF upper and lower do not change column stats, but current Hive resets avgColLen to hive.stats.max.variable.length. Keeping the input data's column stats, including avgColLen, will give more accurate stats to later query optimizers and make a better query plan.

Does this PR introduce any user-facing change?

No

Is the change a dependency upgrade?

No

How was this patch tested?

Added a qfile for testing column stats computation on upper/lower UDF. Current Hive chooses MergeJoin due to column stats over-estimation, while this patch chooses MapJoin.

@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, but we have to update some .q.out of failing test cases.

GenericUDF udf = engfd.getGenericUDF();
Class udfClass =
(udf instanceof GenericUDFBridge) ? ((GenericUDFBridge)udf).getUdfClass() : udf.getClass();
return udfClass == GenericUDFLower.class || udfClass == GenericUDFUpper.class;

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 like this PR. I have also observed that an estimation was wrong, and Map Join was disabled.
We implement some estimation APIs on the UDF side. I'll share examples with you. This is not a strong suggestion, and the current implementation seems to be a good starting point. We may finally need a pluggable I/F to empower custom UDFs more.

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.

Thanks for sharing the examples. I moved the estimation logic to UDF side by using StatEstimatorProvider interface.

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 didn't know the interface and looks super nice!

@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.

mv_iceberg_orc5 failed, but the PR looks mostly good to me

@deniskuzZ deniskuzZ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM +1, pending tests
note: mv_iceberg_orc5 fails in master as well, looks like flaky

@zhangbutao

Copy link
Copy Markdown
Contributor

LGTM +1, pending tests note: mv_iceberg_orc5 fails in master as well, looks like flaky

mv_iceberg_orc5.q is flaky. Please see https://issues.apache.org/jira/browse/HIVE-28203

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

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