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
Cherry-pick of trinodb/trino#11171
The SqlFormatter effectively drops quotes from the quoted identifiers
when formatting 'SET SESSION' statement.
This causes valid queries to fail: e.g. SET SESSION
"name-suffix".property = 'value' PrestoException: Formatted query does
not parse even when identifier (name-suffix) is quoted.

Follow up prestodb#17186

Co-authored-by: Sergey Melnychuk <[email protected]>
  • Loading branch information
v-jizhang and Sergey Melnychuk committed Mar 4, 2022
1 parent fce3301 commit d31c45a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ protected Void visitInsert(Insert node, Integer indent)
public Void visitSetSession(SetSession node, Integer context)
{
builder.append("SET SESSION ")
.append(node.getName())
.append(formatName(node.getName()))
.append(" = ")
.append(formatExpression(node.getValue(), parameters));

Expand All @@ -1256,7 +1256,7 @@ public Void visitSetSession(SetSession node, Integer context)
public Void visitResetSession(ResetSession node, Integer context)
{
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 @@ -696,6 +696,19 @@ 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")));
assertInvalidStatement("SET SESSION foo-bar.name = 'value'",
"mismatched input '-'. Expecting: '.', '='");
assertStatement("RESET SESSION \"foo-bar\".baz",
new ResetSession(QualifiedName.of("foo-bar", "baz")));
assertInvalidStatement("RESET SESSION foo-bar.name",
"mismatched input '-'. Expecting: '.', <EOF>");
}

@Test
public void testShowSession()
{
Expand Down

0 comments on commit d31c45a

Please sign in to comment.