diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index feb8f8f2f..3c35dbf01 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -1513,10 +1513,10 @@ func TestQueryGetNeededColumns(t *testing.T) { unneededColumns := strings.Join(unneeded, ",") if neededColumns != neededColumnsExpected { - t.Fatalf("unexpected neededColumns; got %q; want %q", neededColumns, neededColumnsExpected) + t.Fatalf("unexpected neededColumns for [%s]; got %q; want %q", s, neededColumns, neededColumnsExpected) } if unneededColumns != unneededColumnsExpected { - t.Fatalf("unexpected unneededColumns; got %q; want %q", unneededColumns, unneededColumnsExpected) + t.Fatalf("unexpected unneededColumns for [%s]; got %q; want %q", s, unneededColumns, unneededColumnsExpected) } } @@ -1786,10 +1786,14 @@ func TestQueryGetNeededColumns(t *testing.T) { f(`* | copy a b, c d | count() r1`, `a`, ``) f(`* | delete a, b | count() r1`, `*`, `a`) f(`* | extract "bar" from x | count() r1`, `x`, ``) + f(`* | extract if (q:w p:a) "bar" from x | count() r1`, `p,q,x`, ``) f(`* | extract_regexp "(?P.*)bar" from x | count() r1`, `x`, ``) + f(`* | extract_regexp if (q:w p:a) "(?P.*)bar" from x | count() r1`, `p,q,x`, ``) f(`* | field_names | count() r1`, `*`, `_time`) f(`* | limit 10 | field_names as abc | count() r1`, `*`, ``) f(`* | fields a, b | count() r1`, `a`, ``) f(`* | field_values a | count() r1`, `a`, ``) f(`* | limit 10 | filter a:b c:d | count() r1`, `a,c`, ``) + f(`* | format "" as c | count() r1`, `a,b`, ``) + f(`* | format if (q:w p:a) "" as c | count() r1`, `a,b,p,q`, ``) } diff --git a/lib/logstorage/pipe_extract.go b/lib/logstorage/pipe_extract.go index a2e98cee1..4591fa20f 100644 --- a/lib/logstorage/pipe_extract.go +++ b/lib/logstorage/pipe_extract.go @@ -62,6 +62,9 @@ func (pe *pipeExtract) initFilterInValues(cache map[string][]string, getFieldVal func (pe *pipeExtract) updateNeededFields(neededFields, unneededFields fieldsSet) { if neededFields.isEmpty() { neededFields.add(pe.fromField) + if pe.iff != nil { + neededFields.addFields(pe.iff.neededFields) + } return } diff --git a/lib/logstorage/pipe_extract_regexp.go b/lib/logstorage/pipe_extract_regexp.go index aec47d119..6f1a4b935 100644 --- a/lib/logstorage/pipe_extract_regexp.go +++ b/lib/logstorage/pipe_extract_regexp.go @@ -64,6 +64,9 @@ func (pe *pipeExtractRegexp) initFilterInValues(cache map[string][]string, getFi func (pe *pipeExtractRegexp) updateNeededFields(neededFields, unneededFields fieldsSet) { if neededFields.isEmpty() { neededFields.add(pe.fromField) + if pe.iff != nil { + neededFields.addFields(pe.iff.neededFields) + } return } diff --git a/lib/logstorage/pipe_format.go b/lib/logstorage/pipe_format.go index 7146f99ed..fd85ff21e 100644 --- a/lib/logstorage/pipe_format.go +++ b/lib/logstorage/pipe_format.go @@ -43,6 +43,18 @@ func (pf *pipeFormat) String() string { } func (pf *pipeFormat) updateNeededFields(neededFields, unneededFields fieldsSet) { + if neededFields.isEmpty() { + for _, step := range pf.steps { + if step.field != "" { + neededFields.add(step.field) + } + } + if pf.iff != nil { + neededFields.addFields(pf.iff.neededFields) + } + return + } + if neededFields.contains("*") { if !unneededFields.contains(pf.resultField) { if !pf.keepOriginalFields && !pf.skipEmptyResults {