Skip to content

Commit

Permalink
fix: Update the condition when reseting cursor (#23522)
Browse files Browse the repository at this point in the history
Filters that contain `or` may change between cursor resets so we must remember to update the condition in the read cursor.

```flux
|> filter(fn: (r) => ((r["_field"] == "field1" and r["_value"]==true) or (r["_field"] == "field2" and r["_value"] == false)))
```

Closes influxdata/flux#4804
  • Loading branch information
Marwes authored and bnpfeife committed Nov 8, 2022
1 parent aa72980 commit a8d9335
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions flux/stdlib/influxdata/influxdb/filter_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,37 @@ testcase filter {
|> drop(columns: ["_start", "_stop"])
testing.diff(want, got)
}


input_issue_4804 = "#datatype,string,long,dateTime:RFC3339,string,string,string,boolean
#group,false,false,false,true,true,true,false
#default,_result,,,,,,
,result,table,_time,_measurement,host,_field,_value
,,0,2018-05-22T19:53:26Z,system,host.local,load1,true
,,0,2018-05-22T19:53:36Z,system,host.local,load1,false
,,1,2018-05-22T19:53:26Z,system,host.local,load3,false
,,2,2018-05-22T19:53:26Z,system,host.local,load4,true
"

testcase flux_issue_4804 {
expect.planner(rules: [
"influxdata/influxdb.FromStorageRule": 1,
"PushDownRangeRule": 1,
"PushDownFilterRule": 1,
])

want = csv.from(csv: "#datatype,string,long,dateTime:RFC3339,string,string,string,boolean
#group,false,false,false,true,true,true,false
#default,_result,,,,,,
,result,table,_time,_measurement,host,_field,_value
,,0,2018-05-22T19:53:26Z,system,host.local,load1,true
,,1,2018-05-22T19:53:26Z,system,host.local,load3,false
")

got = csv.from(csv: input_issue_4804)
|> testing.load()
|> range(start: -100y)
|> filter(fn: (r) => ((r["_field"] == "load1" and r["_value"] == true) or (r["_field"] == "load3" and r["_value"] == false)))
|> drop(columns: ["_start", "_stop"])
testing.diff(want, got)
}
10 changes: 10 additions & 0 deletions storage/reads/array_cursor.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ func (c *floatMultiShardArrayCursor) reset(cur cursors.FloatArrayCursor, itrs cu
if cond != nil {
if c.filter == nil {
c.filter = newFloatFilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down Expand Up @@ -1299,6 +1301,8 @@ func (c *integerMultiShardArrayCursor) reset(cur cursors.IntegerArrayCursor, itr
if cond != nil {
if c.filter == nil {
c.filter = newIntegerFilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down Expand Up @@ -2302,6 +2306,8 @@ func (c *unsignedMultiShardArrayCursor) reset(cur cursors.UnsignedArrayCursor, i
if cond != nil {
if c.filter == nil {
c.filter = newUnsignedFilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down Expand Up @@ -3305,6 +3311,8 @@ func (c *stringMultiShardArrayCursor) reset(cur cursors.StringArrayCursor, itrs
if cond != nil {
if c.filter == nil {
c.filter = newStringFilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down Expand Up @@ -3730,6 +3738,8 @@ func (c *booleanMultiShardArrayCursor) reset(cur cursors.BooleanArrayCursor, itr
if cond != nil {
if c.filter == nil {
c.filter = newBooleanFilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down
2 changes: 2 additions & 0 deletions storage/reads/array_cursor.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func (c *{{.name}}MultiShardArrayCursor) reset(cur cursors.{{.Name}}ArrayCursor,
if cond != nil {
if c.filter == nil {
c.filter = new{{.Name}}FilterArrayCursor(cond)
} else {
c.filter.cond = cond
}
c.filter.reset(cur)
cur = c.filter
Expand Down

0 comments on commit a8d9335

Please sign in to comment.