Skip to content

Commit 3fe0b45

Browse files
NaveenNitturuhantangwangd
authored andcommitted
Handle special characters in column names and subfields
1 parent af4fc61 commit 3fe0b45

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

presto-common/src/main/java/com/facebook/presto/common/SubfieldTokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private Subfield.PathElement matchDollarPathElement()
153153

154154
private static boolean isUnquotedPathCharacter(char c)
155155
{
156-
return c == ':' || c == '$' || c == '-' || c == '/' || c == '@' || c == '|' || c == '#' || c == ' ' || isUnquotedSubscriptCharacter(c);
156+
return c == ':' || c == '$' || c == '-' || c == '/' || c == '@' || c == '|' || c == '#' || c == ' ' || c == '<' || c == '>' || isUnquotedSubscriptCharacter(c);
157157
}
158158

159159
private Subfield.PathElement matchUnquotedSubscript()

presto-common/src/test/java/com/facebook/presto/common/TestSubfieldTokenizer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ public void testColumnNames()
8282
assertPath(new Subfield("a and b", ImmutableList.of()));
8383
}
8484

85+
@Test
86+
public void testAngleBracketsInColumnNames()
87+
{
88+
assertPath(new Subfield("<>col", ImmutableList.of()));
89+
assertPath(new Subfield("col<with>brackets", ImmutableList.of()));
90+
assertPath(new Subfield("<>col", ImmutableList.of(new NestedField("<>field"))));
91+
assertPath(new Subfield("table", ImmutableList.of(new NestedField("<>field"))));
92+
assertPath(new Subfield("table", ImmutableList.of(new Subfield.StringSubscript("<>value>"))));
93+
assertPath(new Subfield("<table>", ImmutableList.of(
94+
new NestedField("<field>"),
95+
new Subfield.StringSubscript("<value>"))));
96+
}
97+
8598
@Test
8699
public void testInvalidPaths()
87100
{

presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,15 @@ public void testHiddenColumns()
20512051
testDataSequenceNumberHiddenColumn();
20522052
}
20532053

2054+
@Test
2055+
public void testDeleteWithSpecialCharacterColumnName()
2056+
{
2057+
assertUpdate("CREATE TABLE test_special_character_column_name (\"<age>\" int, name varchar)");
2058+
assertUpdate("INSERT INTO test_special_character_column_name VALUES (1, 'abc'), (2, 'def'), (3, 'ghi')", 3);
2059+
assertUpdate("DELETE FROM test_special_character_column_name where \"<age>\" = 2", 1);
2060+
assertUpdate("DROP TABLE IF EXISTS test_special_character_column_name");
2061+
}
2062+
20542063
@Test
20552064
public void testDeletedHiddenColumn()
20562065
{

0 commit comments

Comments
 (0)