-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-25125:PTF: Vectorize percent_rank function #6752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6db85e
HIVE-25125:PTF: Vectorize percent_rank function
ramitg254 4856aec
nitpicks
ramitg254 fd9d42d
fallback to non vectorized for unbuffered partition col
ramitg254 45083f9
refractored and added q test for it
ramitg254 c0f20c1
updated q file results
ramitg254 5902a28
Limit vector PTF fallback to direct partition-only column arguments
ramitg254 b5b178f
refractored
ramitg254 eb7f026
refractored
ramitg254 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorPercentRank.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hive.ql.exec.vector.ptf; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.apache.hadoop.hive.ql.exec.vector.ColumnVector.Type; | ||
| import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector; | ||
| import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch; | ||
| import org.apache.hadoop.hive.ql.metadata.HiveException; | ||
| import org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef; | ||
|
|
||
| /** | ||
| * Evaluates {@code percent_rank()} as a <b>group-aggregated streaming</b> | ||
| * evaluator. | ||
| * | ||
| * <p> | ||
| * The partition is buffered so {@link #setPartitionSize(int)} is known before | ||
| * output is written. | ||
| * Peer-group rank is tracked incrementally (like | ||
| * {@link VectorPTFEvaluatorRank}) during batch | ||
| * forward; {@link #addStreamingGroupResults} is a no-op because no pre-pass is | ||
| * required. | ||
| */ | ||
| public class VectorPTFEvaluatorPercentRank extends VectorPTFEvaluatorBase { | ||
|
|
||
| private int rank; | ||
| private int groupCount; | ||
|
|
||
| public VectorPTFEvaluatorPercentRank(WindowFrameDef windowFrameDef, int outputColumnNum) { | ||
| super(windowFrameDef, outputColumnNum); | ||
| resetEvaluator(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isGroupAggregatedStreamingEvaluator() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void addStreamingGroupResults(List<Integer> groupRowCounts) { | ||
| // No-op: percent_rank only needs the partition size and the current rank. | ||
| } | ||
|
|
||
| @Override | ||
| public void evaluateGroupBatch(VectorizedRowBatch batch) throws HiveException { | ||
| if (partitionSize <= 0) { | ||
| throw new HiveException("Partition size must be set before computing percent_rank"); | ||
| } | ||
| final double divisor = partitionSize > 1 ? partitionSize - 1 : 1; | ||
| DoubleColumnVector outputColVector = (DoubleColumnVector) batch.cols[outputColumnNum]; | ||
| outputColVector.isRepeating = true; | ||
| outputColVector.noNulls = true; | ||
| outputColVector.isNull[0] = false; | ||
| outputColVector.vector[0] = (rank - 1) / divisor; | ||
| groupCount += batch.size; | ||
| } | ||
|
|
||
| @Override | ||
| public void doLastBatchWork() { | ||
| rank += groupCount; | ||
| groupCount = 0; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean streamsResult() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public Type getResultColumnVectorType() { | ||
| return Type.DOUBLE; | ||
| } | ||
|
|
||
| @Override | ||
| public void resetEvaluator() { | ||
| rank = 1; | ||
| partitionSize = -1; | ||
| groupCount = 0; | ||
| } | ||
| } |
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
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
113 changes: 113 additions & 0 deletions
113
ql/src/test/queries/clientpositive/vector_ptf_percent_rank.q
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| set hive.vectorized.testing.reducer.batch.size=2; | ||
|
|
||
| DROP TABLE IF EXISTS vector_ptf_percent_rank_int; | ||
|
|
||
| CREATE TABLE vector_ptf_percent_rank_int(name string, rowindex int, mynumber int) stored as orc; | ||
|
|
||
| INSERT INTO vector_ptf_percent_rank_int values | ||
| ('five', 1, 10), | ||
| ('five', 2, 20), | ||
| ('five', 3, 30), | ||
| ('five', 4, 40), | ||
| ('five', 5, 50), | ||
| ('six', 1, 10), | ||
| ('six', 2, 20), | ||
| ('six', 3, 30), | ||
| ('six', 4, 40), | ||
| ('six', 5, 50), | ||
| ('six', 6, 60), | ||
| -- single-row partition: percent_rank 0.0 | ||
| ('lonely', 99, 42), | ||
| -- two-row null partition | ||
| (NULL, 1, 100), | ||
| (NULL, 2, 100); | ||
|
|
||
| -- NON-VECTORIZED | ||
| set hive.vectorized.execution.ptf.enabled=false; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (partition by name order by mynumber) as r, | ||
| dense_rank() over (partition by name order by mynumber) as dr, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (order by mynumber) as r, | ||
| dense_rank() over (order by mynumber) as dr, | ||
| percent_rank() over (order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (partition by name) as r, | ||
| dense_rank() over (partition by name) as dr, | ||
| percent_rank() over (partition by name) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over () as r, | ||
| dense_rank() over () as dr, | ||
| percent_rank() over () as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| -- VECTORIZED | ||
| set hive.vectorized.execution.ptf.enabled=true; | ||
|
|
||
| explain vectorization detail select name, rowindex, mynumber, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| explain vectorization detail select name, rowindex, mynumber, | ||
| rank() over (partition by name order by mynumber) as r, | ||
| dense_rank() over (partition by name order by mynumber) as dr, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (partition by name order by mynumber) as r, | ||
| dense_rank() over (partition by name order by mynumber) as dr, | ||
| percent_rank() over (partition by name order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| explain vectorization detail select name, rowindex, mynumber, | ||
| rank() over (order by mynumber) as r, | ||
| dense_rank() over (order by mynumber) as dr, | ||
| percent_rank() over (order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (order by mynumber) as r, | ||
| dense_rank() over (order by mynumber) as dr, | ||
| percent_rank() over (order by mynumber) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| explain vectorization detail select name, rowindex, mynumber, | ||
| rank() over (partition by name) as r, | ||
| dense_rank() over (partition by name) as dr, | ||
| percent_rank() over (partition by name) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over (partition by name) as r, | ||
| dense_rank() over (partition by name) as dr, | ||
| percent_rank() over (partition by name) as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| explain vectorization detail select name, rowindex, mynumber, | ||
| rank() over () as r, | ||
| dense_rank() over () as dr, | ||
| percent_rank() over () as pr | ||
| from vector_ptf_percent_rank_int; | ||
|
|
||
| select name, rowindex, mynumber, | ||
| rank() over () as r, | ||
| dense_rank() over () as dr, | ||
| percent_rank() over () as pr | ||
| from vector_ptf_percent_rank_int; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.