Repository navigation
HIVE-25123: Implement vectorized streaming lead/lag - #6997
Open
ggangadharan wants to merge 3 commits into
Open
ggangadharan wants to merge 3 commits into
ggangadharan wants to merge 3 commits into
Conversation
|
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?
HIVE-25123 asks for vectorized lead/lag evaluators that stream their results where possible. Today both are buffered evaluators: every row goes through
runOnRange, and each value is boxed and stored inPartitionResultsbefore it is unboxed into the output column.Evaluators (package
org.apache.hadoop.hive.ql.exec.vector.ptf)lag()is a pure streaming evaluator. It writes its output while batches are streamed. It keeps only the lastamtinput values of the partition in a ring buffer, which is allocated lazily and capped atamtrows, so it can look back into earlier batches. Each batch is handled in three parts:amtback get the default value;System.arraycopy.When every window function of the PTF streams (lag, row_number, rank, first_value, running sum/min/max/avg), the partition is no longer buffered or spilled.
lead()cannot stream, because it needs rows that arrive later. While the partition is buffered, it collects its input values into a primitive column vector through a new hook,VectorPTFEvaluatorBase#onBufferGroupBatch. It skips the firstamtrows, which are nobody's lead. When the batches are forwarded, it writes its results with at most two bulk copies per batch.Both evaluators support LONG, DOUBLE and DECIMAL column vectors, so tinyint, smallint, int, bigint, boolean, date, float, double and decimal arguments are covered. Copies are type-specialised, with no per-row allocation or boxing.
Default value (3rd argument)
Vectorizer. It uses the sameObjectInspectorConvertersconversion as row mode (GenericUDAFLeadLag), and a missing default means NULL.ConvertDecimal64ToDecimal. The default is evaluated on every incoming batch together with the input expressions, before the batch is buffered. This uses the newVectorPTFEvaluatorBase#getInputVecExprs, whichVectorPTFOperatoruses for evaluation, transient init and buffering of the scratch columns.lag default value must be a constant or have the same type as its first argument.Other changes
Vectorizer: lag/lead are exempt from the "argument references partition-only column" restriction, like ntile. They read their arguments only from incoming or forwarded batches, and both carry the partition columns.VectorPTFOperator#process: the evaluator reset after the last group batch of a PARTITION BY-only window now runs only when all evaluators stream. Buffered evaluators are reset incleanupPartitionafter the partition is forwarded. Resetting them earlier would drop the values lead collected while buffering.VectorPTFGroupBatches.PartitionResultsno longer allocates a per-rowObject[]for streaming evaluators, since they write into the forwarded batches directly. This helps lead/lag as well as cume_dist, percent_rank and ntile.Example:
Why are the changes needed?
PartitionResultsand unbox it again for every row. Both now do a few bulk copies per batch.ConstantVectorExpression#getLongValue(), whatever its type, so constants were not converted to the argument type the way row mode does. Examples:lag(double_col, 1, 1.5),lag(dec_col, 1, 2.345), aNULLdefault, or a string default like'12'.IdentityExpressionnor a constant threwRuntimeExceptionat runtime. That includes a DECIMAL_64 column such aslag(dc, 1, dc)on adecimal(10,2)column, which is wrapped inConvertDecimal64ToDecimal.fillGroupResults, which can fail with aClassCastException.Does this PR introduce any user-facing change?
No change in query results, except that vectorized lead/lag default values now match row mode. Other changes are visible in plans:
streamingColumns. PTFs whose window functions all stream now showallEvaluatorsAreStreaming: true.How was this patch tested?
New qtest
vector_ptf_lead_lag_streaming.q(TestMiniLlapLocalCliDriver). Every scenario runs first withhive.vectorized.execution.ptf.enabled=falseas the row-mode reference, then vectorized, and the results must be identical:amtof 0, larger than a batch, and larger than the partition;hive.vectorized.ptf.max.memory.buffering.batch.count=1;amtup to 2,000, with heavy spilling, then default settings. The row-mode and vectorized results are written to tables and compared row by row with a null-safe full outer join, which returns 0 mismatches, plus checksum aggregates.Regenerated q files , with EXPLAIN-only diffs (
streamingColumns,allEvaluatorsAreStreaming, scratch column types of the converted constants):vector_ptf_bounded_start,vector_ptf_lead_lag,vector_windowing,vector_windowing_expressions,vector_windowing_navfn,vectorized_ptf.These pass without regeneration:
vector_ptf_*,vector_windowing*andvectorized_ptfqtests;ptf,ptf_streaming,windowing,windowing_navfn,leadlagandleadlag_queries;cbo_*windowing*,ptf_decimal,semijoin*,explainuser_1, …), which are unchanged;TestVectorPTFGroupBatches.