Skip to content

Commit c306e41

Browse files
committed
fix(changes): column renames are properly handled now
1 parent 9d5d362 commit c306e41

File tree

2 files changed

+125
-2
lines changed

2 files changed

+125
-2
lines changed

changes/changes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ func (svc *service) matchColumns(leftColCount, rightColCount int, leftColItems,
218218
maxColCount = rightColCount
219219
}
220220

221-
columns := make([]*ChangeReportDeltaComponent, maxColCount)
222-
223221
type cIndex struct {
224222
LPos int
225223
RPos int
@@ -249,6 +247,8 @@ func (svc *service) matchColumns(leftColCount, rightColCount int, leftColItems,
249247
}
250248
}
251249

250+
columns := make([]*ChangeReportDeltaComponent, len(colIndex))
251+
252252
i := 0
253253
for k, v := range colIndex {
254254
columns[i] = &ChangeReportDeltaComponent{

changes/changes_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,129 @@ raleigh,25000,5000.65,false,5`
541541
if diff := cmp.Diff(report, expect); diff != "" {
542542
t.Errorf("column items result mismatch. (-want +got):%s\n", diff)
543543
}
544+
545+
// alter body file - rename column
546+
const alteredBodyDataColumns3 = `city,popz,avg_age,in_usa
547+
toronto,4000000,55.0,false
548+
new york,850000,44.0,false
549+
chicago,30000,440.4,false
550+
chatham,3500,650.25,false
551+
raleigh,25000,5000.65,false`
552+
553+
ds.Name = "cities"
554+
555+
run.updateDataset(t, ds, alteredBodyDataColumns3)
556+
557+
_, err = svc.parseColumns(&rightColItems, ds)
558+
if err != nil {
559+
t.Fatal(err)
560+
}
561+
rightStats, err = svc.parseStats(ds)
562+
if err != nil {
563+
t.Fatal(err)
564+
}
565+
566+
report, err = svc.matchColumns(4, 4, leftColItems, rightColItems, leftStats, rightStats)
567+
if err != nil {
568+
t.Fatal(err)
569+
}
570+
571+
// output order is not strict so we need to enfore it here
572+
sort.SliceStable(report, func(i, j int) bool {
573+
return report[i].Title < report[j].Title
574+
})
575+
576+
expect = getBaseCols()
577+
expect[3] = &ChangeReportDeltaComponent{
578+
ChangeReportComponent: ChangeReportComponent{
579+
Left: EmptyObject{
580+
"count": float64(5),
581+
"max": float64(40000000),
582+
"min": float64(35000),
583+
"mean": float64(9817000),
584+
"median": float64(300000),
585+
"histogram": map[string]interface{}{
586+
"bins": []interface{}{
587+
float64(35000),
588+
float64(250000),
589+
float64(300000),
590+
float64(8500000),
591+
float64(40000000),
592+
float64(40000001),
593+
},
594+
"frequencies": []interface{}{
595+
float64(1),
596+
float64(1),
597+
float64(1),
598+
float64(1),
599+
float64(1),
600+
},
601+
},
602+
"type": "numeric",
603+
},
604+
Right: EmptyObject{},
605+
About: map[string]interface{}{
606+
"status": fsi.STRemoved,
607+
},
608+
},
609+
Title: "pop",
610+
Delta: map[string]interface{}{
611+
"count": float64(-5),
612+
"max": float64(-40000000),
613+
"mean": float64(-9817000),
614+
"median": float64(-300000),
615+
"min": float64(-35000),
616+
},
617+
}
618+
expect = append(expect, &ChangeReportDeltaComponent{
619+
ChangeReportComponent: ChangeReportComponent{
620+
Left: EmptyObject{},
621+
Right: EmptyObject{
622+
"count": float64(5),
623+
"max": float64(4000000),
624+
"min": float64(3500),
625+
"mean": float64(981700),
626+
"median": float64(30000),
627+
"histogram": map[string]interface{}{
628+
"bins": []interface{}{
629+
float64(3500),
630+
float64(25000),
631+
float64(30000),
632+
float64(850000),
633+
float64(4000000),
634+
float64(4000001),
635+
},
636+
"frequencies": []interface{}{
637+
float64(1),
638+
float64(1),
639+
float64(1),
640+
float64(1),
641+
float64(1),
642+
},
643+
},
644+
"type": "numeric",
645+
},
646+
About: map[string]interface{}{
647+
"status": fsi.STAdd,
648+
},
649+
},
650+
Title: "popz",
651+
Delta: map[string]interface{}{
652+
"count": float64(5),
653+
"max": float64(4000000),
654+
"mean": float64(981700),
655+
"median": float64(30000),
656+
"min": float64(3500),
657+
},
658+
})
659+
660+
sort.SliceStable(expect, func(i, j int) bool {
661+
return expect[i].Title < expect[j].Title
662+
})
663+
664+
if diff := cmp.Diff(report, expect); diff != "" {
665+
t.Errorf("column items result mismatch. (-want +got):%s\n", diff)
666+
}
544667
}
545668

546669
func TestReport(t *testing.T) {

0 commit comments

Comments
 (0)