Hive: Fix conversion failure for nested VARIANT and reduce type-string allocations - #16735
Hive: Fix conversion failure for nested VARIANT and reduce type-string allocations#16735wombatu-kun wants to merge 1 commit into
Conversation
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
|
not stale |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
…g allocations Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a55e7b1 to
05a1521
Compare
Problem
HiveSchemaUtil.convert(Schema)builds the Hive column list on every Hive table and view commit (viaHiveOperationsBase.storageDescriptor). For nested types it recursed throughconvert(Type), which isTypeInfoUtils.getTypeInfoFromTypeString(convertToTypeString(type)): it built the type substring, parsed it back into a HiveTypeInfotree, then stringified that tree straight back to the same substring. That round trip produces no value, and because the recursion went through the parser at every nesting level the wasted work and the throwawayTypeInfoallocations compounded with schema depth.It was also a latent crash. An Iceberg
VARIANTmaps to the placeholder string"unknown", which is not a Hive type, soTypeInfoUtils.getTypeInfoFromTypeString("unknown")throwsRuntimeException: Internal error parsing position 0 of 'unknown'. AVARIANTnested inside astruct/list/maptherefore failed the commit outright. The top-level case never hit this becauseconvert(Schema)callsconvertToTypeStringdirectly.Change
Rewrite the private
convertToTypeStringto recurse on itself via aStringBuilder-basedappendTypeString(StringBuilder, Type), building the Hive type string directly with noTypeInfoUtilsparsing and noString.format. The public methods and their outputs are unchanged; only the internal string builder is restructured. Output strings are identical for every type the previous code handled, which is pinned byte for byte by the existingtestComplexSchemaConvertToHiveSchema. NestedVARIANTnow emits"unknown"directly, consistent with the already-tested top-level mapping.Tests
testNestedVariantTypeConvertToHiveSchema: it throws on the previous code (reproducing the failure) and is green after the change.TestHiveSchemaUtilcoverage (nested struct/list/map strings, every primitive type, reverse conversion) still passes, confirming output is unchanged for all other types.Performance
Added
HiveSchemaConversionBenchmark(JMH). The conversion runs once per commit; the benchmark isolatesHiveSchemaUtil.convert(Schema). JDK 17, average time,-prof gc(speedup is before/after):Flat schemas are essentially unchanged (primitive cases never used the parsing path); the gain is concentrated on nested schemas, where the throwaway
TypeInfotrees dominated, and grows with nesting depth (the old code re-parsed each subtree at every level).AI Disclosure