github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/values_differ_tmpl.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  // {{/*
    12  // +build execgen_template
    13  //
    14  // This file is the execgen template for values_differ.eg.go. It's formatted
    15  // in a special way, so it's both valid Go and a valid text/template input.
    16  // This permits editing this file with editor support.
    17  //
    18  // */}}
    19  
    20  package colexec
    21  
    22  import (
    23  	"fmt"
    24  
    25  	"github.com/cockroachdb/cockroach/pkg/col/coldata"
    26  	"github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen"
    27  	"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
    28  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    29  )
    30  
    31  // Remove unused warning.
    32  var _ = execgen.UNSAFEGET
    33  
    34  // {{/*
    35  
    36  // Declarations to make the template compile properly.
    37  
    38  // _GOTYPE is the template variable.
    39  type _GOTYPE interface{}
    40  
    41  // _CANONICAL_TYPE_FAMILY is the template variable.
    42  const _CANONICAL_TYPE_FAMILY = types.UnknownFamily
    43  
    44  // _TYPE_WIDTH is the template variable.
    45  const _TYPE_WIDTH = 0
    46  
    47  // _ASSIGN_NE is the template equality function for assigning the first input
    48  // to the result of the second input != the third input.
    49  func _ASSIGN_NE(_, _, _, _, _, _ string) bool {
    50  	colexecerror.InternalError("")
    51  }
    52  
    53  // */}}
    54  
    55  // valuesDiffer takes in two ColVecs as well as values indices to check whether
    56  // the values differ. This function pays attention to NULLs, and two NULL
    57  // values do *not* differ.
    58  func valuesDiffer(aColVec coldata.Vec, aValueIdx int, bColVec coldata.Vec, bValueIdx int) bool {
    59  	switch aColVec.CanonicalTypeFamily() {
    60  	// {{range .}}
    61  	case _CANONICAL_TYPE_FAMILY:
    62  		switch aColVec.Type().Width() {
    63  		// {{range .WidthOverloads}}
    64  		case _TYPE_WIDTH:
    65  			aCol := aColVec.TemplateType()
    66  			bCol := bColVec.TemplateType()
    67  			aNulls := aColVec.Nulls()
    68  			bNulls := bColVec.Nulls()
    69  			aNull := aNulls.MaybeHasNulls() && aNulls.NullAt(aValueIdx)
    70  			bNull := bNulls.MaybeHasNulls() && bNulls.NullAt(bValueIdx)
    71  			if aNull && bNull {
    72  				return false
    73  			} else if aNull || bNull {
    74  				return true
    75  			}
    76  			arg1 := execgen.UNSAFEGET(aCol, aValueIdx)
    77  			arg2 := execgen.UNSAFEGET(bCol, bValueIdx)
    78  			var unique bool
    79  			_ASSIGN_NE(unique, arg1, arg2, _, aCol, bCol)
    80  			return unique
    81  			// {{end}}
    82  		}
    83  		// {{end}}
    84  	}
    85  	colexecerror.InternalError(fmt.Sprintf("unsupported valuesDiffer type %s", aColVec.Type()))
    86  	// This code is unreachable, but the compiler cannot infer that.
    87  	return false
    88  }