Skip to content

Commit 51b4625

Browse files
committed
[FLINK-38268] Fix incorrect serialization of VARIANT type FLOAT
1 parent 80a95ef commit 51b4625

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantInternalBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void appendTimestamp(long microsSinceEpoch) {
290290
public void appendFloat(float f) {
291291
checkCapacity(1 + 4);
292292
writeBuffer[writePos++] = primitiveHeader(FLOAT);
293-
writeLong(writeBuffer, writePos, Float.floatToIntBits(f), 8);
293+
writeLong(writeBuffer, writePos, Float.floatToIntBits(f), 4);
294294
writePos += 4;
295295
}
296296

flink-core/src/test/java/org/apache/flink/types/variant/BinaryVariantInternalBuilderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.math.BigDecimal;
2525

2626
import static org.assertj.core.api.Assertions.assertThat;
27+
import static org.assertj.core.api.Assertions.assertThatCode;
2728
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2829

2930
class BinaryVariantInternalBuilderTest {
@@ -116,4 +117,17 @@ void testParseJsonObject() throws IOException {
116117
assertThat(variant.getField("k1").getByte()).isEqualTo((byte) 2);
117118
assertThat(variant.getField("k2").getDecimal()).isEqualTo(BigDecimal.valueOf(1.5));
118119
}
120+
121+
@Test
122+
void testAppendFloat(){
123+
BinaryVariantInternalBuilder builder = new BinaryVariantInternalBuilder(false);
124+
float[] floats = new float[25];
125+
java.util.Arrays.fill(floats, 4.2f);
126+
127+
assertThatCode(()->{
128+
for (float f : floats) {
129+
builder.appendFloat(f);
130+
}
131+
}).doesNotThrowAnyException();
132+
}
119133
}

0 commit comments

Comments
 (0)