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

Stop leaking Avro objects from parser #12828

Merged
merged 4 commits into from
Aug 17, 2022

Conversation

imply-cheddar
Copy link
Contributor

The Avro parsing code leaks some "object" representations. We need to convert them into Maps/Lists so that other code can understand and expect good things.

Previously, these objects were handled with .toString(), but that's not a good contract in terms of how to work with objects. That said, this does potentially introduce a chance for "backwards incompatibility" because anybody who happened to actually have these objects "leak" into their ingestion would have ended up with these objects being stored as a String column with a value as the .toString(). When they update to this new code, they will still have a String column, but it will be the String returned from Map.toString() instead of the GenericRecord.toString. So, the actual content would be slightly different.

Relying on this behavior is... questionable at best. If someone is actually relying on this, then they can have the option of grabbing the avro extension from a previous version and continuing to use that instead of using this updated version. In terms of the behavior expected out-of-the-box from the code, the behavior that this change creates is significantly better. So, given that depending on the previous behavior is likely to be low value anyway and that there is a meaningful workaround in that you can choose to use the old extension jar instead, we should accept the compatibility change and make forward progress.

This PR has:

  • been self-reviewed.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • been tested in a test Druid cluster.

The Avro parsing code leaks some "object" representations.
We need to convert them into Maps/Lists so that other code
can understand and expect good things.  Previously, these
objects were handled with .toString(), but that's not a
good contract in terms of how to work with objects.
Copy link
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

makes sense to me 👍

@@ -173,6 +175,20 @@ private Object transformValue(final Object field)
} else {
return ((GenericFixed) field).bytes();
}
} else if (field instanceof Map) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should use like if (avroJsonProvider.isArray(field)) ... andif (avroJsonProvider.isMap(field)) ...
There are also methods like avroJsonProvider.length, avroJsonProvider.getArrayIndex, avroJsonProvider.getPropertyKeys, avroJsonProvider.getMapValue etc. which could be used to extract stuff, though the array one doesn't seem that useful since it just handles List anyway.

@@ -164,7 +166,7 @@ private Object transformValue(final Object field)
} else if (field instanceof Utf8) {
return field.toString();
} else if (field instanceof List) {
return ((List<?>) field).stream().filter(Objects::nonNull).collect(Collectors.toList());
return ((List<?>) field).stream().filter(Objects::nonNull).map(this::transformValue).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

this could possibly generate new output for a list which has ByteBuffer in it. But I think if anyone is using this then their data might look absurd since doing a toString on ByteBuffer doesn't return the backed bytes.

@@ -0,0 +1 @@
This extension enables parsing of Avro data
Copy link
Member

Choose a reason for hiding this comment

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

heh, this readme is causing the license check stuff to fail because it is missing a license header. Suggest deleting since its basically empty, or adding

<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
``` to make the checks happy

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

Successfully merging this pull request may close these issues.

None yet

4 participants