ggangadharan opened a new pull request, #6861:
URL: https://github.com/apache/hive/pull/6861
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA:
https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a
faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section
is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other
DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Adds a vectorized evaluator for `ntile(n)`, so a PTF operator that uses
ntile no longer forces its reducer into row mode.
- **`VectorPTFEvaluatorNTile`** (new): a group-aggregated streaming
evaluator, like `cume_dist` / `percent_rank`. The partition is buffered so its
size is known, then bucket numbers are derived on the fly while the batches are
replayed. State is O(1) per partition (no per-row array), and a batch that
falls entirely within one bucket is emitted as a repeating vector. The bucket
layout matches `GenericUDAFNTile`: the first `partitionSize % n` buckets get
one extra row.
- **`VectorPTFDesc`**: registers `NTILE` and adds it to
`COLUMN_AGNOSTIC_FUNCTIONS`, since its argument is a constant rather than an
input column.
- **`Vectorizer`**: vectorizes ntile only when the number of buckets is a
positive int constant. Row mode also accepts a non-c
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Part of HIVE-24872 (PTF vectorization coverage). Until now, any PTF
containing ntile ran its whole reducer in row mode:
```
notVectorizedReason: PTF operator: ntile not in supported functions [avg,
count, cume_dist, dense_rank, first_value, lag, last_value, lead, max, min,
percent_rank, rank, row_number, sum]
```
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as
the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes
- provide the console output, description, screenshot and/or a reproducible
example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to
the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No change in query results. Queries using `ntile(<constant>)` can now run
with a vectorized reducer, which is visible in EXPLAIN:
```sql
explain vectorization detail
select name, rowindex, mynumber,
ntile(4) over (partition by name order by mynumber) as nt
from vector_ptf_ntile_int;
```
- Before: `Reducer 2` shows `Execution mode: llap` and the
`notVectorizedReason` above.
- After: `Reducer 2` shows `Execution mode: vectorized, llap` and
`evaluatorClasses: [VectorPTFEvaluatorNTile]`.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some
test cases that check the changes thoroughly including negative and positive
cases if possible.
If it was tested in a way different from regular unit tests, please clarify
how you tested step by step, ideally copy and paste-able, so that other
reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why
it was difficult to add.
-->
- **New unit test `TestVectorPTFEvaluatorNTile`** (17 tests): compared
against the `GenericUDAFNTile` algorithm for partition sizes 0-25 x 1-10
buckets x several batch sizes; repeating and non-repeating output; reuse across
partitions; a ~100M-row partition; error cases.
- **New qtest `vector_ptf_ntile.q`**: every query runs with PTF
vectorization off and then on, with identical results. Covers partitioned,
unpartitioned and `over ()` windows, more buckets than rows, a NULL partition,
NULL order keys, ntile mixed with `rank` / `cume_dist` / `sum` in one PTF
operator, and the non-constant fallback. The reducer batch size is 2 so bucket
boundaries fall across batches.
- **Updated q files**, with no result changes: `vector_windowing.q.out`
(ntile is now in the supported list; that query is now blocked by `stddev_pop`)
and `sketches_materialized_view_ntile.q.out` (one reducer is now vectorized).
```
mvn test -pl ql -Dtest=TestVectorPTFEvaluatorNTile,TestVectorPTFGroupBatches
mvn test -Pitests -pl itests/qtest -Dtest=TestMiniLlapLocalCliDriver \
-Dqfile=vector_ptf_ntile.q,vector_windowing.q,windowing.q,windowing_ntile.q,ptf_decimal.q,cbo_rp_windowing_2.q,lineage_ptf.q,sketches_materialized_view_ntile.q
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]