Add Hadoop config option to auto-derive Parquet list encoding from writer schema#1341
Open
clairemcginty wants to merge 3 commits into
Open
Add Hadoop config option to auto-derive Parquet list encoding from writer schema#1341clairemcginty wants to merge 3 commits into
clairemcginty wants to merge 3 commits into
Conversation
clairemcginty
commented
Jun 23, 2026
|
|
||
| override private[parquet] def properties: MagnolifyParquetProperties = | ||
| propertiesWithAvroImportCompat | ||
| override private[parquet] def updateProperties( |
Contributor
Author
There was a problem hiding this comment.
this feels like a very non-idiomatic way to achieve this in Scala, but couldn't think of a better option that wouldn't break API compat
Contributor
There was a problem hiding this comment.
Maybe a private apply would seem nicer?
kellen
approved these changes
Jun 29, 2026
regadas
requested changes
Jun 30, 2026
regadas
left a comment
Contributor
There was a problem hiding this comment.
one thing worth confirming before moving ahead.
|
|
||
| val reader = pt | ||
| .readBuilder(...) | ||
| + .withConf(ParquetConfiguration.of("parquet.type.read.auto-detect-list-encoding" -> true) |
Contributor
There was a problem hiding this comment.
nit: missing )
Suggested change
| + .withConf(ParquetConfiguration.of("parquet.type.read.auto-detect-list-encoding" -> true) | |
| + .withConf(ParquetConfiguration.of("parquet.type.read.auto-detect-list-encoding" -> true)) |
Comment on lines
+98
to
+136
| def detectArrayEncoding(schema: Type): Option[ArrayEncoding] = { | ||
| val encodings = scala.collection.mutable.Set.empty[ArrayEncoding] | ||
|
|
||
| def visit(t: Type): Unit = t match { | ||
| case g: GroupType if g.getLogicalTypeAnnotation == LogicalTypeAnnotation.listType() => | ||
| g.getFields.asScala.headOption match { | ||
| case Some(child) if child.getName == "list" => | ||
| encodings += ArrayEncoding.ThreeLevelList | ||
| case Some(child) if child.getName == "array" => | ||
| encodings += ArrayEncoding.ThreeLevelArray | ||
| case Some(_) => | ||
| throw new InvalidRecordException( | ||
| s"Schema contained unsupported list encoding ```$t```;" + | ||
| s" child element of LIST annotation must be one of: [list, array]`" | ||
| ) | ||
| case None => | ||
| } | ||
| g.getFields.asScala.foreach(visit) | ||
| case g: GroupType => | ||
| g.getFields.asScala.foreach(visit) | ||
| case t: PrimitiveType if t.getRepetition == Repetition.REPEATED => | ||
| encodings += ArrayEncoding.Ungrouped | ||
| case _ => | ||
| } | ||
|
|
||
| schema match { | ||
| case g: GroupType => g.getFields.asScala.foreach(visit) | ||
| case _ => | ||
| } | ||
|
|
||
| if (encodings.size > 1) { | ||
| throw new InvalidRecordException( | ||
| s"Multiple list encodings detected in writer schema: ${encodings.mkString(", ")}. " + | ||
| "Cannot auto-detect list encoding." | ||
| ) | ||
| } | ||
|
|
||
| encodings.headOption | ||
| } |
Contributor
There was a problem hiding this comment.
hmm maybe I'm wrong but the current 2-level-array test fixtures use a group element, so we're missing a primitive-element unit test + roundtrip? If so I think this path might be broken for 2-level array encoding over primitive elements ... throwing "Multiple list encodings".
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(branched off #1340; once that's merged I'll update the base ref)
Adds a hadoop configuration flag
parquet.type.read.auto-detect-list-encodingthat will instruct ParquetType to auto-detect list encoding based off writer schema.todo: update benchmarks to check added ms cost per file