Skip to content

Commit ea7dfa8

Browse files
authored
Update error code for checkElementNotNull used in array comparison operators (prestodb#24570)
1 parent d6c5af6 commit ea7dfa8

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

presto-common/src/main/java/com/facebook/presto/common/type/TypeUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package com.facebook.presto.common.type;
1515

16-
import com.facebook.presto.common.NotSupportedException;
16+
import com.facebook.presto.common.InvalidFunctionArgumentException;
1717
import com.facebook.presto.common.block.Block;
1818
import com.facebook.presto.common.block.BlockBuilder;
1919
import io.airlift.slice.Slice;
@@ -189,7 +189,7 @@ public static boolean isFloatingPointNaN(Type type, Object value)
189189
static void checkElementNotNull(boolean isNull, String errorMsg)
190190
{
191191
if (isNull) {
192-
throw new NotSupportedException(errorMsg);
192+
throw new InvalidFunctionArgumentException(errorMsg);
193193
}
194194
}
195195

presto-main/src/main/java/com/facebook/presto/type/TypeUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535

3636
import static com.facebook.presto.common.type.BigintType.BIGINT;
37+
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
3738
import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED;
3839
import static com.google.common.base.Preconditions.checkArgument;
3940
import static com.google.common.base.Throwables.throwIfUnchecked;
@@ -174,7 +175,7 @@ public static Page getHashPage(Page page, List<? extends Type> types, List<Integ
174175
public static void checkElementNotNull(boolean isNull, String errorMsg)
175176
{
176177
if (isNull) {
177-
throw new PrestoException(NOT_SUPPORTED, errorMsg);
178+
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, errorMsg);
178179
}
179180
}
180181
}

presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,13 @@ public void testArrayMinWithNullsInBothArraysNotComparedSecondIsMin()
710710
@Test
711711
public void testArrayMinWithNullInFirstArrayIsCompared()
712712
{
713-
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", NOT_SUPPORTED);
713+
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", INVALID_FUNCTION_ARGUMENT);
714714
}
715715

716716
@Test
717717
public void testArrayMinWithNullInSecondArrayIsCompared()
718718
{
719-
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", NOT_SUPPORTED);
719+
assertInvalidFunction("ARRAY_MIN(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", INVALID_FUNCTION_ARGUMENT);
720720
}
721721

722722
@Test
@@ -764,13 +764,13 @@ public void testArrayMaxWithNullsInBothArraysNotComparedFirstIsMax()
764764
@Test
765765
public void testArrayMaxWithNullInFirstArrayIsCompared()
766766
{
767-
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", NOT_SUPPORTED);
767+
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]])", INVALID_FUNCTION_ARGUMENT);
768768
}
769769

770770
@Test
771771
public void testArrayMaxWithNullInSecondArrayIsCompared()
772772
{
773-
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", NOT_SUPPORTED);
773+
assertInvalidFunction("ARRAY_MAX(ARRAY [ARRAY[1, 2], ARRAY[1, NULL]])", INVALID_FUNCTION_ARGUMENT);
774774
}
775775

776776
@Test
@@ -1145,7 +1145,7 @@ public void testSort()
11451145
assertInvalidFunction(
11461146
"ARRAY_SORT(ARRAY[ARRAY[1], ARRAY[null]])",
11471147
INVALID_FUNCTION_ARGUMENT,
1148-
"Array contains elements not supported for comparison");
1148+
"ARRAY comparison not supported for arrays with null elements");
11491149
assertInvalidFunction(
11501150
"ARRAY_SORT(ARRAY[ROW(1), ROW(null)])",
11511151
INVALID_FUNCTION_ARGUMENT,

presto-main/src/test/java/com/facebook/presto/type/TestRowOperators.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ public void testRowComparison()
692692
assertInvalidFunction("row(TRUE, ARRAY [1, 2], MAP(ARRAY[1, 3], ARRAY[2.0E0, 4.0E0])) > row(TRUE, ARRAY [1, 2], MAP(ARRAY[1, 3], ARRAY[2.0E0, 4.0E0]))",
693693
SemanticErrorCode.TYPE_MISMATCH, "line 1:64: '>' cannot be applied to row(boolean,array(integer),map(integer,double)), row(boolean,array(integer),map(integer,double))");
694694

695-
assertInvalidFunction("row(1, CAST(NULL AS INTEGER)) < row(1, 2)", StandardErrorCode.NOT_SUPPORTED);
695+
assertInvalidFunction("row(1, CAST(NULL AS INTEGER)) < row(1, 2)", StandardErrorCode.INVALID_FUNCTION_ARGUMENT);
696696

697697
assertComparisonCombination("row(1.0E0, ARRAY [1,2,3], row(2, 2.0E0))", "row(1.0E0, ARRAY [1,3,3], row(2, 2.0E0))");
698698
assertComparisonCombination("row(TRUE, ARRAY [1])", "row(TRUE, ARRAY [1, 2])");

presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java

+30
Original file line numberDiff line numberDiff line change
@@ -3234,6 +3234,36 @@ public void testTry()
32343234

32353235
// test try with null
32363236
assertQuery("SELECT TRY(1 / x) FROM (SELECT NULL as x)", "SELECT NULL");
3237+
3238+
// Test try with map method and value parameter is optional and argument is an array with null,
3239+
// the error should be suppressed and just return null.
3240+
assertQuery("SELECT\n" +
3241+
" TRY(map_keys_by_top_n_values(c0, BIGINT '6455219767830808341'))\n" +
3242+
"FROM (\n" +
3243+
" VALUES\n" +
3244+
" MAP(\n" +
3245+
" ARRAY[1, 2], ARRAY[\n" +
3246+
" ARRAY[1, null],\n" +
3247+
" ARRAY[1, null]\n" +
3248+
" ]\n" +
3249+
" )\n" +
3250+
") t(c0)", "SELECT NULL");
3251+
3252+
assertQuery("SELECT\n" +
3253+
" TRY(map_keys_by_top_n_values(c0, BIGINT '6455219767830808341'))\n" +
3254+
"FROM (\n" +
3255+
" VALUES\n" +
3256+
" MAP(\n" +
3257+
" ARRAY[1, 2], ARRAY[\n" +
3258+
" ARRAY[null, null],\n" +
3259+
" ARRAY[1, 2]\n" +
3260+
" ]\n" +
3261+
" )\n" +
3262+
") t(c0)", "SELECT NULL");
3263+
3264+
// Test try with array method with an input array containing null values.
3265+
// the error should be suppressed and just return null.
3266+
assertQuery("SELECT TRY(ARRAY_MAX(ARRAY [ARRAY[1, NULL], ARRAY[1, 2]]))", "SELECT NULL");
32373267
}
32383268

32393269
@Test

0 commit comments

Comments
 (0)