github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/invariants_checker.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  	"github.com/cockroachdb/cockroach/pkg/sql/colexecbase"
    18  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    19  )
    20  
    21  // invariantsChecker is a helper Operator that will check that invariants that
    22  // are present in the vectorized engine are maintained on all batches. It
    23  // should be planned between other Operators in tests.
    24  type invariantsChecker struct {
    25  	OneInputNode
    26  }
    27  
    28  var _ colexecbase.Operator = invariantsChecker{}
    29  
    30  // NewInvariantsChecker creates a new invariantsChecker.
    31  func NewInvariantsChecker(input colexecbase.Operator) colexecbase.Operator {
    32  	return &invariantsChecker{
    33  		OneInputNode: OneInputNode{input: input},
    34  	}
    35  }
    36  
    37  func (i invariantsChecker) Init() {
    38  	i.input.Init()
    39  }
    40  
    41  func (i invariantsChecker) Next(ctx context.Context) coldata.Batch {
    42  	b := i.input.Next(ctx)
    43  	n := b.Length()
    44  	if n == 0 {
    45  		return b
    46  	}
    47  	for colIdx := 0; colIdx < b.Width(); colIdx++ {
    48  		v := b.ColVec(colIdx)
    49  		if v.CanonicalTypeFamily() == types.BytesFamily {
    50  			v.Bytes().AssertOffsetsAreNonDecreasing(n)
    51  		}
    52  	}
    53  	return b
    54  }