-
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
Skip the '@' character in the beginning of the field name in JSON #581
Skip the '@' character in the beginning of the field name in JSON #581
Conversation
@@ -132,12 +132,18 @@ private Object enforceFieldType(Schema fieldSchema, JsonNode fieldJsonNode) { | |||
Iterator<String> fieldNames = jsonNode.fieldNames(); | |||
while (fieldNames.hasNext()) { | |||
String fieldName = fieldNames.next(); | |||
keyMap.put(fieldName.toUpperCase(), fieldName); | |||
if (fieldName.startsWith("@")) { |
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.
Is it possible that the fieldName could just be @
? in which case the next line would fail
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.
Field name cannot be '@' and if we have '@' as field name we should fail anyway.
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.
Maybe we should fail with a more meaningful exception? i.e.., not IndexOutOfBoundsException
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.
Added better error message for field name '@'.
KsqlJsonDeserializer ksqlJsonDeserializer = new KsqlJsonDeserializer(orderSchema); | ||
|
||
GenericRow genericRow = ksqlJsonDeserializer.deserialize("", jsonBytes); | ||
Assert.assertTrue(genericRow.getColumns().size() == 6); |
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.
use assertThat
and below.
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.
Done!
|
||
GenericRow genericRow = ksqlJsonDeserializer.deserialize("", jsonBytes); | ||
assertThat("Incorrect columns count.", genericRow.getColumns().size(), equalTo(6)); | ||
assertThat("Incorrect deserialization", (Long) genericRow.getColumns().get(0) == |
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.
assertThat(..., equalTo(...))
and elsewhere in the test
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.
LGTM
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.
lgtm
Hi, using 5.0.1 this still seems like an issue? Also using Logstash and Elastic and they do use @ for Logstash\Elastic related fields. |
This PR is to fix the issue reported in #572
Some data sources may create JSON data with
@
prefix for field name which is not acceptable as a valid column name in KSQL.In this PR we ignore the
@
in the beginning of the field names for JSON formats.Fixes #647 and Fixes #572 and Fixes #264