zeroshade commented on code in PR #2677:
URL: https://github.com/apache/iceberg-go/pull/2677#discussion_r4669726012


##########
table/arrow_utils.go:
##########
@@ -790,6 +804,8 @@ type ArrowSchemaOptions struct {
        IncludeFieldIDs bool
        UseLargeTypes   bool
        TableProperties iceberg.Properties
+
+       dictionaryFieldIDs set[int]

Review Comment:
   With this field unexported, external callers of 
`SchemaToArrowSchemaWithOptions` and `ToRequestedSchema` (same on 
`SchemaOptions`) cannot request dictionary output. Fine if this is meant to 
stay internal for now; just checking that is intended.



##########
table/arrow_utils.go:
##########
@@ -1021,6 +1039,14 @@ func defaultToScalar(v any, t iceberg.Type, dt 
arrow.DataType) scalar.Scalar {
 
 // defaultToArray creates an Arrow array of length n filled with the given 
default value v.
 func defaultToArray(v any, t iceberg.Type, dt arrow.DataType, n int, alloc 
memory.Allocator) arrow.Array {
+       if dictType, ok := dt.(*arrow.DictionaryType); ok {
+               plain := defaultToArray(v, t, dictType.ValueType, n, alloc)
+               defer plain.Release()
+
+               return 
retOrPanic(compute.DictionaryEncodeArray(compute.WithAllocator(context.Background(),
 alloc),

Review Comment:
   nit: this uses `context.Background()` rather than the scan context. 
`defaultToArray` has no context to pass, so it is fine, but a short comment 
would keep someone from "fixing" it.



##########
table/table.go:
##########
@@ -1523,6 +1523,29 @@ func WithArrowBatchSize(n int) ScanOption {
        }
 }
 
+// WithDictionaryColumns returns the named string and binary columns as Arrow
+// dictionary arrays. Names may be dotted paths to nested fields. They are
+// resolved when the scan reads, against the schema it reads with, honoring
+// [WithCaseSensitive].
+//
+// Requested columns always have type dictionary<int32, utf8> or
+// dictionary<int32, binary>, in the declared schema and in every batch, even
+// with the arrow.use_large_types option or when a data file stores the column
+// plain, as a large type, or as another dictionary type. Columns that are not
+// requested keep their usual types.
+//
+// The dictionary can differ from one batch to the next, including within a
+// file, so callers must not rely on dictionary identity across batches.

Review Comment:
   nit: worth mentioning here that filtering on a requested column decodes the 
dictionary per batch to evaluate the predicate, so a filtered scan may not get 
faster (the PR description measured ~0% to +5.8%).



##########
table/internal/parquet_files.go:
##########
@@ -2314,6 +2314,71 @@ func (w wrapPqArrowReader) PrunedSchema(projectedIDs 
map[int]struct{}, mapping i
        return pruneParquetColumns(w.Manifest, projectedIDs, false, mapping)
 }
 
+// ReadDictionaries rebuilds the schema manifest because pqarrow decides
+// dictionary reads when it builds the manifest, not when it reads. The value
+// receiver is safe: the writes go through the embedded *pqarrow.FileReader.
+func (w wrapPqArrowReader) ReadDictionaries(fieldIDs map[int]struct{}, mapping 
iceberg.NameMapping) error {

Review Comment:
   #2675 also changes `wrapPqArrowReader` (`PrunedSchema`, `GetRecords`). 
Whichever lands second will need a rebase, and the millisecond timestamp 
normalization there should run on the manifest after `ReadDictionaries` 
rebuilds it.



-- 
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