Skip to content

Commit

Permalink
Fix type signature serialization for varchar
Browse files Browse the repository at this point in the history
Varchar without length should serialize without a length
rather than using the internal MAX_INT representation.
  • Loading branch information
electrum committed Feb 11, 2016
1 parent 09d7a2e commit 918ecbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,16 @@ private static String parseFieldName(String fieldName)
@JsonValue
public String toString()
{
// TODO: remove these hacks
if (base.equalsIgnoreCase(StandardTypes.ROW)) {
return rowToString();
}
else if (base.equalsIgnoreCase(StandardTypes.VARCHAR) &&
(parameters.size() == 1) &&
parameters.get(0).isLongLiteral() &&
parameters.get(0).getLongLiteral() == VarcharType.MAX_LENGTH) {
return base;
}
else {
StringBuilder typeName = new StringBuilder(base);
if (!parameters.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Map;

import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.facebook.presto.spi.type.VarcharType.createVarcharType;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

Expand Down Expand Up @@ -144,6 +146,14 @@ public void parseWithLiteralParameters()
assertSignature("varchar(10)", "varchar", ImmutableList.<String>of("10"));
}

@Test
public void testVarchar()
throws Exception
{
assertEquals(VARCHAR.getTypeSignature().toString(), "varchar");
assertEquals(createVarcharType(42).getTypeSignature().toString(), "varchar(42)");
}

private static void assertRowSignature(
String typeName,
String base,
Expand Down

0 comments on commit 918ecbe

Please sign in to comment.