Skip to content

Commit

Permalink
colexecproj: split up default cmp proj op file into two
Browse files Browse the repository at this point in the history
This commit splits up a single file containing two default comparison
projection operators into two files. This is done in preparation of
the following commit (which will move one of the operators to a
different package).

Release note: None
  • Loading branch information
yuzefovich committed Apr 7, 2022
1 parent 112a008 commit 4f9c27b
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 80 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ EXECGEN_TARGETS = \
pkg/sql/colexec/colexecjoin/mergejoiner_rightanti.eg.go \
pkg/sql/colexec/colexecjoin/mergejoiner_rightouter.eg.go \
pkg/sql/colexec/colexecjoin/mergejoiner_rightsemi.eg.go \
pkg/sql/colexec/colexecproj/default_cmp_proj_ops.eg.go \
pkg/sql/colexec/colexecproj/default_cmp_proj_const_op.eg.go \
pkg/sql/colexec/colexecproj/default_cmp_proj_op.eg.go \
pkg/sql/colexec/colexecproj/proj_const_left_ops.eg.go \
pkg/sql/colexec/colexecproj/proj_const_right_ops.eg.go \
pkg/sql/colexec/colexecproj/proj_like_ops.eg.go \
Expand Down
3 changes: 2 additions & 1 deletion pkg/gen/execgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ EXECGEN_SRCS = [
"//pkg/sql/colexec/colexecjoin:mergejoiner_rightanti.eg.go",
"//pkg/sql/colexec/colexecjoin:mergejoiner_rightouter.eg.go",
"//pkg/sql/colexec/colexecjoin:mergejoiner_rightsemi.eg.go",
"//pkg/sql/colexec/colexecproj:default_cmp_proj_ops.eg.go",
"//pkg/sql/colexec/colexecproj:default_cmp_proj_const_op.eg.go",
"//pkg/sql/colexec/colexecproj:default_cmp_proj_op.eg.go",
"//pkg/sql/colexec/colexecproj:proj_const_left_ops.eg.go",
"//pkg/sql/colexec/colexecproj:proj_const_right_ops.eg.go",
"//pkg/sql/colexec/colexecproj:proj_like_ops.eg.go",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/colexec/colexecproj/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ go_test(

# Map between target name and relevant template.
targets = [
("default_cmp_proj_ops.eg.go", "default_cmp_proj_ops_tmpl.go"),
("default_cmp_proj_const_op.eg.go", "default_cmp_proj_ops_tmpl.go"),
("default_cmp_proj_op.eg.go", "default_cmp_proj_ops_tmpl.go"),
("proj_const_left_ops.eg.go", "proj_const_ops_tmpl.go"),
("proj_const_right_ops.eg.go", "proj_const_ops_tmpl.go"),
("proj_like_ops.eg.go", "proj_const_ops_tmpl.go"),
Expand Down
78 changes: 78 additions & 0 deletions pkg/sql/colexec/colexecproj/default_cmp_proj_const_op.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pkg/sql/colexec/colexecproj/default_cmp_proj_ops_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// +build execgen_template

//
// This file is the execgen template for default_cmp_proj_ops.eg.go. It's
// formatted in a special way, so it's both valid Go and a valid text/template
// input. This permits editing this file with editor support.
// This file is the execgen template for default_cmp_proj_op.eg.go and
// default_cmp_proj_const_op.eg.go. It's formatted in a special way, so it's
// both valid Go and a valid text/template input. This permits editing this file
// with editor support.
//
// */}}

Expand All @@ -31,7 +32,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
)

// {{range .}}
// {{define "defaultCmpProjOp"}}

type defaultCmp_KINDProjOp struct {
// {{if .IsRightConst}}
Expand Down
87 changes: 71 additions & 16 deletions pkg/sql/colexec/execgen/cmd/execgen/default_cmp_proj_ops_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,82 @@ import (
"text/template"
)

// defaultCmpProjTemplate is the common base for the template used to generate
// code for default comparison projection operators. It should be used as a
// format string with one %s argument that specifies the package that the
// generated code is placed in.
const defaultCmpProjTemplate = `
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package {{.TargetPkg}}
import (
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/sql/colconv"
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexeccmp"
"github.com/cockroachdb/cockroach/pkg/sql/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/colexecop"
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
)
{{template "defaultCmpProjOp" .}}
`

const defaultCmpProjOpsTmpl = "pkg/sql/colexec/colexecproj/default_cmp_proj_ops_tmpl.go"

func genDefaultCmpProjOps(inputFileContents string, wr io.Writer) error {
s := strings.ReplaceAll(inputFileContents, "_KIND", "{{.Kind}}")
type defaultCmpProjOpOverload struct {
TargetPkg string
// Comparison operators are always normalized so that the constant is on the
// right side, so we skip generating the code when the constant is on the
// left.
IsRightConst bool
Kind string
}

func getDefaultCmpProjOps(overload defaultCmpProjOpOverload) generator {
return func(inputFileContents string, wr io.Writer) error {
s := strings.ReplaceAll(inputFileContents, "_KIND", "{{.Kind}}")

tmpl, err := template.New("default_cmp_proj_ops").Parse(s)
if err != nil {
return err
tmpl, err := template.New("default_cmp_proj_ops").Parse(s)
if err != nil {
return err
}
tmpl, err = tmpl.Parse(defaultCmpProjTemplate)
if err != nil {
return err
}
return tmpl.Execute(wr, overload)
}
return tmpl.Execute(wr, []struct {
// Comparison operators are always normalized so that the constant is
// on the right side, so we skip generating the code when the constant
// is on the left.
IsRightConst bool
Kind string
}{
{IsRightConst: false, Kind: ""},
{IsRightConst: true, Kind: "RConst"},
})
}

func init() {
registerGenerator(genDefaultCmpProjOps, "default_cmp_proj_ops.eg.go", defaultCmpProjOpsTmpl)
registerGenerator(
getDefaultCmpProjOps(
defaultCmpProjOpOverload{
TargetPkg: "colexecproj",
IsRightConst: true,
Kind: "RConst",
}),
"default_cmp_proj_const_op.eg.go", /* outputFile */
defaultCmpProjOpsTmpl,
)
registerGenerator(
getDefaultCmpProjOps(
defaultCmpProjOpOverload{
TargetPkg: "colexecproj",
IsRightConst: false,
Kind: "",
}),
"default_cmp_proj_op.eg.go", /* outputFile */
defaultCmpProjOpsTmpl,
)
}

0 comments on commit 4f9c27b

Please sign in to comment.