Skip to content

Commit

Permalink
array_min/array_max throw if first element is an inner Array with a n…
Browse files Browse the repository at this point in the history
…ull element
  • Loading branch information
kevinwilfong authored and xiaoxmeng committed Aug 15, 2024
1 parent be29974 commit 330fa47
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ public static Block blockArrayMax(
return null;
}

if (block.isNull(0)) {
return null;
}

Block selectedValue = (Block) elementType.getObject(block, 0);
for (int i = 0; i < block.getPositionCount(); i++) {
for (int i = 1; i < block.getPositionCount(); i++) {
if (block.isNull(i)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ public static Block blockArrayMin(
return null;
}

if (block.isNull(0)) {
return null;
}

Block selectedValue = (Block) elementType.getObject(block, 0);
for (int i = 0; i < block.getPositionCount(); i++) {
for (int i = 1; i < block.getPositionCount(); i++) {
if (block.isNull(i)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,30 @@ public void testArrayMin()
assertDecimalFunction("ARRAY_MIN(ARRAY [2.22222222222222222, 2.3])", decimal("2.22222222222222222"));
}

@Test
public void testArrayMinWithNullsInBothArraysNotComparedFirstIsMin()
{
assertFunction("ARRAY_MIN(ARRAY [ARRAY[1, NULL], ARRAY[2, NULL]])", new ArrayType(INTEGER), Lists.newArrayList(1, null));
}

@Test
public void testArrayMinWithNullsInBothArraysNotComparedSecondIsMin()
{
assertFunction("ARRAY_MIN(ARRAY [ARRAY[2, NULL], ARRAY[1, NULL]])", new ArrayType(INTEGER), Lists.newArrayList(1, null));
}

@Test
public void testArrayMinWithNullInFirstArrayIsCompared()
{
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", NOT_SUPPORTED);
}

@Test
public void testArrayMinWithNullInSecondArrayIsCompared()
{
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", NOT_SUPPORTED);
}

@Test
public void testArrayMax()
{
Expand Down Expand Up @@ -725,6 +749,30 @@ public void testArrayMax()
assertDecimalFunction("ARRAY_MAX(ARRAY [2.22222222222222222, 2.3])", decimal("2.30000000000000000"));
}

@Test
public void testArrayMaxWithNullsInBothArraysNotComparedSecondIsMax()
{
assertFunction("ARRAY_MAX(ARRAY [ARRAY[1, NULL], ARRAY[2, NULL]])", new ArrayType(INTEGER), Lists.newArrayList(2, null));
}

@Test
public void testArrayMaxWithNullsInBothArraysNotComparedFirstIsMax()
{
assertFunction("ARRAY_MAX(ARRAY [ARRAY[2, NULL], ARRAY[1, NULL]])", new ArrayType(INTEGER), Lists.newArrayList(2, null));
}

@Test
public void testArrayMaxWithNullInFirstArrayIsCompared()
{
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", NOT_SUPPORTED);
}

@Test
public void testArrayMaxWithNullInSecondArrayIsCompared()
{
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", NOT_SUPPORTED);
}

@Test
public void testArrayPosition()
{
Expand Down

0 comments on commit 330fa47

Please sign in to comment.