laskoviymishka commented on code in PR #2784:
URL: https://github.com/apache/iceberg-go/pull/2784#discussion_r4760708484


##########
table/compaction/compaction.go:
##########
@@ -65,8 +66,8 @@ type Config struct {
        DeleteRatioThreshold float64
 
        // PackingLookback controls how many open bins the packer considers
-       // before evicting. Higher values produce better packing at the cost
-       // of memory. Default: DefaultPackingLookback.
+       // before evicting. Must be at least 1. Higher values produce better
+       // packing at the cost of memory. Default: DefaultPackingLookback.

Review Comment:
   With "Must be at least 1" next to "Default: DefaultPackingLookback", this 
reads as if a zero value picks up the default, and after this PR it's rejected 
instead. Only `DefaultConfig()` sets it. `DeleteFileThreshold` uses the same 
"Default:" convention, so this is wording only:
   
   ```suggestion
        // packing at the cost of memory. DefaultConfig sets 
DefaultPackingLookback.
   ```



##########
table/compaction/compaction.go:
##########
@@ -171,6 +172,12 @@ func (cfg Config) Validate() error {
                return fmt.Errorf("max group size (%d) must be zero or at least 
the target file size (%d)",
                        cfg.MaxGroupSizeBytes, cfg.TargetFileSizeBytes)
        }
+       if cfg.PackingLookback == 0 {
+               return fmt.Errorf("packing lookback must be >= 1, got %d", 
cfg.PackingLookback)
+       }
+       if cfg.PackingLookback > math.MaxInt {
+               return fmt.Errorf("packing lookback (%d) exceeds max int (%d)", 
cfg.PackingLookback, math.MaxInt)

Review Comment:
   Could this one use the "must be" phrasing like the rest of `Validate`, e.g. 
`packing lookback must be <= %d, got %d`? The "exceeds max int" assertions in 
`TestConfig_Validate` and `TestPlanCompaction_InvalidPackingLookback` would 
change with it.



##########
table/compaction/compaction_test.go:
##########
@@ -249,6 +264,43 @@ func TestConfig_Validate(t *testing.T) {
        }
 }
 
+func TestPlanCompaction_InvalidPackingLookback(t *testing.T) {
+       newCfg := func(lookback uint) compaction.Config {
+               return compaction.Config{
+                       TargetFileSizeBytes: 100 * 1024 * 1024,
+                       MinFileSizeBytes:    75 * 1024 * 1024,
+                       MaxFileSizeBytes:    180 * 1024 * 1024,
+                       MinInputFiles:       2,
+                       DeleteFileThreshold: 5,
+                       PackingLookback:     lookback,
+               }
+       }
+       tasks := make([]table.FileScanTask, 0, 4)
+       for i := range 4 {
+               tasks = append(tasks, 
makeTask(newDataFile(fmt.Sprintf("file-%d.parquet", i), 10), 0, 0))
+       }
+
+       t.Run("zero lookback", func(t *testing.T) {
+               _, err := newCfg(0).PlanCompaction(tasks)
+               require.Error(t, err)
+               assert.Contains(t, err.Error(), "packing lookback must be >= 1")
+       })
+
+       t.Run("lookback above max int", func(t *testing.T) {
+               _, err := newCfg(math.MaxInt + 1).PlanCompaction(tasks)
+               require.Error(t, err)
+               assert.Contains(t, err.Error(), "exceeds max int")
+       })
+
+       t.Run("minimum lookback packs every candidate", func(t *testing.T) {

Review Comment:
   Should this subtest also make lookback 1 evict? All four files fit in the 
first bin, so the `len(bins) == 2` path in the `lookback == 1` branch of 
`PackingIterator` never runs 
([utils.go#L173-L186](https://github.com/apache/iceberg-go/blob/c3446942ce358ac33317e19776fb4c811caa295d/internal/utils.go#L173-L186)).
 A file that doesn't fit with the others would cover 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