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


##########
ql/src/test/queries/clientpositive/vector_ptf_ntile.q:
##########
@@ -125,16 +125,167 @@ ntile(3) over (partition by name order by mynumber) as 
nt,
 sum(mynumber) over (partition by name order by mynumber) as s
 from vector_ptf_ntile_int;
 
--- NOT VECTORIZED: a non-constant number of buckets falls back to row mode, 
which takes the value
--- from the first row of each partition
-explain vectorization detail select name, rowindex,
+-- Non-constant number of buckets: taken from the first row of each partition, 
as in row mode.
+-- Each partition of vector_ptf_ntile_buckets holds its number of buckets (nb) 
in its first row by
+-- ord; the later rows hold NULL, 0, negative and other counts, which must not 
be read.
+DROP TABLE IF EXISTS vector_ptf_ntile_buckets;
+
+CREATE TABLE vector_ptf_ntile_buckets(k int, ord int, nb int) stored as orc;
+
+INSERT INTO vector_ptf_ntile_buckets values
+-- a single bucket
+(1, 1, 1), (1, 2, NULL), (1, 3, 0), (1, 4, -3), (1, 5, 7),
+-- fewer buckets than rows, with a remainder: 7 rows in 2 buckets
+(3, 6, 2), (3, 7, 0), (3, 8, NULL), (3, 9, 100), (3, 10, -1), (3, 11, 2), (3, 
12, 5),
+-- fewer buckets than rows, without a remainder: 6 rows in 3 buckets
+(2, 13, 3), (2, 14, NULL), (2, 15, 0), (2, 16, 1), (2, 17, -6), (2, 18, 4),
+-- as many buckets as rows
+(4, 19, 4), (4, 20, 0), (4, 21, NULL), (4, 22, 1),
+-- more buckets than rows: the largest int
+(10, 23, 2147483647), (10, 24, NULL), (10, 25, 0),
+-- a negative number of buckets larger in magnitude than the partition: one 
row per bucket
+(-4, 26, -4), (-4, 27, 0), (-4, 28, NULL),
+-- a single row
+(5, 29, -2);
+
+set hive.vectorized.execution.ptf.enabled=false;
+
+select k, ord, nb,
+ntile(nb) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+select k,
+ntile(k * 2) over (partition by k) as nt
+from vector_ptf_ntile_buckets;
+
+select k, ord,
+ntile(k) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+select name, rowindex,
 ntile(rowindex) over (partition by name order by rowindex) as nt
 from vector_ptf_ntile_int;
 
+select name, rowindex, mynumber,
+ntile(mynumber % 8 + 1) over (partition by name order by mynumber desc nulls 
last, rowindex) as nt
+from vector_ptf_ntile_int;
+
+select k, ord, nb,
+rank() over (partition by k order by ord) as r,
+ntile(3) over (partition by k order by ord) as nt3,
+ntile(nb) over (partition by k order by ord) as nt,
+sum(nb) over (partition by k order by ord) as s
+from vector_ptf_ntile_buckets;
+
+set hive.vectorized.execution.ptf.enabled=true;
+
+-- column argument
+explain vectorization detail select k, ord, nb,
+ntile(nb) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+select k, ord, nb,
+ntile(nb) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+-- expression argument; with PARTITION BY only, a batch holds several rows of 
the partition
+explain vectorization detail select k,
+ntile(k * 2) over (partition by k) as nt
+from vector_ptf_ntile_buckets;
+
+select k,
+ntile(k * 2) over (partition by k) as nt
+from vector_ptf_ntile_buckets;
+
+-- partition key argument, which is not buffered but restored when the 
partition is forwarded
+explain vectorization detail select k, ord,
+ntile(k) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+select k, ord,
+ntile(k) over (partition by k order by ord) as nt
+from vector_ptf_ntile_buckets;
+
+-- order key argument
 select name, rowindex,
 ntile(rowindex) over (partition by name order by rowindex) as nt
 from vector_ptf_ntile_int;
 
+-- expression argument, read from the first row in ORDER BY order rather than 
insertion order
+select name, rowindex, mynumber,
+ntile(mynumber % 8 + 1) over (partition by name order by mynumber desc nulls 
last, rowindex) as nt
+from vector_ptf_ntile_int;
+
+-- constant and non-constant ntile mixed with streaming (rank) and buffered 
(sum) evaluators while
+-- spilling every batch to disk
+set hive.vectorized.ptf.max.memory.buffering.batch.count=1;
+
+select k, ord, nb,
+rank() over (partition by k order by ord) as r,
+ntile(3) over (partition by k order by ord) as nt3,
+ntile(nb) over (partition by k order by ord) as nt,

Review Comment:
   The spill run covers only a plain column (ntile(nb)). 
   
   Could you add ntile(k * 2) and ntile(k) with the same window here? They 
cover a spilled scratch column and the partition key being restored when 
spilled batches are replayed.                 



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