Skip to content
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

Merged
merged 6 commits into from
Jan 10, 2018

Conversation

hjafarpour
Copy link
Contributor

@hjafarpour hjafarpour commented Jan 2, 2018

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

@hjafarpour hjafarpour self-assigned this Jan 2, 2018
@hjafarpour hjafarpour changed the title Skip the '@` character in the beginning of the field name in JSON Skip the '@' character in the beginning of the field name in JSON Jan 2, 2018
@@ -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("@")) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertThat and below.

Copy link
Contributor Author

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) ==
Copy link
Contributor

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

Copy link
Contributor

@dguy dguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@bluemonk3y bluemonk3y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hjafarpour hjafarpour merged commit 070dbc2 into confluentinc:master Jan 10, 2018
@apurvam apurvam mentioned this pull request Feb 13, 2018
@javadevmtl
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants