Skip to content

Commit

Permalink
Make sure that quoted identifiers remain quoted in formatter
Browse files Browse the repository at this point in the history
The side-effect of this change is that formatted statements for SetSession
and ResetSession are no longer lowercased as before. However QualifiedName
instances are resolved and compared case-insensitive, thus such side-effect
does not lead to any consequences.
  • Loading branch information
Sergey Melnychuk authored and hashhar committed Mar 1, 2022
1 parent 33277e7 commit 38d7d5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ protected Void visitTruncateTable(TruncateTable node, Integer indent)
public Void visitSetSession(SetSession node, Integer indent)
{
builder.append("SET SESSION ")
.append(node.getName())
.append(formatName(node.getName()))
.append(" = ")
.append(formatExpression(node.getValue()));

Expand All @@ -1522,7 +1522,7 @@ public Void visitSetSession(SetSession node, Integer indent)
public Void visitResetSession(ResetSession node, Integer indent)
{
builder.append("RESET SESSION ")
.append(node.getName());
.append(formatName(node.getName()));

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,20 @@ public void testResetSession()
assertStatement("RESET SESSION foo", new ResetSession(QualifiedName.of("foo")));
}

@Test
public void testSessionIdentifiers()
{
assertStatement("SET SESSION \"foo-bar\".baz = 'x'",
new SetSession(QualifiedName.of("foo-bar", "baz"), new StringLiteral("x")));
assertStatementIsInvalid("SET SESSION foo-bar.name = 'value'")
.withMessage("line 1:16: mismatched input '-'. Expecting: '.', '='");

assertStatement("RESET SESSION \"foo-bar\".baz",
new ResetSession(QualifiedName.of("foo-bar", "baz")));
assertStatementIsInvalid("RESET SESSION foo-bar.name")
.withMessage("line 1:18: mismatched input '-'. Expecting: '.', <EOF>");
}

@Test
public void testShowSession()
{
Expand Down

0 comments on commit 38d7d5b

Please sign in to comment.