Skip to content
Permalink
Browse files

Quote identifier name during row subscript desugar

Names can be reserved SQL keywords, so we need to quote them
to avoid issues when deserializing plans on workers.
  • Loading branch information
martint committed Nov 6, 2019
1 parent 3a2557b commit 3fab865cb6b3764375132e789e00f9cb2dda3193
@@ -169,8 +169,8 @@ public void parseRowSignature()
assertSignature(
"row( time time with time zone, array( interval day to seconds ) )",
"row",
ImmutableList.of("time time with time zone", "array(interval day to seconds)"),
"row(time time with time zone,array(interval day to seconds))");
ImmutableList.of("\"time\" time with time zone", "array(interval day to seconds)"),
"row(\"time\" time with time zone,array(interval day to seconds))");

// preserve base name case
assertRowSignature(
@@ -302,7 +302,6 @@ private static void assertRowSignature(
{
TypeSignature signature = parseTypeSignature(typeName, literalParameters);
assertEquals(signature, expectedSignature);
assertEquals(signature.toString(), typeName);
}

private static void assertRowSignature(
@@ -65,7 +65,7 @@ public boolean equals(Object o)
public String toString()
{
if (fieldName.isPresent()) {
return format("%s %s", fieldName.get(), typeSignature);
return format("\"%s\" %s", fieldName.get().getName().replace("\"", "\"\""), typeSignature);
}
return typeSignature.toString();
}
@@ -446,6 +446,16 @@ public void testRowFieldAccessorInJoin()
"SELECT * FROM VALUES (11, 370, 1), (22, 781, 2), (33, 1234, 3)");
}

@Test
public void testRowTypeWithReservedKeyword()
{
// This test is here because it only reproduces the issue (https://github.com/prestosql/presto/issues/1962)
// when running in distributed mode
assertQuery(
"SELECT cast(row(1) AS row(\"cross\" bigint)).\"cross\"",
"VALUES 1");
}

@Test
public void testRowCast()
{

0 comments on commit 3fab865

Please sign in to comment.
You can’t perform that action at this time.