laskoviymishka commented on code in PR #818: URL: https://github.com/apache/iceberg-go/pull/818#discussion_r3005882919
########## table/equality_delete_reader.go: ########## @@ -0,0 +1,391 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package table + +import ( + "bytes" + "context" + "encoding/binary" + "fmt" + "math" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/compute" + "github.com/apache/iceberg-go" + iceinternal "github.com/apache/iceberg-go/internal" + iceio "github.com/apache/iceberg-go/io" + "github.com/apache/iceberg-go/table/internal" + "golang.org/x/sync/errgroup" +) + +// equalityDeleteSet holds the set of delete keys and the column names +// used to look them up in data records. Each set corresponds to one +// group of equality field IDs — delete files with different field IDs +// produce separate sets. +type equalityDeleteSet struct { + keys set[string] + fieldIDs []int + colNames []string +} + +// readAllEqualityDeleteFiles reads all unique equality delete files from +// the tasks and builds per-task delete key sets. Returns nil if there are +// no equality deletes. Delete files with different equality field IDs are +// kept as separate sets (not merged). +func readAllEqualityDeleteFiles(ctx context.Context, fs iceio.IO, schema *iceberg.Schema, tasks []FileScanTask, concurrency int) (map[int][]*equalityDeleteSet, error) { + type deleteFileInfo struct { + file iceberg.DataFile + fieldIDs []int + } + + uniqueDeletes := make(map[string]deleteFileInfo) + hasAny := false + + for _, t := range tasks { + for _, d := range t.EqualityDeleteFiles { + if d.ContentType() != iceberg.EntryContentEqDeletes { + continue + } + + hasAny = true + if _, ok := uniqueDeletes[d.FilePath()]; !ok { + uniqueDeletes[d.FilePath()] = deleteFileInfo{ + file: d, + fieldIDs: d.EqualityFieldIDs(), + } + } + } + } + + if !hasAny { + return nil, nil + } + + type deleteFileResult struct { + path string + fieldIDs []int + colNames []string + keys set[string] + } + + g, ctx := errgroup.WithContext(ctx) + g.SetLimit(concurrency) + + resultCh := make(chan deleteFileResult, len(uniqueDeletes)) + + go func() { + defer close(resultCh) + + for _, info := range uniqueDeletes { + g.Go(func() error { + keys, colNames, err := readEqualityDeleteFile(ctx, fs, schema, info.file, info.fieldIDs) + if err != nil { + return err + } + + resultCh <- deleteFileResult{ + path: info.file.FilePath(), + fieldIDs: info.fieldIDs, + colNames: colNames, + keys: keys, + } + + return nil + }) + } + + _ = g.Wait() + }() + + type perFileDeleteKeys struct { + fieldIDs []int + colNames []string + keys set[string] + } + + perFile := make(map[string]*perFileDeleteKeys) + for result := range resultCh { + perFile[result.path] = &perFileDeleteKeys{ + fieldIDs: result.fieldIDs, + colNames: result.colNames, + keys: result.keys, + } + } + + if err := g.Wait(); err != nil { Review Comment: good catch! -- 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]
