Skip to content

Commit

Permalink
fix: create better error message for pivot column conflict (#4579)
Browse files Browse the repository at this point in the history
Also, change the type of the error to Invalid so it is seen by users.
  • Loading branch information
Christopher M. Wolff authored Apr 4, 2022
1 parent f7ba69c commit e2648ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion stdlib/universe/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ func (t *pivotTransformation) Process(id execute.DatasetID, tbl flux.Table) erro
}
nextCol, err := builder.AddCol(newCol)
if err != nil {
return err
// column already exists
return errors.Newf(
codes.Invalid,
"value %q appears in a column key column, but a column named %q already exists; consider renaming %q to something else before pivoting",
colKey, colKey, colKey,
)
}
t.colKeyMaps[groupKeyString][colKey] = nextCol
}
Expand Down
30 changes: 30 additions & 0 deletions stdlib/universe/pivot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,36 @@ func TestPivot_Process(t *testing.T) {
},
wantErr: errors.New(codes.Invalid, "specified value column does not exist in table: _value"),
},
{
name: "column name conflict",
spec: &universe.PivotProcedureSpec{
RowKey: []string{"_time"},
ColumnKey: []string{"_field"},
ValueColumn: "_value",
},
data: []flux.Table{
&executetest.Table{
KeyCols: []string{"_measurement", "_field", "f1"},
ColMeta: []flux.ColMeta{
{Label: "_time", Type: flux.TTime},
{Label: "_value", Type: flux.TFloat},
{Label: "_measurement", Type: flux.TString},
{Label: "_field", Type: flux.TString},
{Label: "f1", Type: flux.TString},
},
Data: [][]interface{}{
{execute.Time(1), 1.0, "m1", "f1", "foo"},
{execute.Time(1), 2.0, "m1", "f2", "foo"},
{execute.Time(2), 3.0, "m1", "f1", "foo"},
{execute.Time(2), 4.0, "m1", "f2", "foo"},
},
},
},
wantErr: errors.New(
codes.Invalid,
`value "f1" appears in a column key column, but a column named "f1" already exists; consider renaming "f1" to something else before pivoting`,
),
},
}
for _, tc := range testCases {
tc := tc
Expand Down

0 comments on commit e2648ea

Please sign in to comment.