Skip to content

Commit 52d819f

Browse files
committed
fix lint, missing func
1 parent b384c0f commit 52d819f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

catalog/catalog.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"crypto/tls"
2323
"errors"
24+
"fmt"
25+
"maps"
2426
"net/url"
2527
"strings"
2628

@@ -203,6 +205,51 @@ func NamespaceFromIdent(ident table.Identifier) table.Identifier {
203205
return ident[:len(ident)-1]
204206
}
205207

208+
func checkForOverlap(removals []string, updates iceberg.Properties) error {
209+
overlap := []string{}
210+
for _, key := range removals {
211+
if _, ok := updates[key]; ok {
212+
overlap = append(overlap, key)
213+
}
214+
}
215+
if len(overlap) > 0 {
216+
return fmt.Errorf("conflict between removals and updates for keys: %v", overlap)
217+
}
218+
return nil
219+
}
220+
221+
func getUpdatedPropsAndUpdateSummary(currentProps iceberg.Properties, removals []string, updates iceberg.Properties) (iceberg.Properties, PropertiesUpdateSummary, error) {
222+
if err := checkForOverlap(removals, updates); err != nil {
223+
return nil, PropertiesUpdateSummary{}, err
224+
}
225+
var (
226+
updatedProps = maps.Clone(currentProps)
227+
removed = make([]string, 0, len(removals))
228+
updated = make([]string, 0, len(updates))
229+
)
230+
231+
for _, key := range removals {
232+
if _, exists := updatedProps[key]; exists {
233+
delete(updatedProps, key)
234+
removed = append(removed, key)
235+
}
236+
}
237+
238+
for key, value := range updates {
239+
if updatedProps[key] != value {
240+
updated = append(updated, key)
241+
updatedProps[key] = value
242+
}
243+
}
244+
245+
summary := PropertiesUpdateSummary{
246+
Removed: removed,
247+
Updated: updated,
248+
Missing: iceberg.Difference(removals, removed),
249+
}
250+
return updatedProps, summary, nil
251+
}
252+
206253
type createTableOpt func(*createTableCfg)
207254

208255
type createTableCfg struct {

0 commit comments

Comments
 (0)