This commit is contained in:
Aliaksandr Valialkin 2024-05-30 11:44:29 +02:00
parent 1790caa082
commit 277f13f3fa
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 24 additions and 2 deletions

View file

@ -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 "<f1>bar" from x | count() r1`, `x`, ``)
f(`* | extract if (q:w p:a) "<f1>bar" from x | count() r1`, `p,q,x`, ``)
f(`* | extract_regexp "(?P<f1>.*)bar" from x | count() r1`, `x`, ``)
f(`* | extract_regexp if (q:w p:a) "(?P<f1>.*)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 "<a><b>" as c | count() r1`, `a,b`, ``)
f(`* | format if (q:w p:a) "<a><b>" as c | count() r1`, `a,b,p,q`, ``)
}

View file

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

View file

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

View file

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