"first_null_row" configuration option
This commit is contained in:
@@ -30,6 +30,7 @@ type nativeDataset struct {
|
||||
Columns []string
|
||||
ValueEncodings map[string]project.TopDataValueEncodingConfig
|
||||
ValueDefaults map[string]any
|
||||
RowGeneration string
|
||||
CompareReference bool
|
||||
}
|
||||
|
||||
@@ -240,6 +241,7 @@ func buildNativeUnchecked(p *project.Project, opts NativeBuildOptions, progress
|
||||
}
|
||||
datasets = applyTopDataValueEncodings(datasets, p.Config.TopData.ValueEncodings)
|
||||
datasets = applyTopDataValueDefaults(datasets, p.Config.TopData.ValueDefaults)
|
||||
datasets = applyTopDataRowGeneration(datasets, p.Config.TopData.RowGeneration)
|
||||
registryDatasets, err := collectGeneratedRegistryDatasets(dataDir)
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
@@ -448,6 +450,30 @@ func applyTopDataValueDefaults(datasets []nativeDataset, defaults []project.TopD
|
||||
return out
|
||||
}
|
||||
|
||||
func applyTopDataRowGeneration(datasets []nativeDataset, rules []project.TopDataRowGenerationConfig) []nativeDataset {
|
||||
if len(rules) == 0 {
|
||||
return datasets
|
||||
}
|
||||
out := append([]nativeDataset(nil), datasets...)
|
||||
for index := range out {
|
||||
for _, rule := range rules {
|
||||
datasetName := strings.TrimSpace(rule.Dataset)
|
||||
if datasetName == "" {
|
||||
datasetName = strings.TrimSpace(rule.Namespace)
|
||||
}
|
||||
if filepath.ToSlash(datasetName) != out[index].Name {
|
||||
continue
|
||||
}
|
||||
mode := strings.TrimSpace(rule.Mode)
|
||||
if mode == "" {
|
||||
mode = "after_base"
|
||||
}
|
||||
out[index].RowGeneration = mode
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func nativeCompileGroup(datasetName string) string {
|
||||
head, _, ok := strings.Cut(datasetName, "/")
|
||||
if !ok {
|
||||
@@ -785,6 +811,7 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
|
||||
rowByID := map[int]map[string]any{}
|
||||
rowByKey := map[string]map[string]any{}
|
||||
usedIDs := map[int]struct{}{}
|
||||
firstNullRowMode := dataset.RowGeneration == "first_null_row"
|
||||
lockModified := false
|
||||
lockAdded := 0
|
||||
lockPruned := 0
|
||||
@@ -798,8 +825,28 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if firstNullRowMode {
|
||||
for key, rowID := range lockData {
|
||||
if rowID <= baseBoundaryID {
|
||||
continue
|
||||
}
|
||||
if _, ok := baseRowKeys[key]; ok {
|
||||
continue
|
||||
}
|
||||
if explicitID, ok := explicitModuleIDs[key]; ok && explicitID == rowID {
|
||||
continue
|
||||
}
|
||||
delete(lockData, key)
|
||||
lockModified = true
|
||||
lockPruned++
|
||||
}
|
||||
}
|
||||
|
||||
for key, rowID := range lockData {
|
||||
if rowID <= baseBoundaryID {
|
||||
if firstNullRowMode {
|
||||
continue
|
||||
}
|
||||
if _, ok := baseRowKeys[key]; ok {
|
||||
continue
|
||||
}
|
||||
@@ -823,8 +870,11 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
|
||||
if err != nil {
|
||||
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: %w", dataset.Name, err)
|
||||
}
|
||||
rows = append(rows, row)
|
||||
rowID := row["id"].(int)
|
||||
if firstNullRowMode && isNativeAllocationNullRow(row, columns) {
|
||||
continue
|
||||
}
|
||||
rows = append(rows, row)
|
||||
if key, ok := row["key"].(string); ok && key != "" {
|
||||
if baseRowKeyCounts[key] > 1 {
|
||||
if lockedID, ok := lockData[key]; !ok || lockedID != rowID {
|
||||
@@ -843,8 +893,10 @@ func collectBaseDataset(dataset nativeDataset) (nativeCollectedDataset, error) {
|
||||
}
|
||||
usedIDs[rowID] = struct{}{}
|
||||
}
|
||||
for rowID := 0; rowID <= baseBoundaryID; rowID++ {
|
||||
usedIDs[rowID] = struct{}{}
|
||||
if !firstNullRowMode {
|
||||
for rowID := 0; rowID <= baseBoundaryID; rowID++ {
|
||||
usedIDs[rowID] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, rowID := range explicitModuleIDs {
|
||||
usedIDs[rowID] = struct{}{}
|
||||
@@ -4457,6 +4509,18 @@ func ensureRowsExposeColumns(rows []map[string]any, columns []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func isNativeAllocationNullRow(row map[string]any, columns []string) bool {
|
||||
if key, ok := row["key"].(string); ok && strings.TrimSpace(key) != "" && strings.TrimSpace(key) != nullValue {
|
||||
return false
|
||||
}
|
||||
for _, column := range columns {
|
||||
if !isNullLikeValue(row[column]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func canonicalizeBaseRow(dataset nativeDataset, columns []string, raw map[string]any, index int) (map[string]any, error) {
|
||||
rowID := index
|
||||
if value, ok := raw["id"]; ok {
|
||||
|
||||
Reference in New Issue
Block a user