ggangadharan commented on code in PR #6946:
URL: https://github.com/apache/hive/pull/6946#discussion_r4610565505


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFEvaluatorNTile.java:
##########
@@ -44,34 +44,41 @@
  * 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 0 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()));
+    // A constant needs no input column; any other expression is evaluated 
before batches are
+    // buffered, and its result column is read back when the partition's first 
batch is replayed.
+    super(windowFrameDef,
+        numBucketsExpression instanceof ConstantVectorExpression ? null : 
numBucketsExpression,
+        outputColumnNum);
+    if (numBucketsExpression == null) {
+      throw new RuntimeException("NTILE expects an expression for the number 
of buckets");

Review Comment:
   Hive builds with Java 21, which doesn't allow statements before super(...) 
(flexible constructor bodies are final only in Java 25 if my assumption is 
right). Moved the check into a static helper, getInputExpression, called in the 
super(...) argument list, so it now fails before the base class is constructed. 
It also throws through Preconditions.checkArgument (an 
IllegalArgumentException) instead of a plain RuntimeException, which eventually 
will clear the Sonar issue on that line.



-- 
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]

Reply via email to