diff --git a/http/delete_handler.go b/http/delete_handler.go index acb7018c5e..d575ebca8b 100644 --- a/http/delete_handler.go +++ b/http/delete_handler.go @@ -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, diff --git a/http/delete_test.go b/http/delete_test.go index eeabb259db..99d72b472a 100644 --- a/http/delete_test.go +++ b/http/delete_test.go @@ -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{