Skip to content

Commit

Permalink
fix spelling, address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Jan 5, 2024
1 parent c88adc2 commit b712355
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
*
* otherwise
* Long:Integer:bytes
*
* The StringSize can be following:
* -1 : Denotes an empty string
* 0 : Denotes a null string
* >0 : Denotes a non-empty string
*
* Mapping of null and empty string is done weirdly to preserve backward compatibility when nulls were returned all the
* time, and there was no distinction between empty and null string
*/
public class SerializablePairLongStringDeltaEncodedStagedSerde implements StagedSerde<SerializablePairLongString>
{
Expand Down Expand Up @@ -76,6 +84,8 @@ public void store(ByteBuffer byteBuffer)
}

if (rhsString == null) {
byteBuffer.putInt(0);
} else if (rhsBytes.length == 0) {
byteBuffer.putInt(-1);
} else {
byteBuffer.putInt(rhsBytes.length);
Expand Down Expand Up @@ -116,11 +126,13 @@ public SerializablePairLongString deserialize(ByteBuffer byteBuffer)
int stringSize = readOnlyBuffer.getInt();
String lastString = null;

if (stringSize >= 0) {
if (stringSize > 0) {
byte[] stringBytes = new byte[stringSize];

readOnlyBuffer.get(stringBytes, 0, stringSize);
lastString = StringUtils.fromUtf8(stringBytes);
} else if (stringSize < 0) {
lastString = "";
}

return new SerializablePairLongString(lhs, lastString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
* <p>
* or
* Long:StringSize:StringData
*
* The StringSize can be following:
* -1 : Denotes an empty string
* 0 : Denotes a null string
* >0 : Denotes a non-empty string
*
* Mapping of null and empty string is done weirdly to preserve backward compatibility when nulls were returned all the
* time, and there was no distinction between empty and null string
*/
public class SerializablePairLongStringSimpleStagedSerde implements StagedSerde<SerializablePairLongString>
{
Expand All @@ -56,6 +64,8 @@ public void store(ByteBuffer byteBuffer)

byteBuffer.putLong(value.lhs);
if (rhsString == null) {
byteBuffer.putInt(0);
} else if (rhsBytes.length == 0) {
byteBuffer.putInt(-1);
} else {
byteBuffer.putInt(rhsBytes.length);
Expand Down Expand Up @@ -87,11 +97,13 @@ public SerializablePairLongString deserialize(ByteBuffer byteBuffer)
int stringSize = readOnlyBuffer.getInt();
String lastString = null;

if (stringSize >= 0) {
if (stringSize > 0) {
byte[] stringBytes = new byte[stringSize];

readOnlyBuffer.get(stringBytes, 0, stringSize);
lastString = StringUtils.fromUtf8(stringBytes);
} else if (stringSize < 0) {
lastString = "";
}

return new SerializablePairLongString(lhs, lastString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.nio.ByteOrder;
import java.util.Random;

public class BackwordCompatibleSerializablePairLongStringDeltaEncodedStagedSerdeTest
public class BackwardCompatibleSerializablePairLongStringDeltaEncodedStagedSerdeTest
{
private static final OlderSerializablePairLongStringDeltaEncodedStagedSerde OLDER_INTEGER_SERDE =
new OlderSerializablePairLongStringDeltaEncodedStagedSerde(0L, true);
Expand Down Expand Up @@ -71,11 +71,11 @@ public void testNullString()

// Write using the older serde, read using the newer serde
Assert.assertEquals(
new SerializablePairLongString(TIMESTAMP, ""),
new SerializablePairLongString(TIMESTAMP, null),
readUsingSerde(writeUsingSerde(value, OLDER_INTEGER_SERDE), INTEGER_SERDE)
);
Assert.assertEquals(
new SerializablePairLongString(TIMESTAMP, ""),
new SerializablePairLongString(TIMESTAMP, null),
readUsingSerde(writeUsingSerde(value, OLDER_LONG_SERDE), LONG_SERDE)
);

Expand Down Expand Up @@ -104,11 +104,11 @@ public void testEmptyString()

// Write using the older serde, read using the newer serde
Assert.assertEquals(
new SerializablePairLongString(TIMESTAMP, ""),
new SerializablePairLongString(TIMESTAMP, null),
readUsingSerde(writeUsingSerde(value, OLDER_INTEGER_SERDE), INTEGER_SERDE)
);
Assert.assertEquals(
new SerializablePairLongString(TIMESTAMP, ""),
new SerializablePairLongString(TIMESTAMP, null),
readUsingSerde(writeUsingSerde(value, OLDER_LONG_SERDE), LONG_SERDE)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.nio.ByteOrder;
import java.util.Random;

public class BackwordCompatibleSerializablePairLongStringSimpleStagedSerdeTest
public class BackwardCompatibleSerializablePairLongStringSimpleStagedSerdeTest
{
private static final OlderSerializablePairLongStringSimpleStagedSerde OLDER_SERDE =
new OlderSerializablePairLongStringSimpleStagedSerde();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testNullStringLong()
@Test
public void testEmptyStringLong()
{
assertValueEquals(new SerializablePairLongString(100L, ""), 8, LONG_SERDE);
assertValueEquals(new SerializablePairLongString(100L, ""), 12, LONG_SERDE);
}


Expand Down

0 comments on commit b712355

Please sign in to comment.