@@ -393,12 +393,21 @@ public void testArrayTopNEdgeAndErrorCase()
393
393
// Test exceptions
394
394
assertInvalidFunction ("ARRAY_TOP_N(ARRAY [ROW('a', 1), ROW('a', null), null, ROW('a', 0)], 2)" , StandardErrorCode .INVALID_FUNCTION_ARGUMENT );
395
395
assertInvalidFunction ("ARRAY_TOP_N(ARRAY [MAP(ARRAY['foo', 'bar'], ARRAY[1, 2]), MAP(ARRAY['foo', 'bar'], ARRAY[0, 3])], 2)" , SemanticErrorCode .FUNCTION_NOT_FOUND );
396
- assertInvalidFunction ("ARRAY_TOP_N(ARRAY ['a', 'a', 'd', 'a', 'a', 'a'], -1)" , StandardErrorCode .GENERIC_USER_ERROR , "Parameter n: -1 to ARRAY_TOP_N is negative" );
397
396
398
397
// Test edge cases
399
398
assertFunction ("ARRAY_TOP_N(ARRAY [null, null], 3)" , new ArrayType (UNKNOWN ), asList (null , null ));
400
399
assertFunction ("ARRAY_TOP_N(ARRAY [3, 5, 1, 2], 0)" , new ArrayType (INTEGER ), emptyList ());
401
400
assertFunction ("ARRAY_TOP_N(ARRAY [], 3)" , new ArrayType (UNKNOWN ), emptyList ());
402
401
assertFunction ("ARRAY_TOP_N(ARRAY [1, 4], 3)" , new ArrayType (INTEGER ), ImmutableList .of (4 , 1 ));
403
402
}
403
+
404
+ @ Test
405
+ public void testArrayTopNNegativeParameter ()
406
+ {
407
+ assertFunction ("ARRAY_TOP_N(ARRAY ['a', 'a', 'd', 'a', 'a', 'a'], -1)" , new ArrayType (createVarcharType (1 )), null );
408
+ assertFunction ("ARRAY_TOP_N(ARRAY [1,2,3,4,5,6], -5)" , new ArrayType (INTEGER ), null );
409
+ assertFunction ("ARRAY_TOP_N(ARRAY [DOUBLE '1.0', 100, 2, DOUBLE '5.0', DOUBLE '3.0'], -3)" , new ArrayType (DOUBLE ), null );
410
+ assertFunction ("ARRAY_TOP_N(ARRAY [true, true, false, true, false], -4)" , new ArrayType (BOOLEAN ), null );
411
+ assertFunction ("ARRAY_TOP_N(ARRAY [null, null], -3)" , new ArrayType (UNKNOWN ), null );
412
+ }
404
413
}
0 commit comments