Skip to content

Commit

Permalink
Test CALL with delimited identifiers
Browse files Browse the repository at this point in the history
Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com>
findepi and kasiafi committed Mar 5, 2022
1 parent c9920a2 commit c3ff799
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -127,10 +127,18 @@ public void error()
throw new RuntimeException("test error from procedure");
}

@UsedByGeneratedCode
public void names(ConnectorSession session, String x, String y, String z, String v)
{
tester.recordCalled("names", x, y, z, v);
}

public List<Procedure> getProcedures(String schema)
{
return ImmutableList.<Procedure>builder()
.add(procedure(schema, "test_simple", "simple", ImmutableList.of()))
.add(procedure(schema, "test_lowercase_name", "simple", ImmutableList.of()))
.add(procedure(schema, "TEST_UPPERCASE_NAME", "simple", ImmutableList.of()))
.add(procedure(schema, "test_args", "args", ImmutableList.of(
new Argument("x", BIGINT),
new Argument("y", DOUBLE),
@@ -164,6 +172,11 @@ public List<Procedure> getProcedures(String schema)
new Argument("v", VARCHAR, false, "v default"))))
.add(procedure(schema, "test_exception", "exception", ImmutableList.of()))
.add(procedure(schema, "test_error", "error", ImmutableList.of()))
.add(procedure(schema, "test_argument_names", "names", ImmutableList.of(
new Argument("lower", VARCHAR, false, "a"),
new Argument("UPPER", VARCHAR, false, "b"),
new Argument("MixeD", VARCHAR, false, "c"),
new Argument("with space", VARCHAR, false, "d"))))
.build();
}

Original file line number Diff line number Diff line change
@@ -156,6 +156,47 @@ public void testProcedureCallWithOptionals()
assertCallFails("CALL test_optionals4(y => 'cd', v => 'value')", "line 1:1: Required procedure argument 'x' is missing");
}

@Test
public void testProcedureName()
{
assertCall("CALL test_lowercase_name()", "simple");
assertCall("CALL TEST_LOWERCASE_NAME()", "simple");
assertCall("CALL Test_Lowercase_NAME()", "simple");
assertCall("CALL \"test_lowercase_name\"()", "simple");
assertCall("CALL \"TEST_LOWERCASE_NAME\"()", "simple");
assertCall("CALL \"Test_Lowercase_Name\"()", "simple");

assertCall("CALL test_uppercase_name()", "simple");
assertCall("CALL TEST_UPPERCASE_NAME()", "simple");
assertCall("CALL Test_Uppercase_NAME()", "simple");
assertCall("CALL \"test_uppercase_name\"()", "simple");
assertCall("CALL \"TEST_UPPERCASE_NAME\"()", "simple");
assertCall("CALL \"Test_Uppercase_NAME\"()", "simple");
}

@Test
public void testNamedArguments()
{
assertCall("CALL test_argument_names(lower => 'a')", "names", "a", "b", "c", "d");
assertCallFails("CALL test_argument_names(LOWER => 'a')", "line 1:26: Unknown argument name: LOWER");
assertCallFails("CALL test_argument_names(\"lower\" => 'a')", "line 1:26: Unknown argument name: \"lower\"");
assertCallFails("CALL test_argument_names(\"LOWER\" => 'a')", "line 1:26: Unknown argument name: \"LOWER\"");

assertCallFails("CALL test_argument_names(upper => 'b')", "line 1:26: Unknown argument name: upper");
assertCall("CALL test_argument_names(UPPER => 'b')", "names", "a", "b", "c", "d");
assertCallFails("CALL test_argument_names(\"upper\" => 'b')", "line 1:26: Unknown argument name: \"upper\"");
assertCallFails("CALL test_argument_names(\"UPPER\" => 'b')", "line 1:26: Unknown argument name: \"UPPER\"");

assertCallFails("CALL test_argument_names(mixed => 'c')", "line 1:26: Unknown argument name: mixed");
assertCall("CALL test_argument_names(MixeD => 'c')", "names", "a", "b", "c", "d");
assertCallFails("CALL test_argument_names(MIXED => 'c')", "line 1:26: Unknown argument name: MIXED");
assertCallFails("CALL test_argument_names(\"mixed\" => 'c')", "line 1:26: Unknown argument name: \"mixed\"");
assertCallFails("CALL test_argument_names(\"MixeD\" => 'c')", "line 1:26: Unknown argument name: \"MixeD\"");
assertCallFails("CALL test_argument_names(\"MIXED\" => 'c')", "line 1:26: Unknown argument name: \"MIXED\"");

assertCallFails("CALL test_argument_names(\"with space\" => 'd')", "line 1:26: Unknown argument name: \"with space\"");
}

private void assertCall(@Language("SQL") String sql, String name, Object... arguments)
{
tester.reset();

0 comments on commit c3ff799

Please sign in to comment.