/** * Verifies that the output and output type of the function call matches the provided expected values * * @param functionCall A {@link FunctionCall} with function name and a list of input arguments. * @param expectedOutput The expected output data * @param expectedOutputTypeSignature The type signature string for the data type of the expected output */ default void check(FunctionCall functionCall, Object expectedOutput, String expectedOutputTypeSignature) { check(new TestCase(functionCall, expectedOutput, expectedOutputTypeSignature)); } }
/** * Verifies that the output and output type of the function call matches the provided expected values * * @param functionCall A {@link FunctionCall} with function name and a list of input arguments. * @param expectedOutput The expected output data * @param expectedOutputTypeSignature The type signature string for the data type of the expected output */ default void check(FunctionCall functionCall, Object expectedOutput, String expectedOutputTypeSignature) { check(new TestCase(functionCall, expectedOutput, expectedOutputTypeSignature)); } }
@Test public void testStructCreateByNameFunction() { StdTester tester = getTester(); tester.check(functionCall("struct_create_by_name", "a", "x", "b", "y"), row("x", "y"), "row(varchar,varchar)"); tester.check(functionCall("struct_create_by_name", null, "x", "b", "y"), null, "row(varchar,varchar)"); tester.check(functionCall("struct_create_by_name", "a", "x", null, "y"), null, "row(varchar,varchar)"); } }
@Test public void testStructCreateByIndexFunctionFailsOnPresto() { StdTester tester = getTester(); // TODO: We don't have good support in Presto for null input value with unkown non-nullable type tester.check(functionCall("struct_create_by_index", null, null), null, "row(unknown,unknown)"); } }
@Test public void testArrayFillFailsOnPresto() { // TODO: We don't have good support in Presto for null input value with unkown non-nullable type getTester().check(functionCall("array_fill", null, 2L), null, "array(unknown)"); } }
@Test public void testStructCreateByNameFunctionFailsOnPresto() { StdTester tester = getTester(); // TODO: We don't have good support in Presto for null input value with unkown non-nullable type tester.check(functionCall("struct_create_by_name", "a", null, "b", "y"), null, "row(unknown,varchar)"); } }
@Test public void testFileLookup() { StdTester tester = getTester(); tester.check(functionCall("file_lookup", resource("file_lookup_function/sample"), 1), true, "boolean"); tester.check(functionCall("file_lookup", resource("file_lookup_function/sample"), 6), false, "boolean"); tester.check(functionCall("file_lookup", resource("file_lookup_function/sample"), null), null, "boolean"); // TODO: Check behaviour consistency between platforms when file argument is null // tester.check(functionCall("file_lookup", null, 1), null, "boolean"); } }
@Test public void testMapKeySet() { StdTester tester = getTester(); tester.check(functionCall("map_key_set", map(1, 4, 2, 5, 3, 6)), array(1, 2, 3), "array(integer)"); tester.check(functionCall("map_key_set", map("1", "4", "2", "5", "3", "6")), array("1", "2", "3"), "array(varchar)"); tester.check(functionCall("map_key_set", (Object) null), null, "array(unknown)"); } }
@Test public void testMapValues() { StdTester tester = getTester(); tester.check(functionCall("std_map_values", map(1, 4, 2, 5, 3, 6)), array(4, 5, 6), "array(integer)"); tester.check(functionCall("std_map_values", map("1", "4", "2", "5", "3", "6")), array("4", "5", "6"), "array(varchar)"); tester.check(functionCall("std_map_values", (Object) null), null, "array(unknown)"); } }
@Test public void testArrayFill() { StdTester tester = getTester(); tester.check(functionCall("array_fill", 1, 5L), array(1, 1, 1, 1, 1), "array(integer)"); tester.check(functionCall("array_fill", "1", 5L), array("1", "1", "1", "1", "1"), "array(varchar)"); tester.check(functionCall("array_fill", true, 5L), array(true, true, true, true, true), "array(boolean)"); tester.check(functionCall("array_fill", array(1), 5L), array(array(1), array(1), array(1), array(1), array(1)), "array(array(integer))"); tester.check(functionCall("array_fill", 1, 0L), array(), "array(integer)"); tester.check(functionCall("array_fill", 1, null), null, "array(integer)"); } }
@Test public void testStructCreateByIndexFunction() { StdTester tester = getTester(); tester.check(functionCall("struct_create_by_index", "x", "y"), row("x", "y"), "row(varchar,varchar)"); tester.check(functionCall("struct_create_by_index", 1, array(1)), row(1, array(1)), "row(integer,array(integer))"); } }
@Test public void testArrayElementAtFunctionNested() { StdTester tester = getTester(); tester.check(functionCall("array_element_at", array(functionCall("numeric_add", 0, 1), 2, 3), 0), 1, "integer"); } }
@Test public void testArrayElementAt() { StdTester tester = getTester(); tester.check(functionCall("array_element_at", array("1", "2"), 1), "2", "varchar"); tester.check(functionCall("array_element_at", array(1, 2), 1), 2, "integer"); tester.check(functionCall("array_element_at", array(true, false), 1), false, "boolean"); tester.check(functionCall("array_element_at", array(array("1"), array("2")), 1), array("2"), "array(varchar)"); tester.check(functionCall("array_element_at", null, 1), null, "unknown"); tester.check(functionCall("array_element_at", array(1), null), null, "integer"); tester.check(functionCall("array_element_at", array("1", null, "2"), 1), null, "varchar"); tester.check(functionCall("array_element_at", array(array("1"), array("2", null)), 1), array("2", null), "array(varchar)"); } }
@Test public void testMapFromTwoArraysFunctionNested() { StdTester tester = getTester(); tester.check(functionCall("map_from_two_arrays", functionCall("std_map_values", map(1, "a", 2, "b")), functionCall("map_key_set", map(1, "a", 2, "b"))), map("a", 1, "b", 2), "map(varchar, integer)"); tester.check(functionCall("map_from_two_arrays", functionCall("std_map_values", map(1, "a", 2, "b")), functionCall("map_key_set", map(1, "a", 2, "b"))), map("a", 1, "b", 2), "map(varchar, integer)"); } }
@Test public void testMapFromTwoArraysFunction() { StdTester tester = getTester(); tester.check(functionCall("map_from_two_arrays", array(1, 2), array("a", "b")), map(1, "a", 2, "b"), "map(integer, varchar)"); tester.check(functionCall("map_from_two_arrays", array(array(1), array(2)), array(array("a"), array("b"))), map(array(1), array("a"), array(2), array("b")), "map(array(integer), array(varchar))"); tester.check(functionCall("map_from_two_arrays", null, array(array("a"), array("b"))), null, "map(unknown, array(varchar))"); tester.check(functionCall("map_from_two_arrays", array(array(1), array(2)), null), null, "map(array(integer), unknown)"); } }