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 fieldpull/24135/head
parent
b819edf095
commit
e1d0102a6f
|
@ -197,6 +197,24 @@ func decodeDeleteRequest(ctx context.Context, r *http.Request, orgSvc influxdb.O
|
||||||
}
|
}
|
||||||
return false, nil
|
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 {
|
if err != nil {
|
||||||
return nil, nil, &errors.Error{
|
return nil, nil, &errors.Error{
|
||||||
Code: errors.EInvalid,
|
Code: errors.EInvalid,
|
||||||
|
|
|
@ -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",
|
name: "complex delete",
|
||||||
args: args{
|
args: args{
|
||||||
|
|
Loading…
Reference in New Issue