This commit is contained in:
Aliaksandr Valialkin 2024-05-17 11:04:50 +02:00
parent 900d74a560
commit 160034bda3
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 15 additions and 7 deletions

View file

@ -95,7 +95,7 @@ func (br *blockResult) clone() *blockResult {
// initFromNeededColumns initializes br from brSrc, by copying only the given neededColumns for rows identified by set bits at bm. // initFromNeededColumns initializes br from brSrc, by copying only the given neededColumns for rows identified by set bits at bm.
// //
// The br valid until brSrc is reset or bm is updated. // The br valid until brSrc or bm is updated.
func (br *blockResult) initFromNeededColumns(brSrc *blockResult, bm *bitmap, neededColumns []string) { func (br *blockResult) initFromNeededColumns(brSrc *blockResult, bm *bitmap, neededColumns []string) {
br.reset() br.reset()
@ -106,6 +106,11 @@ func (br *blockResult) initFromNeededColumns(brSrc *blockResult, bm *bitmap, nee
}) })
br.timestamps = dstTimestamps br.timestamps = dstTimestamps
if len(br.timestamps) == 0 {
// There is no need in initializing columns for zero rows.
return
}
for _, neededColumn := range neededColumns { for _, neededColumn := range neededColumns {
cSrc := brSrc.getColumnByName(neededColumn) cSrc := brSrc.getColumnByName(neededColumn)
@ -1277,6 +1282,9 @@ func (br *blockResult) areSameColumns(columnNames []string) bool {
} }
func (br *blockResult) getColumnByName(columnName string) *blockResultColumn { func (br *blockResult) getColumnByName(columnName string) *blockResultColumn {
if columnName == "" {
columnName = "_msg"
}
for _, c := range br.getColumns() { for _, c := range br.getColumns() {
if c.name == columnName { if c.name == columnName {
return c return c

View file

@ -32,8 +32,8 @@ func (fp *filterPhrase) String() string {
return quoteFieldNameIfNeeded(fp.fieldName) + quoteTokenIfNeeded(fp.phrase) return quoteFieldNameIfNeeded(fp.fieldName) + quoteTokenIfNeeded(fp.phrase)
} }
func (fp *filterPhrase) updateNeededFields(neededColumns fieldsSet) { func (fp *filterPhrase) updateNeededFields(neededFields fieldsSet) {
neededColumns.add(fp.fieldName) neededFields.add(fp.fieldName)
} }
func (fp *filterPhrase) getTokens() []string { func (fp *filterPhrase) getTokens() []string {

View file

@ -523,16 +523,16 @@ func parsePipeStats(lex *lexer) (*pipeStats, error) {
} }
f.f = sf f.f = sf
neededFields := newFieldsSet()
f.f.updateNeededFields(neededFields)
f.neededFieldsForFunc = neededFields.getAll()
if lex.isKeyword("if") { if lex.isKeyword("if") {
iff, err := parseIfFilter(lex) iff, err := parseIfFilter(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse 'if' filter for %s: %w", sf, err) return nil, fmt.Errorf("cannot parse 'if' filter for %s: %w", sf, err)
} }
f.iff = iff f.iff = iff
neededFields := newFieldsSet()
iff.updateNeededFields(neededFields)
f.neededFieldsForFunc = neededFields.getAll()
} }
resultName, err := parseResultName(lex) resultName, err := parseResultName(lex)