Skip to content

Commit

Permalink
fix: add error message when attempting to delete by field (influxdata…
Browse files Browse the repository at this point in the history
…#24131)

* fix: add error message when attempting to delete by field

* test: add test for delete by field
  • Loading branch information
jeffreyssmith2nd authored Mar 10, 2023
1 parent b819edf commit e1d0102
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
18 changes: 18 additions & 0 deletions http/delete_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ func decodeDeleteRequest(ctx context.Context, r *http.Request, orgSvc influxdb.O
}
return false, nil
})

var walkError error
influxql.WalkFunc(expr, func(e influxql.Node) {
if v, ok := e.(*influxql.BinaryExpr); ok {
if vv, ok := v.LHS.(*influxql.VarRef); ok && v.Op == influxql.EQ {
if vv.Val == "_field" {
walkError = &errors.Error{
Code: errors.ENotImplemented,
Msg: "",
Err: fmt.Errorf("delete by field is not supported"),
}
}
}
}
})
if walkError != nil {
return nil, nil, walkError
}
if err != nil {
return nil, nil, &errors.Error{
Code: errors.EInvalid,
Expand Down
54 changes: 54 additions & 0 deletions http/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,60 @@ func TestDelete(t *testing.T) {
}`,
},
},
{
name: "unsupported delete by field",
args: args{
queryParams: map[string][]string{
"org": {"org1"},
"bucket": {"buck1"},
},
body: []byte(`{
"start":"2009-01-01T23:00:00Z",
"stop":"2019-11-10T01:00:00Z",
"predicate": "_field=\"cpu\""
}`),
authorizer: &influxdb.Authorization{
UserID: user1ID,
Status: influxdb.Active,
Permissions: []influxdb.Permission{
{
Action: influxdb.WriteAction,
Resource: influxdb.Resource{
Type: influxdb.BucketsResourceType,
ID: influxtesting.IDPtr(platform.ID(2)),
OrgID: influxtesting.IDPtr(platform.ID(1)),
},
},
},
},
},
fields: fields{
DeleteService: mock.NewDeleteService(),
BucketService: &mock.BucketService{
FindBucketFn: func(ctx context.Context, f influxdb.BucketFilter) (*influxdb.Bucket, error) {
return &influxdb.Bucket{
ID: platform.ID(2),
Name: "bucket1",
}, nil
},
},
OrganizationService: &mock.OrganizationService{
FindOrganizationF: func(ctx context.Context, f influxdb.OrganizationFilter) (*influxdb.Organization, error) {
return &influxdb.Organization{
ID: platform.ID(1),
Name: "org1",
}, nil
},
},
},
wants: wants{
statusCode: http.StatusNotImplemented,
body: `{
"code": "not implemented",
"message": "delete by field is not supported"
}`,
},
},
{
name: "complex delete",
args: args{
Expand Down

0 comments on commit e1d0102

Please sign in to comment.