-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Make null key serialization/deserialization symmetrical #4351
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient; | ||
import io.confluent.ksql.name.ColumnName; | ||
|
@@ -148,6 +149,7 @@ public void shouldThrowOnValidateIfStruct() { | |
@Test | ||
public void shouldHandleNulls() { | ||
shouldHandle(SqlTypes.INTEGER, null); | ||
shouldHandle(SqlTypes.STRING, null); | ||
} | ||
|
||
@Test | ||
|
@@ -192,7 +194,11 @@ private void shouldHandle(final SqlType fieldSchema, final Object value) { | |
final Object result = serde.deserializer().deserialize("topic", bytes); | ||
|
||
// Then: | ||
assertThat(result, is(struct)); | ||
if (value == null) { | ||
assertThat(result, is(nullValue())); | ||
} else { | ||
assertThat(result, is(struct)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if its null, then assert its null... weird asserting! ;) Also, this means all of the tests will pass if deserialize always returns I think it would be more explicit if we revert this change and instead have explicit tests that test we: a) serialize Just played around with this, so may as well share the code. i.e. we revert this to: assertThat(result, is(struct)); And replace @Test
public void shouldSerializeNullAsNull() {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(SqlTypes.INTEGER);
final Serde<Object> serde = factory.createSerde(schema, ksqlConfig, srClientFactory);
// When:
final byte[] result = serde.serializer().serialize("topic", null);
// Then:
assertThat(result, is(nullValue()));
}
@Test
public void shouldDeserializeNullAsNull() {
// Given:
final PersistenceSchema schema = schemaWithFieldOfType(SqlTypes.INTEGER);
final Serde<Object> serde = factory.createSerde(schema, ksqlConfig, srClientFactory);
// When:
final Object result = serde.deserializer().deserialize("topic", null);
// Then:
assertThat(result, is(nullValue()));
} |
||
} | ||
|
||
private static PersistenceSchema schemaWithFieldOfType(final SqlType fieldSchema) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if
primitive
isnull
, then could return after line 142.