github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/colexec/execgen/cmd/execgen/window_peer_grouper_gen.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 main
    12  
    13  import (
    14  	"io"
    15  	"strings"
    16  	"text/template"
    17  )
    18  
    19  type windowPeerGrouperTmplInfo struct {
    20  	AllPeers     bool
    21  	HasPartition bool
    22  	String       string
    23  }
    24  
    25  const windowPeerGrouperOpsTmpl = "pkg/sql/colexec/colexecwindow/window_peer_grouper_tmpl.go"
    26  
    27  func genWindowPeerGrouperOps(inputFileContents string, wr io.Writer) error {
    28  	s := strings.ReplaceAll(inputFileContents, "_PEER_GROUPER_STRING", "{{.String}}")
    29  
    30  	// Now, generate the op, from the template.
    31  	tmpl, err := template.New("peer_grouper_op").Parse(s)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	windowPeerGrouperTmplInfos := []windowPeerGrouperTmplInfo{
    37  		{AllPeers: false, HasPartition: false, String: "windowPeerGrouperNoPartition"},
    38  		{AllPeers: false, HasPartition: true, String: "windowPeerGrouperWithPartition"},
    39  		{AllPeers: true, HasPartition: false, String: "windowPeerGrouperAllPeersNoPartition"},
    40  		{AllPeers: true, HasPartition: true, String: "windowPeerGrouperAllPeersWithPartition"},
    41  	}
    42  	return tmpl.Execute(wr, windowPeerGrouperTmplInfos)
    43  }
    44  
    45  func init() {
    46  	registerGenerator(genWindowPeerGrouperOps, "window_peer_grouper.eg.go", windowPeerGrouperOpsTmpl)
    47  }