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

     1  // Copyright 2020 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 colexecbase
    12  
    13  import (
    14  	"context"
    15  	"fmt"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    18  	"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
    20  )
    21  
    22  // Operator is a column vector operator that produces a Batch as output.
    23  type Operator interface {
    24  	// Init initializes this operator. Will be called once at operator setup
    25  	// time. If an operator has an input operator, it's responsible for calling
    26  	// Init on that input operator as well.
    27  	// TODO(yuzefovich): we might need to clarify whether it is ok to call
    28  	// Init() multiple times before the first call to Next(). It is possible to
    29  	// hit the memory limit during Init(), and a disk-backed operator needs to
    30  	// make sure that the input has been initialized. We could also in case that
    31  	// Init() doesn't succeed for bufferingInMemoryOperator - which should only
    32  	// happen when 'workmem' setting is too low - just bail, even if we have
    33  	// disk spilling for that operator.
    34  	Init()
    35  
    36  	// Next returns the next Batch from this operator. Once the operator is
    37  	// finished, it will return a Batch with length 0. Subsequent calls to
    38  	// Next at that point will always return a Batch with length 0.
    39  	//
    40  	// Calling Next may invalidate the contents of the last Batch returned by
    41  	// Next.
    42  	// Canceling the provided context results in forceful termination of
    43  	// execution.
    44  	Next(context.Context) coldata.Batch
    45  
    46  	execinfra.OpNode
    47  }
    48  
    49  // ZeroInputNode is an execinfra.OpNode with no inputs.
    50  type ZeroInputNode struct{}
    51  
    52  // ChildCount implements the execinfra.OpNode interface.
    53  func (ZeroInputNode) ChildCount(verbose bool) int {
    54  	return 0
    55  }
    56  
    57  // Child implements the execinfra.OpNode interface.
    58  func (ZeroInputNode) Child(nth int, verbose bool) execinfra.OpNode {
    59  	colexecerror.InternalError(fmt.Sprintf("invalid index %d", nth))
    60  	// This code is unreachable, but the compiler cannot infer that.
    61  	return nil
    62  }