nssalian commented on code in PR #2002:
URL: https://github.com/apache/iceberg-go/pull/2002#discussion_r4040108892


##########
table/internal/parquet_files.go:
##########
@@ -711,9 +711,91 @@ func getWriteProperties(writeProps any, arrowSchema 
*arrow.Schema) (*parquet.Wri
                wp = append(wp, parquet.WithStoreDecimalAsInteger(true))
        }
 
+       // Match Iceberg Java: apply parquet-mr's cost-based dictionary 
fallback to every leaf
+       // column so high-cardinality columns fall back to PLAIN rather than 
keeping a dictionary.
+       // arrow-go otherwise enables it only for uncompressed columns, so zstd 
(our default) would
+       // retain dictionaries on all-distinct columns and roughly double their 
size.
+       costFallback, err := dictCostFallbackProps(arrowSchema, wp)
+       if err != nil {
+               return nil, err
+       }
+       wp = append(wp, costFallback...)
+
        return parquet.NewWriterProperties(wp...), nil
 }
 
+// dictCostFallbackProps returns a WithDictionaryCostFallbackFor(true) 
property per leaf, walking the arrow schema directly (extensions unwrapped) and 
falling back to pqarrow.ToParquet for list/map schemas.
+func dictCostFallbackProps(arrowSchema *arrow.Schema, base 
[]parquet.WriterProperty) ([]parquet.WriterProperty, error) {
+       if schemaHasListOrMap(arrowSchema) {
+               return dictCostFallbackViaParquet(arrowSchema, base)

Review Comment:
   I added a `TestDictCostFallbackListSchemaUsesToParquet`: a `ListOf` schema, 
asserts `schemaHasListOrMap` is true (so `dictCostFallbackViaParquet` runs) and 
round-trips the leaf paths through `DictionaryCostFallbackEnabledFor`. Also 
unwrapped `*arrow.DictionaryType` in the walk and added a `dict` case to 
`TestDictCostFallbackWalkMatchesToParquet`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to