fix: add error message when attempting to delete by field (#24131)

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

* test: add test for delete by field
pull/24135/head
Jeffrey Smith II 2023-03-10 09:13:24 -05:00 committed by GitHub
parent b819edf095
commit e1d0102a6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 0 deletions

View File

@ -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,

View File

@ -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{