Minimum row

This commit is contained in:
2026-05-25 14:50:01 +02:00
parent a646c905e4
commit 37db91314b
7 changed files with 171 additions and 38 deletions
+26 -19
View File
@@ -18,20 +18,21 @@ import (
const nullValue = "****"
type nativeDataset struct {
Kind nativeDatasetKind
Name string
RootPath string
BasePath string
LockPath string
ModulesDir string
GeneratedDir string
OutputName string
Spec datasetTextSpec
Columns []string
ValueEncodings map[string]project.TopDataValueEncodingConfig
ValueDefaults map[string]any
RowGeneration string
CompareReference bool
Kind nativeDatasetKind
Name string
RootPath string
BasePath string
LockPath string
ModulesDir string
GeneratedDir string
OutputName string
Spec datasetTextSpec
Columns []string
ValueEncodings map[string]project.TopDataValueEncodingConfig
ValueDefaults map[string]any
RowGeneration string
RowGenerationMinRow int
CompareReference bool
}
type nativeDatasetKind string
@@ -470,6 +471,7 @@ func applyTopDataRowGeneration(datasets []nativeDataset, rules []project.TopData
mode = "after_base"
}
out[index].RowGeneration = mode
out[index].RowGenerationMinRow = rule.MinimumRow
}
}
return out
@@ -813,6 +815,7 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
rowByKey := map[string]map[string]any{}
usedIDs := map[int]struct{}{}
firstNullRowMode := dataset.RowGeneration == "first_null_row"
rowGenerationMinRow := dataset.RowGenerationMinRow
lockModified := false
lockAdded := 0
lockPruned := 0
@@ -828,7 +831,7 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
if firstNullRowMode {
for key, rowID := range lockData {
if rowID <= baseBoundaryID {
if rowID >= rowGenerationMinRow && (rowID <= baseBoundaryID || rowGenerationMinRow > baseBoundaryID) {
continue
}
if _, ok := baseRowKeys[key]; ok {
@@ -872,7 +875,7 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: %w", dataset.Name, err)
}
rowID := row["id"].(int)
if firstNullRowMode && isNativeAllocationNullRow(row, columns) {
if firstNullRowMode && rowID >= rowGenerationMinRow && isNativeAllocationNullRow(row, columns) {
continue
}
rows = append(rows, row)
@@ -903,11 +906,11 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
usedIDs[rowID] = struct{}{}
}
nextID := nextAvailableID(usedIDs)
nextID := nextAvailableIDAtLeast(usedIDs, rowGenerationMinRow)
allocateNextID := func() int {
rowID := nextID
usedIDs[rowID] = struct{}{}
nextID = nextAvailableID(usedIDs)
nextID = nextAvailableIDAtLeast(usedIDs, rowGenerationMinRow)
return rowID
}
lockedIDForKey := func(key string) (int, bool) {
@@ -5669,7 +5672,11 @@ func asInt(value any) (int, error) {
}
func nextAvailableID(used map[int]struct{}) int {
next := 0
return nextAvailableIDAtLeast(used, 0)
}
func nextAvailableIDAtLeast(used map[int]struct{}, minimum int) int {
next := minimum
for {
if _, ok := used[next]; !ok {
return next