Skip to content

Commit

Permalink
Revert changes in SingleValueParser for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
wmoustafa committed Apr 28, 2023
1 parent b20b765 commit 70ae07b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions core/src/main/java/org/apache/iceberg/SingleValueParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static Object fromJson(Type type, JsonNode defaultValue) {
defaultLength);
byte[] fixedBytes =
BaseEncoding.base16().decode(defaultValue.textValue().toUpperCase(Locale.ROOT));
return fixedBytes;
return ByteBuffer.wrap(fixedBytes);
case BINARY:
Preconditions.checkArgument(
defaultValue.isTextual(), "Cannot parse default as a %s value: %s", type, defaultValue);
Expand Down Expand Up @@ -236,7 +236,7 @@ public static String toJson(Type type, Object defaultValue, boolean pretty) {
return JsonUtil.generate(gen -> toJson(type, defaultValue, gen), pretty);
}

@SuppressWarnings({"checkstyle:MethodLength", "checkstyle:CyclomaticComplexity"})
@SuppressWarnings("checkstyle:MethodLength")
public static void toJson(Type type, Object defaultValue, JsonGenerator generator)
throws IOException {
if (defaultValue == null) {
Expand Down Expand Up @@ -303,28 +303,17 @@ public static void toJson(Type type, Object defaultValue, JsonGenerator generato
generator.writeString(defaultValue.toString());
break;
case FIXED:
// Normally, FIXED is backed by a byte[], but it can also be backed by a ByteBuffer in the
// case of Fixed Literals. Ideally, Fixed Literals would be backed by a byte[], but that
// would make the APIs backwards incompatible.
// See {@link org.apache.iceberg.expressions.Literals.FixedLiteral}.
Preconditions.checkArgument(
defaultValue instanceof byte[] || defaultValue instanceof ByteBuffer,
"Invalid default %s value: %s",
type,
defaultValue);
byte[] byteArrayValue;
if (defaultValue instanceof ByteBuffer) {
byteArrayValue = ByteBuffers.toByteArray((ByteBuffer) defaultValue);
} else {
byteArrayValue = (byte[]) defaultValue;
}
defaultValue instanceof ByteBuffer, "Invalid default %s value: %s", type, defaultValue);
ByteBuffer byteBufferValue = (ByteBuffer) defaultValue;
int expectedLength = ((Types.FixedType) type).length();
Preconditions.checkArgument(
byteArrayValue.length == expectedLength,
byteBufferValue.remaining() == expectedLength,
"Invalid default %s value, incorrect length: %s",
type,
byteArrayValue.length);
generator.writeString(BaseEncoding.base16().encode(byteArrayValue));
byteBufferValue.remaining());
generator.writeString(
BaseEncoding.base16().encode(ByteBuffers.toByteArray(byteBufferValue)));
break;
case BINARY:
Preconditions.checkArgument(
Expand Down

0 comments on commit 70ae07b

Please sign in to comment.