default void check(TestCase testCase) { assertFunctionCall(getSqlFunctionCallGenerator().getSqlFunctionCallString(testCase.getFunctionCall()), getToPlatformTestOutputConverter().convertToTestOutput(testCase.getExpectedOutput(), testCase.getInferredOutputType()), getPlatformType(testCase.getExpectedOutputType())); }
/** * 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)); } }
private static synchronized StdTesterService getInstance() { if (service == null) { service = new StdTesterService(); } return service; }
/** * Returns SQL function call string of the format {@code functionName(argument1, argument2, argument3, ...)} */ default String getSqlFunctionCallString(FunctionCall functionCall) { return functionCall.getFunctionName() + "(" + IntStream.range(0, functionCall.getParameters().size()) .mapToObj(idx -> getFunctionCallArgumentString(functionCall.getParameters().get(idx), functionCall.getInferredParameterTypes().get(idx))) .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code STRUCT(f1, f2, f3, ...)} representing a struct literal */ default String getStructArgumentString(Row struct, List<TestType> structFieldTypes) { List<Object> structFields = struct.getFields(); return "STRUCT" + "(" + IntStream.range(0, structFields.size()) .mapToObj(idx -> getFunctionCallArgumentString(structFields.get(idx), structFieldTypes.get(idx))) .collect(Collectors.joining(", ")) + ")"; } }
/** * Returns a {@link StdTester} for the underlying test platform */ protected StdTester getTester() { StdTester tester = StdTesterService.getTester(); validateTopLevelStdUDFClassesAndImplementations(getTopLevelStdUDFClassesAndImplementations()); tester.setup(getTopLevelStdUDFClassesAndImplementations()); return tester; }
/** * Creates a row from the provided elements to pass to the test framework */ protected static Row row(Object... args) { return new Row(Arrays.asList(args)); }
@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)"); } }
/** * Creates a {@link FunctionCall} for a {@link TestCase} from the provided function name and parameters */ protected static FunctionCall functionCall(String functionName, Object... parameters) { return new FunctionCall(functionName, Arrays.asList(parameters)); }
/** * Returns the {@link StdTester} available on the classpath */ public static StdTester getTester() { StdTesterService service = getInstance(); try { return service.stdTesterClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw (new RuntimeException(e)); } } }
default Object getPlatformType(String typeSignature) { return getStdFactory().createStdType(typeSignature).underlyingType(); } }
default void check(TestCase testCase) { assertFunctionCall(getSqlFunctionCallGenerator().getSqlFunctionCallString(testCase.getFunctionCall()), getToPlatformTestOutputConverter().convertToTestOutput(testCase.getExpectedOutput(), testCase.getInferredOutputType()), getPlatformType(testCase.getExpectedOutputType())); }
/** * Returns SQL function call string of the format {@code functionName(argument1, argument2, argument3, ...)} */ default String getSqlFunctionCallString(FunctionCall functionCall) { return functionCall.getFunctionName() + "(" + IntStream.range(0, functionCall.getParameters().size()) .mapToObj(idx -> getFunctionCallArgumentString(functionCall.getParameters().get(idx), functionCall.getInferredParameterTypes().get(idx))) .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code STRUCT(f1, f2, f3, ...)} representing a struct literal */ default String getStructArgumentString(Row struct, List<TestType> structFieldTypes) { List<Object> structFields = struct.getFields(); return "STRUCT" + "(" + IntStream.range(0, structFields.size()) .mapToObj(idx -> getFunctionCallArgumentString(structFields.get(idx), structFieldTypes.get(idx))) .collect(Collectors.joining(", ")) + ")"; } }
/** * 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)); } }
/** * Returns a {@link StdTester} for the underlying test platform */ protected StdTester getTester() { StdTester tester = StdTesterService.getTester(); validateTopLevelStdUDFClassesAndImplementations(getTopLevelStdUDFClassesAndImplementations()); tester.setup(getTopLevelStdUDFClassesAndImplementations()); return tester; }
/** * Creates a row from the provided elements to pass to the test framework */ protected static Row row(Object... args) { return new Row(Arrays.asList(args)); }
@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))"); } }
private static synchronized StdTesterService getInstance() { if (service == null) { service = new StdTesterService(); } return service; }
/** * Creates a {@link FunctionCall} for a {@link TestCase} from the provided function name and parameters */ protected static FunctionCall functionCall(String functionName, Object... parameters) { return new FunctionCall(functionName, Arrays.asList(parameters)); }