github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/window_functions_util.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  	"fmt"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
    17  	"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
    18  )
    19  
    20  const columnOmitted = -1
    21  
    22  // SupportedWindowFns contains all window functions supported by the
    23  // vectorized engine.
    24  var SupportedWindowFns = map[execinfrapb.WindowerSpec_WindowFunc]struct{}{
    25  	execinfrapb.WindowerSpec_ROW_NUMBER:   {},
    26  	execinfrapb.WindowerSpec_RANK:         {},
    27  	execinfrapb.WindowerSpec_DENSE_RANK:   {},
    28  	execinfrapb.WindowerSpec_PERCENT_RANK: {},
    29  	execinfrapb.WindowerSpec_CUME_DIST:    {},
    30  }
    31  
    32  // windowFnNeedsPeersInfo returns whether a window function pays attention to
    33  // the concept of "peers" during its computation ("peers" are tuples within the
    34  // same partition - from PARTITION BY clause - that are not distinct on the
    35  // columns in ORDER BY clause). For most window functions, the result of
    36  // computation should be the same for "peers", so most window functions do need
    37  // this information.
    38  func windowFnNeedsPeersInfo(windowFn execinfrapb.WindowerSpec_WindowFunc) bool {
    39  	switch windowFn {
    40  	case execinfrapb.WindowerSpec_ROW_NUMBER:
    41  		// row_number doesn't pay attention to the concept of "peers."
    42  		return false
    43  	case
    44  		execinfrapb.WindowerSpec_RANK,
    45  		execinfrapb.WindowerSpec_DENSE_RANK,
    46  		execinfrapb.WindowerSpec_PERCENT_RANK,
    47  		execinfrapb.WindowerSpec_CUME_DIST:
    48  		return true
    49  	default:
    50  		colexecerror.InternalError(fmt.Sprintf("window function %s is not supported", windowFn.String()))
    51  		// This code is unreachable, but the compiler cannot infer that.
    52  		return false
    53  	}
    54  }