Repository navigation
HIVE-30162: PTF: Vectorize ntile with a non-constant number of buckets - #6946
Open
ggangadharan wants to merge 1 commit into
Open
ggangadharan wants to merge 1 commit into
ggangadharan wants to merge 1 commit into
Conversation
|
Contributor
Author
|
@abstractdog could you please review the PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changes were proposed in this pull request?
Vectorize
ntilewhen the number of buckets is not a constant: a column, an expression, or apartition key. Row mode (
GenericUDAFNTile) reads the number of buckets from the first row of eachpartition, and the vectorized path now does the same.
VectorPTFEvaluatorNTile: takes either a constant or a non-constant expression. For anon-constant one, the value is read from row 0 of the partition's first batch when the buffered
batches are replayed for output. Partition key columns are restored at that point, so a
partition key argument works even though it is not buffered. The bucket sizes are set up once per
partition, so nothing is added per row. A constant is still neither evaluated per batch nor
buffered.
Vectorizer: non-constant arguments are now vectorized. A non-positive constant still fallsback to row mode, as before. Lead/lag inside the argument now falls back with an explicit reason.
ntile is in
COLUMN_AGNOSTIC_FUNCTIONS, so that check was skipped for it before.VectorPTFDesc: corrected the comment onCOLUMN_AGNOSTIC_FUNCTIONS, which said these functionsdon't read input columns. ntile now reads its argument, but only from forwarded batches.
Row mode does not validate the number of buckets. The vectorized evaluator returns the same result
wherever row mode returns one, and fails right away wherever row mode fails:
n(partition ofNrows)n > 0n < -N0ArithmeticException: / by zeroHiveException: NTILE requires a positive number of buckets, got: 0NULLNullPointerExceptionHiveException: ... got: NULL-N <= n < 0HiveException: ... got: nWhy are the changes needed?
HIVE-30018 vectorized
ntileonly for a positive int constant. Any other argument made the wholePTF fall back to row mode, with
notVectorizedReason: PTF operator: ntile only supports a positive integer constant number of buckets.This is part of the PTF vectorization coverage effort (HIVE-24872).
Does this PR introduce any user-facing change?
No, Released Hive versions do not vectorize
ntileat all.ntile(col) over (...)now run vectorized, with the same results as row mode.Example:
notVectorizedReasonabove.After: the reducer runs
VectorPTFOperatorwithfunctionInputExpressions: [col 1:int]. Thequery returns
a: 1 2 3 3(3 buckets) andb: 1 1(2 buckets) in both modes.magnitude than the partition), the query still fails, as in row mode. The error is now a clear
HiveException, and the negative case fails immediately instead of running out of memory.No configuration changes.
How was this patch tested?
New and updated qtests:
clientpositive/vector_ptf_ntile.q: every non-constant case runs in row mode and vectorized modewith identical results. A new table holds each partition's number of buckets in its first row,
with NULL, 0 and negative values in the later rows that must never be read.
rows; more than rows (the largest int); a negative count larger in magnitude than the
partition; single-row partitions.
the first row is taken in ORDER BY order rather than insertion order.
disk; constant and non-constant ntile in one PTF alongside
rankandsum.explainshows the row-mode fallback for a non-positive constant and for lead/lag inthe argument.
clientnegative/vector_ptf_ntile_invalid_buckets.q: 0, NULL and-Nin the first row each failwith the vectorized error.
cbo_rp_windowing_2,lineage_ptf,ptf_decimal,sketches_materialized_view_ntile,sketches_rewrite_ntile,sketches_rewrite_ntile_partition_by,vector_ptf_buffered_complex_scratch_col,vector_ptf_ntile,vector_windowing,windowing,windowing_ntile,vector_ptf_1,vector_ptf_cume_dist,vector_ptf_percent_rank,vector_ptf_unbuffered_partition_col,vector_ptf_spill_partition_order_overlap,vector_ptf_part_simple,vector_ptf_nested_input_expr,vector_ptf_lead_lag,vector_windowing_rank,vector_windowing_expressions.To reproduce: