Skip to content

Commit

Permalink
[hotfix][table-common] Summarize VARBINARY(Int.MAX) to BYTES
Browse files Browse the repository at this point in the history
  • Loading branch information
twalthr committed May 16, 2019
1 parent 6a293ee commit 529dcbb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*
* <p>The serialized string representation is {@code VARBINARY(n)} where {@code n} is the maximum
* number of bytes. {@code n} must have a value between 1 and {@link Integer#MAX_VALUE} (both
* inclusive). If no length is specified, {@code n} is equal to 1.
* inclusive). If no length is specified, {@code n} is equal to 1. {@code BYTES} is a synonym for
* {@code VARBINARY(2147483647)}.
*/
@PublicEvolving
public final class VarBinaryType extends LogicalType {
Expand All @@ -44,6 +45,8 @@ public final class VarBinaryType extends LogicalType {

private static final String FORMAT = "VARBINARY(%d)";

private static final String MAX_FORMAT = "BYTES";

private static final Set<String> INPUT_OUTPUT_CONVERSION = conversionSet(
byte[].class.getName(),
"org.apache.flink.table.dataformat.BinaryArray");
Expand Down Expand Up @@ -86,6 +89,14 @@ public String asSerializableString() {
return withNullability(FORMAT, length);
}

@Override
public String asSummaryString() {
if (length == MAX_LENGTH) {
return withNullability(MAX_FORMAT);
}
return withNullability(FORMAT, length);
}

@Override
public boolean supportsInputConversion(Class<?> clazz) {
return INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ public void testVarBinaryType() {
);
}

@Test
public void testVarBinaryTypeWithMaximumLength() {
testAll(
new VarBinaryType(Integer.MAX_VALUE),
"VARBINARY(2147483647)",
"BYTES",
new Class[]{byte[].class},
new Class[]{byte[].class},
new LogicalType[]{},
new VarBinaryType(12)
);
}

@Test
public void testDecimalType() {
testAll(
Expand Down

0 comments on commit 529dcbb

Please sign in to comment.