Fixed plain datasets generating lock ids when not necessary

This commit is contained in:
2026-05-27 23:51:49 +02:00
parent a2d9820f8d
commit c7dc81b80f
2 changed files with 97 additions and 4 deletions
+35 -4
View File
@@ -865,6 +865,10 @@ func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
if err != nil {
return err
}
lockPath := filepath.Join(rootPath, "lock.json")
if !plainDatasetNeedsLock(lockPath, tableData) {
lockPath = ""
}
outputName, _ := tableData["output"].(string)
if strings.TrimSpace(outputName) == "" {
outputName = nativeDatasetDefaultOutputName(filePath, nativeDatasetPlain)
@@ -874,7 +878,7 @@ func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
Name: filepath.ToSlash(relName),
RootPath: rootPath,
BasePath: filePath,
LockPath: filepath.Join(rootPath, "lock.json"),
LockPath: lockPath,
OutputName: outputName,
Spec: specForDataset(filepath.ToSlash(relName)),
CompareReference: optionalBool(tableData["compare_reference"], true),
@@ -979,6 +983,29 @@ func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
return datasets, nil
}
func plainDatasetNeedsLock(lockPath string, tableData map[string]any) bool {
if _, err := os.Stat(lockPath); err == nil {
return true
}
rawRows, ok := tableData["rows"].([]any)
if !ok {
return false
}
for _, raw := range rawRows {
row, ok := raw.(map[string]any)
if !ok {
continue
}
key, hasKey := row["key"].(string)
if hasKey && strings.TrimSpace(key) != "" {
if _, hasID := row["id"]; !hasID {
return true
}
}
}
return false
}
func discoverNativeOutputCatalog(dataDir string) (map[string]string, error) {
datasets, err := discoverNativeDatasets(dataDir)
if err != nil {
@@ -3396,9 +3423,13 @@ func collectPlainDataset(dataset nativeDataset) (nativeCollectedDataset, error)
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: rows must be an array", dataset.Name)
}
lockData, err := loadLockfile(dataset.LockPath)
if err != nil {
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: %w", dataset.Name, err)
lockData := map[string]int{}
if dataset.LockPath != "" {
var err error
lockData, err = loadLockfile(dataset.LockPath)
if err != nil {
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: %w", dataset.Name, err)
}
}
usedIDs := map[int]struct{}{}
for _, rowID := range lockData {