github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/fn_op.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package colexec
    12  
    13  import (
    14  	"context"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    17  )
    18  
    19  // fnOp is an operator that executes an arbitrary function for its side-effects,
    20  // once per input batch, passing the input batch unmodified along.
    21  type fnOp struct {
    22  	OneInputNode
    23  	NonExplainable
    24  
    25  	fn func()
    26  }
    27  
    28  var _ resettableOperator = fnOp{}
    29  
    30  func (f fnOp) Init() {
    31  	f.input.Init()
    32  }
    33  
    34  func (f fnOp) Next(ctx context.Context) coldata.Batch {
    35  	batch := f.input.Next(ctx)
    36  	f.fn()
    37  	return batch
    38  }
    39  
    40  func (f fnOp) reset(ctx context.Context) {
    41  	if resettableOp, ok := f.input.(resetter); ok {
    42  		resettableOp.reset(ctx)
    43  	}
    44  }