ggangadharan commented on code in PR #6946:
URL: https://github.com/apache/hive/pull/6946#discussion_r4678258406
##########
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorNTile.java:
##########
@@ -44,38 +46,44 @@
* evaluator keeps O(1) state regardless of partition size, and a batch that
falls entirely within
* one bucket is emitted as a repeating vector.
*
- * <p>The number of buckets must be a positive integer constant (e.g. {@code
ntile(4)}); the
- * Vectorizer leaves any other form to row mode.
+ * <p>The number of buckets is either a positive integer constant (e.g. {@code
ntile(4)}) or any
+ * other int expression (e.g. {@code ntile(col)}), which, as in {@code
GenericUDAFNTile}, is read
+ * from the first row of each partition. The Vectorizer leaves a non-positive
constant to row mode.
*/
public class VectorPTFEvaluatorNTile extends VectorPTFEvaluatorBase {
- private final long numBuckets;
+ // Number of buckets of a constant argument, or null when it is read from
the partition's first
+ // row.
+ private final Long constantNumBuckets;
- // Per-partition bucket layout, set up by addStreamingGroupResults.
+ // Per-partition bucket layout, set up by setUpBuckets once the first batch
is replayed.
private int bucketSize;
private int largerBucketCount;
- // Replay position within the partition.
+ // Replay position within the partition; 0 until the bucket layout is set up.
private int currentBucket;
private int rowsLeftInBucket;
public VectorPTFEvaluatorNTile(WindowFrameDef windowFrameDef,
VectorExpression numBucketsExpression, int outputColumnNum) {
- super(windowFrameDef, outputColumnNum);
- if (!(numBucketsExpression instanceof ConstantVectorExpression
constantExpr)) {
- throw new RuntimeException(
- "NTILE expects a constant integer expression for the number of
buckets, got: "
- + (numBucketsExpression == null ? "null"
- : numBucketsExpression.getClass().getName()));
- }
- numBuckets = constantExpr.getLongValue();
- if (numBuckets <= 0) {
- throw new RuntimeException(
- "NTILE requires a positive number of buckets, got: " + numBuckets);
- }
+ super(windowFrameDef, getInputExpression(numBucketsExpression),
outputColumnNum);
Review Comment:
Good catch, confirmed. initializeOp transient-initialized the partition and
order expressions but not the evaluator input expressions, so CastStringToLong
turned every value into NULL. ntile(cast(s as int)) failed with got: NULL, and
it wasn't only ntile: sum(cast(s as int)) silently returned NULLs. initializeOp
now runs doTransientInit on each evaluator's input expression, which fixes it
for every PTF function. I added a string-to-int case for both ntile and sum to
the row/vector comparisons in vector_ptf_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]