-
Notifications
You must be signed in to change notification settings - Fork 57
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
[Do not merg] TMP #866
Closed
+73
−4
Closed
[Do not merg] TMP #866
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,18 +418,31 @@ private static ParquetBufferValue getStructValue( | |
DataValidationUtil.validateAndParseIcebergStruct(path, value, insertRowsCurrIndex); | ||
Set<String> extraFields = new HashSet<>(structVal.keySet()); | ||
List<Object> listVal = new ArrayList<>(type.getFieldCount()); | ||
|
||
float estimatedParquetSize = 0f; | ||
for (int i = 0; i < type.getFieldCount(); i++) { | ||
StringBuilder sb = new StringBuilder(); | ||
String fieldName = type.getFieldName(i); | ||
for (int j = 0; j < fieldName.length(); j++) { | ||
if (fieldName.charAt(j) == '_') { | ||
sb.append((char) Integer.parseInt(fieldName.substring(j + 2, j + 4), 16)); | ||
j += 3; | ||
} else { | ||
sb.append(fieldName.charAt(j)); | ||
} | ||
} | ||
String originalFieldName = sb.substring(0, sb.toString().lastIndexOf('_')); | ||
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. We need this for extra field validation. |
||
|
||
ParquetBufferValue parsedValue = | ||
parseColumnValueToParquet( | ||
structVal.getOrDefault(type.getFieldName(i), null), | ||
structVal.getOrDefault(originalFieldName, null), | ||
type.getType(i), | ||
statsMap, | ||
defaultTimezone, | ||
insertRowsCurrIndex, | ||
path, | ||
isDescendantsOfRepeatingGroup); | ||
extraFields.remove(type.getFieldName(i)); | ||
extraFields.remove(originalFieldName); | ||
listVal.add(parsedValue.getValue()); | ||
estimatedParquetSize += parsedValue.getSize(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ public static Type getTypeFromJson(@Nonnull JsonNode jsonNode) { | |
field.isObject(), "Cannot parse struct field from non-object: %s", field); | ||
|
||
int id = JsonUtil.getInt(ID, field); | ||
String name = JsonUtil.getString(NAME, field); | ||
String name = (JsonUtil.getString(NAME, field) + "_" + id).replace("_", "_x5F"); | ||
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. Encode all "_" to its hex, same idea as escape. |
||
Type type = getTypeFromJson(field.get(TYPE)); | ||
|
||
String doc = JsonUtil.getStringOrNull(DOC, field); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doing this stringbuilder business on the hotpath will make performance even worse.
Have two suggestions:
Option 1:
Option 2:
return str.replace("_", "_x" + Integer.toHexString("_").toUpperCase())
This combined with AvroSchemaUtil's internal behavior to escape every non-digit, non-letter, non-underscore character, will make sure we are able to generate safe non-colliding names. tldr with this fix we're making sure everything except digits and numbers is getting escaped properly, and effectively fixing AvroSchemaUtil's bug
In both cases, switching what we iterate on will need to be accompanied by fixes in how extraFields collection's bookkeeping is done.
I prefer option 1 because it completely sidesteps AvroSchemaUtil's buggy behavior. But i'm not sure if there is an easy way to maintain this per-struct-type map somewhere and handle all nested struct situations where there's a series of structs embedded inside each other. Still putting it out here in case you can come up with something.
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.
Sounds good, will try option 1