assertCall("CALL test_simple()", "simple"); assertCall(format("CALL %s.test_simple()", PROCEDURE_SCHEMA), "simple"); assertCall(format("CALL %s.%s.test_simple()", TESTING_CATALOG, PROCEDURE_SCHEMA), "simple"); assertCall("CALL test_args(123, 4.5, 'hello', true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(-5, nan(), 'bye', false)", "args", -5L, Double.NaN, "bye", false); assertCall("CALL test_args(3, 88, 'coerce', true)", "args", 3L, 88.0, "coerce", true); assertCall("CALL test_args(x => 123, y => 4.5, z => 'hello', q => true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(q => true, z => 'hello', y => 4.5, x => 123)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_nulls(123, null)", "nulls", 123L, null); assertCall("CALL test_nulls(null, 'apple')", "nulls", null, "apple"); assertCall("CALL test_arrays(ARRAY [12, 34], ARRAY['abc', 'xyz'])", "arrays", list(12L, 34L), list("abc", "xyz")); assertCall("CALL test_arrays(ARRAY [], ARRAY[])", "arrays", list(), list()); assertCall("CALL test_nested(ARRAY [ARRAY[12, 34], ARRAY[56]])", "nested", list(list(12L, 34L), list(56L))); assertCall("CALL test_nested(ARRAY [])", "nested", list()); assertCall("CALL test_nested(ARRAY [ARRAY[]])", "nested", list(list())); assertCall("CALL test_session_first(123)", "session_first", 123L); assertCall("CALL test_session_last('grape')", "session_last", "grape"); assertCallThrows("CALL test_exception()", "exception", "test exception from procedure"); assertCallThrows("CALL test_error()", "error", "test error from procedure"); assertCallFails("CALL test_args(null, 4.5, 'hello', true)", "Procedure argument cannot be null: x"); assertCallFails("CALL test_args(123, null, 'hello', true)", "Procedure argument cannot be null: y"); assertCallFails("CALL test_args(123, 4.5, 'hello', null)", "Procedure argument cannot be null: q");
private void assertCallThrows(@Language("SQL") String sql, String name, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list()); assertEquals(e.getMessage(), message); } }
private void assertCallFails(@Language("SQL") String sql, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertFalse(tester.wasCalled()); assertEquals(e.getMessage(), message); } }
@BeforeClass public void setUp() { TestingPrestoServer coordinator = ((DistributedQueryRunner) getQueryRunner()).getCoordinator(); tester = coordinator.getProcedureTester(); // register procedures in the bogus testing catalog ProcedureRegistry procedureRegistry = coordinator.getMetadata().getProcedureRegistry(); TestingProcedures procedures = new TestingProcedures(coordinator.getProcedureTester()); procedureRegistry.addProcedures( new ConnectorId(TESTING_CATALOG), procedures.getProcedures(PROCEDURE_SCHEMA)); session = testSessionBuilder() .setCatalog(TESTING_CATALOG) .setSchema(PROCEDURE_SCHEMA) .build(); }
private void assertCallFails(@Language("SQL") String sql, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertFalse(tester.wasCalled()); assertEquals(e.getMessage(), message); } }
@BeforeClass public void setUp() { TestingPrestoServer coordinator = ((DistributedQueryRunner) getQueryRunner()).getCoordinator(); tester = coordinator.getProcedureTester(); // register procedures in the bogus testing catalog ProcedureRegistry procedureRegistry = coordinator.getMetadata().getProcedureRegistry(); TestingProcedures procedures = new TestingProcedures(coordinator.getProcedureTester()); procedureRegistry.addProcedures( new ConnectorId(TESTING_CATALOG), procedures.getProcedures(PROCEDURE_SCHEMA)); session = testSessionBuilder() .setCatalog(TESTING_CATALOG) .setSchema(PROCEDURE_SCHEMA) .build(); }
assertCall("CALL test_simple()", "simple"); assertCall(format("CALL %s.test_simple()", PROCEDURE_SCHEMA), "simple"); assertCall(format("CALL %s.%s.test_simple()", TESTING_CATALOG, PROCEDURE_SCHEMA), "simple"); assertCall("CALL test_args(123, 4.5, 'hello', true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(-5, nan(), 'bye', false)", "args", -5L, Double.NaN, "bye", false); assertCall("CALL test_args(3, 88, 'coerce', true)", "args", 3L, 88.0, "coerce", true); assertCall("CALL test_args(x => 123, y => 4.5, z => 'hello', q => true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(q => true, z => 'hello', y => 4.5, x => 123)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_nulls(123, null)", "nulls", 123L, null); assertCall("CALL test_nulls(null, 'apple')", "nulls", null, "apple"); assertCall("CALL test_arrays(ARRAY [12, 34], ARRAY['abc', 'xyz'])", "arrays", list(12L, 34L), list("abc", "xyz")); assertCall("CALL test_arrays(ARRAY [], ARRAY[])", "arrays", list(), list()); assertCall("CALL test_nested(ARRAY [ARRAY[12, 34], ARRAY[56]])", "nested", list(list(12L, 34L), list(56L))); assertCall("CALL test_nested(ARRAY [])", "nested", list()); assertCall("CALL test_nested(ARRAY [ARRAY[]])", "nested", list(list())); assertCall("CALL test_session_first(123)", "session_first", 123L); assertCall("CALL test_session_last('grape')", "session_last", "grape"); assertCallThrows("CALL test_exception()", "exception", "test exception from procedure"); assertCallThrows("CALL test_error()", "error", "test error from procedure"); assertCallFails("CALL test_args(null, 4.5, 'hello', true)", "Procedure argument cannot be null: x"); assertCallFails("CALL test_args(123, null, 'hello', true)", "Procedure argument cannot be null: y"); assertCallFails("CALL test_args(123, 4.5, 'hello', null)", "Procedure argument cannot be null: q");
private void assertCall(@Language("SQL") String sql, String name, Object... arguments) { tester.reset(); assertUpdate(sql); assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list(arguments)); }
private void assertCallFails(@Language("SQL") String sql, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertFalse(tester.wasCalled()); assertEquals(e.getMessage(), message); } }
String catalog = getSession().getCatalog().get(); String schema = getSession().getSchema().get(); assertCall("CALL test_simple()", "simple"); assertCall(format("CALL %s.test_simple()", schema), "simple"); assertCall(format("CALL %s.%s.test_simple()", catalog, schema), "simple"); assertCall("CALL test_args(123, 4.5, 'hello', true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(-5, nan(), 'bye', false)", "args", -5L, Double.NaN, "bye", false); assertCall("CALL test_args(3, 88, 'coerce', true)", "args", 3L, 88.0, "coerce", true); assertCall("CALL test_args(x => 123, y => 4.5, z => 'hello', q => true)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_args(q => true, z => 'hello', y => 4.5, x => 123)", "args", 123L, 4.5, "hello", true); assertCall("CALL test_nulls(123, null)", "nulls", 123L, null); assertCall("CALL test_nulls(null, 'apple')", "nulls", null, "apple"); assertCall("CALL test_arrays(ARRAY [12, 34], ARRAY['abc', 'xyz'])", "arrays", list(12L, 34L), list("abc", "xyz")); assertCall("CALL test_arrays(ARRAY [], ARRAY[])", "arrays", list(), list()); assertCall("CALL test_nested(ARRAY [ARRAY[12, 34], ARRAY[56]])", "nested", list(list(12L, 34L), list(56L))); assertCall("CALL test_nested(ARRAY [])", "nested", list()); assertCall("CALL test_nested(ARRAY [ARRAY[]])", "nested", list(list())); assertCall("CALL test_session_first(123)", "session_first", 123L); assertCall("CALL test_session_last('grape')", "session_last", "grape"); assertCallThrows("CALL test_exception()", "exception", "test exception from procedure"); assertCallThrows("CALL test_error()", "error", "test error from procedure");
private void assertCallThrows(@Language("SQL") String sql, String name, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list()); assertEquals(e.getMessage(), message); } }
private void assertCall(@Language("SQL") String sql, String name, Object... arguments) { tester.reset(); assertUpdate(sql); assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list(arguments)); }
private void assertCallThrows(@Language("SQL") String sql, String name, String message) { tester.reset(); try { assertUpdate(sql); fail("expected exception"); } catch (RuntimeException e) { assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list()); assertEquals(e.getMessage(), message); } }
private void assertCall(@Language("SQL") String sql, String name, Object... arguments) { tester.reset(); assertUpdate(sql); assertEquals(tester.getCalledName(), name); assertEquals(tester.getCalledArguments(), list(arguments)); }