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


##########
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:
   Thanks for the review! Agreed, whichever PR lands second will merge `main` 
and make sure millisecond timestamp normalization runs on the rebuilt manifest 
after `ReadDictionaries`.



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

Review Comment:
   I kept it private by default just because it's hard to take back a public 
API. LMK if you want this to be public instead.



##########
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:
   Added a short comment above the call explaining that `defaultToArray` has no 
context parameter and only uses the context to pass `alloc`.



##########
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:
   Added that note to both the `WithDictionaryColumns` doc comment and 
`website/src/api.md`.



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