From 23cfb1339ed39b40dc5b85036485c555ebf7c31b Mon Sep 17 00:00:00 2001 From: Daylon Wilkins Date: Thu, 18 Apr 2024 05:01:06 -0700 Subject: [PATCH] Added explicit initialization order to packages --- server/cast/bool.go | 4 +- server/cast/bytea.go | 4 +- server/cast/char.go | 4 +- server/cast/float32.go | 4 +- server/cast/float64.go | 4 +- server/cast/init.go | 31 +++++++ server/cast/int16.go | 4 +- server/cast/int32.go | 4 +- server/cast/int64.go | 4 +- server/cast/numeric.go | 4 +- server/cast/text.go | 4 +- server/cast/uuid.go | 4 +- server/cast/varchar.go | 4 +- server/config/parameters.go | 4 +- server/expression/binary_operator.go | 1 - server/expression/cast.go | 1 - server/expression/unary_operator.go | 1 - server/functions/abs.go | 4 +- server/functions/acos.go | 4 +- server/functions/acosd.go | 4 +- server/functions/acosh.go | 4 +- server/functions/ascii.go | 4 +- server/functions/asin.go | 4 +- server/functions/asind.go | 4 +- server/functions/asinh.go | 4 +- server/functions/atan.go | 4 +- server/functions/atan2.go | 4 +- server/functions/atan2d.go | 4 +- server/functions/atand.go | 4 +- server/functions/atanh.go | 4 +- server/functions/binary/bit_and.go | 4 +- server/functions/binary/bit_or.go | 4 +- server/functions/binary/bit_xor.go | 4 +- server/functions/binary/divide.go | 4 +- server/functions/binary/init.go | 29 +++++++ server/functions/binary/minus.go | 4 +- server/functions/binary/mod.go | 4 +- server/functions/binary/multiply.go | 4 +- server/functions/binary/plus.go | 4 +- server/functions/binary/shift_left.go | 4 +- server/functions/binary/shift_right.go | 4 +- server/functions/bit_length.go | 4 +- server/functions/btrim.go | 4 +- server/functions/cbrt.go | 4 +- server/functions/ceil.go | 4 +- server/functions/char_length.go | 4 +- server/functions/chr.go | 4 +- server/functions/cos.go | 4 +- server/functions/cosd.go | 4 +- server/functions/cosh.go | 4 +- server/functions/cot.go | 4 +- server/functions/cotd.go | 4 +- server/functions/degrees.go | 4 +- server/functions/div.go | 4 +- server/functions/exp.go | 4 +- server/functions/factorial.go | 4 +- server/functions/floor.go | 4 +- server/functions/gcd.go | 4 +- server/functions/init.go | 91 ++++++++++++++++++++ server/functions/initcap.go | 4 +- server/functions/lcm.go | 4 +- server/functions/left.go | 4 +- server/functions/length.go | 4 +- server/functions/ln.go | 4 +- server/functions/log.go | 4 +- server/functions/log10.go | 4 +- server/functions/lower.go | 4 +- server/functions/lpad.go | 4 +- server/functions/ltrim.go | 4 +- server/functions/md5.go | 4 +- server/functions/min_scale.go | 4 +- server/functions/mod.go | 4 +- server/functions/octet_length.go | 4 +- server/functions/pi.go | 4 +- server/functions/power.go | 4 +- server/functions/radians.go | 4 +- server/functions/random.go | 4 +- server/functions/repeat.go | 4 +- server/functions/replace.go | 4 +- server/functions/reverse.go | 4 +- server/functions/right.go | 4 +- server/functions/round.go | 4 +- server/functions/rpad.go | 4 +- server/functions/rtrim.go | 4 +- server/functions/scale.go | 4 +- server/functions/sign.go | 4 +- server/functions/sin.go | 4 +- server/functions/sind.go | 4 +- server/functions/sinh.go | 4 +- server/functions/split_part.go | 4 +- server/functions/sqrt.go | 4 +- server/functions/strpos.go | 4 +- server/functions/substr.go | 4 +- server/functions/tan.go | 4 +- server/functions/tand.go | 4 +- server/functions/tanh.go | 4 +- server/functions/to_hex.go | 4 +- server/functions/trim_scale.go | 4 +- server/functions/trunc.go | 4 +- server/functions/unary/init.go | 21 +++++ server/functions/unary/minus.go | 4 +- server/functions/unary/plus.go | 4 +- server/functions/upper.go | 4 +- server/functions/width_bucket.go | 4 +- server/initialization/initialization.go | 42 +++++++++ server/listener.go | 2 - server/server.go | 6 +- server/types/base_ids.go | 4 +- testing/generation/function_coverage/main.go | 4 +- 109 files changed, 414 insertions(+), 207 deletions(-) create mode 100644 server/cast/init.go create mode 100644 server/functions/binary/init.go create mode 100644 server/functions/init.go create mode 100644 server/functions/unary/init.go create mode 100644 server/initialization/initialization.go diff --git a/server/cast/bool.go b/server/cast/bool.go index e346ff7414..fc25bcb9ee 100644 --- a/server/cast/bool.go +++ b/server/cast/bool.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initBool handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initBool() { boolExplicit() boolImplicit() } diff --git a/server/cast/bytea.go b/server/cast/bytea.go index 27c0ff367b..31a27e5f06 100644 --- a/server/cast/bytea.go +++ b/server/cast/bytea.go @@ -21,8 +21,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initBytea handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initBytea() { // TODO: handle the different output formats? byteaExplicit() byteaImplicit() diff --git a/server/cast/char.go b/server/cast/char.go index 3eb7aa775d..dd6c8c722e 100644 --- a/server/cast/char.go +++ b/server/cast/char.go @@ -27,8 +27,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initChar handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initChar() { charExplicit() charImplicit() } diff --git a/server/cast/float32.go b/server/cast/float32.go index 1e7dde0748..0572f7287b 100644 --- a/server/cast/float32.go +++ b/server/cast/float32.go @@ -25,8 +25,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initFloat32 handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initFloat32() { float32Explicit() float32Implicit() } diff --git a/server/cast/float64.go b/server/cast/float64.go index 85174efbfb..7e2f041787 100644 --- a/server/cast/float64.go +++ b/server/cast/float64.go @@ -25,8 +25,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initFloat64 handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initFloat64() { float64Explicit() float64Implicit() } diff --git a/server/cast/init.go b/server/cast/init.go new file mode 100644 index 0000000000..cf4d715229 --- /dev/null +++ b/server/cast/init.go @@ -0,0 +1,31 @@ +// Copyright 2024 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cast + +// Init initializes all casts in this package. +func Init() { + initBool() + initBytea() + initChar() + initFloat32() + initFloat64() + initInt16() + initInt32() + initInt64() + initNumeric() + initText() + initUuid() + initVarChar() +} diff --git a/server/cast/int16.go b/server/cast/int16.go index 92fec30175..fbd3001fc5 100644 --- a/server/cast/int16.go +++ b/server/cast/int16.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initInt16 handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initInt16() { int16Explicit() int16Implicit() } diff --git a/server/cast/int32.go b/server/cast/int32.go index a72c133974..8556d10de8 100644 --- a/server/cast/int32.go +++ b/server/cast/int32.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initInt32 handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initInt32() { int32Explicit() int32Implicit() } diff --git a/server/cast/int64.go b/server/cast/int64.go index 2ac4d0a581..6449928810 100644 --- a/server/cast/int64.go +++ b/server/cast/int64.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initInt64 handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initInt64() { int64Explicit() int64Implicit() } diff --git a/server/cast/numeric.go b/server/cast/numeric.go index 162b3976c8..4f208bdb7d 100644 --- a/server/cast/numeric.go +++ b/server/cast/numeric.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initNumeric handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initNumeric() { numericExplicit() numericImplicit() } diff --git a/server/cast/text.go b/server/cast/text.go index f962e0f050..d6f5a26ff2 100644 --- a/server/cast/text.go +++ b/server/cast/text.go @@ -27,8 +27,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initText handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initText() { textExplicit() textImplicit() } diff --git a/server/cast/uuid.go b/server/cast/uuid.go index 08e63fa343..e25530f3dd 100644 --- a/server/cast/uuid.go +++ b/server/cast/uuid.go @@ -20,8 +20,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initUuid handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initUuid() { uuidExplicit() uuidImplicit() } diff --git a/server/cast/varchar.go b/server/cast/varchar.go index b7b8a4f74c..fc73b72c11 100644 --- a/server/cast/varchar.go +++ b/server/cast/varchar.go @@ -27,8 +27,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init handles all explicit and implicit casts that are built-in. This comprises only the "From" types. -func init() { +// initVarChar handles all explicit and implicit casts that are built-in. This comprises only the "From" types. +func initVarChar() { varcharExplicit() varcharImplicit() } diff --git a/server/config/parameters.go b/server/config/parameters.go index 5968dbe55e..c14c35a639 100644 --- a/server/config/parameters.go +++ b/server/config/parameters.go @@ -26,11 +26,11 @@ import ( "github.com/dolthub/go-mysql-server/sql/variables" ) -// init initializes or appends to SystemVariables as it functions as a global variable. +// Init initializes or appends to SystemVariables as it functions as a global variable. // Currently, we append all of postgres configuration parameters to sql.SystemVariables. // This means that all of mysql system variables and postgres config parameters will be stored together. // TODO: get rid of me, use an integration point to define new sysvars -func init() { +func Init() { // There are two postgres parameters have the same name as mysql variables // TODO: issue with this approach is that those parameters will override the mysql variables. if sql.SystemVariables == nil { diff --git a/server/expression/binary_operator.go b/server/expression/binary_operator.go index ad46e850ba..e4555839ed 100644 --- a/server/expression/binary_operator.go +++ b/server/expression/binary_operator.go @@ -21,7 +21,6 @@ import ( "github.com/dolthub/go-mysql-server/sql/expression" vitess "github.com/dolthub/vitess/go/vt/sqlparser" - _ "github.com/dolthub/doltgresql/server/functions/binary" "github.com/dolthub/doltgresql/server/functions/framework" ) diff --git a/server/expression/cast.go b/server/expression/cast.go index d23d0df14b..317a392ee5 100644 --- a/server/expression/cast.go +++ b/server/expression/cast.go @@ -21,7 +21,6 @@ import ( "github.com/dolthub/vitess/go/vt/proto/query" vitess "github.com/dolthub/vitess/go/vt/sqlparser" - _ "github.com/dolthub/doltgresql/server/cast" "github.com/dolthub/doltgresql/server/functions/framework" pgtypes "github.com/dolthub/doltgresql/server/types" ) diff --git a/server/expression/unary_operator.go b/server/expression/unary_operator.go index 4215fce5ce..fa8ad2cca9 100644 --- a/server/expression/unary_operator.go +++ b/server/expression/unary_operator.go @@ -21,7 +21,6 @@ import ( vitess "github.com/dolthub/vitess/go/vt/sqlparser" "github.com/dolthub/doltgresql/server/functions/framework" - _ "github.com/dolthub/doltgresql/server/functions/unary" ) // UnaryOperator represents a VALUE OPERATOR VALUE expression. diff --git a/server/functions/abs.go b/server/functions/abs.go index 7280890fe1..5c9ac33c95 100644 --- a/server/functions/abs.go +++ b/server/functions/abs.go @@ -22,8 +22,8 @@ import ( "github.com/dolthub/doltgresql/utils" ) -// init registers the functions to the catalog. -func init() { +// initAbs registers the functions to the catalog. +func initAbs() { framework.RegisterFunction(abs_int16) framework.RegisterFunction(abs_int32) framework.RegisterFunction(abs_int64) diff --git a/server/functions/acos.go b/server/functions/acos.go index 7414efb544..379c2f5497 100644 --- a/server/functions/acos.go +++ b/server/functions/acos.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAcos registers the functions to the catalog. +func initAcos() { framework.RegisterFunction(acos_float64) } diff --git a/server/functions/acosd.go b/server/functions/acosd.go index d76fbfce28..97d5a84fba 100644 --- a/server/functions/acosd.go +++ b/server/functions/acosd.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAcosd registers the functions to the catalog. +func initAcosd() { framework.RegisterFunction(acosd_float64) } diff --git a/server/functions/acosh.go b/server/functions/acosh.go index 3e9208a703..275e3202c1 100644 --- a/server/functions/acosh.go +++ b/server/functions/acosh.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAcosh registers the functions to the catalog. +func initAcosh() { framework.RegisterFunction(acosh_float64) } diff --git a/server/functions/ascii.go b/server/functions/ascii.go index c4bbe94097..307a3563a2 100644 --- a/server/functions/ascii.go +++ b/server/functions/ascii.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAscii registers the functions to the catalog. +func initAscii() { framework.RegisterFunction(ascii_varchar) } diff --git a/server/functions/asin.go b/server/functions/asin.go index 821bc14890..919d43f75a 100644 --- a/server/functions/asin.go +++ b/server/functions/asin.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAsin registers the functions to the catalog. +func initAsin() { framework.RegisterFunction(asin_float64) } diff --git a/server/functions/asind.go b/server/functions/asind.go index 975eb83665..d64fbc141d 100644 --- a/server/functions/asind.go +++ b/server/functions/asind.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAsind registers the functions to the catalog. +func initAsind() { framework.RegisterFunction(asind_float64) } diff --git a/server/functions/asinh.go b/server/functions/asinh.go index 660c703a13..73021f16e7 100644 --- a/server/functions/asinh.go +++ b/server/functions/asinh.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAsinh registers the functions to the catalog. +func initAsinh() { framework.RegisterFunction(asinh_float64) } diff --git a/server/functions/atan.go b/server/functions/atan.go index fae538ce9e..2b6af74ad7 100644 --- a/server/functions/atan.go +++ b/server/functions/atan.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAtan registers the functions to the catalog. +func initAtan() { framework.RegisterFunction(atan_float64) } diff --git a/server/functions/atan2.go b/server/functions/atan2.go index de0a3214bc..4a541b6334 100644 --- a/server/functions/atan2.go +++ b/server/functions/atan2.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAtan2 registers the functions to the catalog. +func initAtan2() { framework.RegisterFunction(atan2_float64) } diff --git a/server/functions/atan2d.go b/server/functions/atan2d.go index e2f91588c7..767806289e 100644 --- a/server/functions/atan2d.go +++ b/server/functions/atan2d.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAtan2d registers the functions to the catalog. +func initAtan2d() { framework.RegisterFunction(atan2d_float64) } diff --git a/server/functions/atand.go b/server/functions/atand.go index 36431914e9..23d49ad1e4 100644 --- a/server/functions/atand.go +++ b/server/functions/atand.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAtand registers the functions to the catalog. +func initAtand() { framework.RegisterFunction(atand_float64) } diff --git a/server/functions/atanh.go b/server/functions/atanh.go index ab3c3bbacc..88f6468618 100644 --- a/server/functions/atanh.go +++ b/server/functions/atanh.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initAtanh registers the functions to the catalog. +func initAtanh() { framework.RegisterFunction(atanh_float64) } diff --git a/server/functions/binary/bit_and.go b/server/functions/binary/bit_and.go index 0c58877ff4..8585a54836 100644 --- a/server/functions/binary/bit_and.go +++ b/server/functions/binary/bit_and.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '&' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// InitBinaryBitAnd registers the functions to the catalog. +func InitBinaryBitAnd() { framework.RegisterBinaryFunction(framework.Operator_BinaryBitAnd, int2and) framework.RegisterBinaryFunction(framework.Operator_BinaryBitAnd, int4and) framework.RegisterBinaryFunction(framework.Operator_BinaryBitAnd, int8and) diff --git a/server/functions/binary/bit_or.go b/server/functions/binary/bit_or.go index 9d513cede4..a938faf735 100644 --- a/server/functions/binary/bit_or.go +++ b/server/functions/binary/bit_or.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '|' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryBitOr registers the functions to the catalog. +func initBinaryBitOr() { framework.RegisterBinaryFunction(framework.Operator_BinaryBitOr, int2or) framework.RegisterBinaryFunction(framework.Operator_BinaryBitOr, int4or) framework.RegisterBinaryFunction(framework.Operator_BinaryBitOr, int8or) diff --git a/server/functions/binary/bit_xor.go b/server/functions/binary/bit_xor.go index 1fdfbc81f9..cc306da314 100644 --- a/server/functions/binary/bit_xor.go +++ b/server/functions/binary/bit_xor.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '#' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryBitXor registers the functions to the catalog. +func initBinaryBitXor() { framework.RegisterBinaryFunction(framework.Operator_BinaryBitXor, int2xor) framework.RegisterBinaryFunction(framework.Operator_BinaryBitXor, int4xor) framework.RegisterBinaryFunction(framework.Operator_BinaryBitXor, int8xor) diff --git a/server/functions/binary/divide.go b/server/functions/binary/divide.go index 93131ec2cd..66ddd771c0 100644 --- a/server/functions/binary/divide.go +++ b/server/functions/binary/divide.go @@ -26,8 +26,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '/' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryDivide registers the functions to the catalog. +func initBinaryDivide() { framework.RegisterBinaryFunction(framework.Operator_BinaryDivide, float4div) framework.RegisterBinaryFunction(framework.Operator_BinaryDivide, float48div) framework.RegisterBinaryFunction(framework.Operator_BinaryDivide, float8div) diff --git a/server/functions/binary/init.go b/server/functions/binary/init.go new file mode 100644 index 0000000000..e4ef628c01 --- /dev/null +++ b/server/functions/binary/init.go @@ -0,0 +1,29 @@ +// Copyright 2024 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package binary + +// Init initializes all binary operators in this package. +func Init() { + InitBinaryBitAnd() + initBinaryBitOr() + initBinaryBitXor() + initBinaryDivide() + initBinaryMinus() + initBinaryMod() + initBinaryMultiply() + initBinaryPlus() + initBinaryShiftLeft() + initBinaryShiftRight() +} diff --git a/server/functions/binary/minus.go b/server/functions/binary/minus.go index 21df7c95cb..bb58423c77 100644 --- a/server/functions/binary/minus.go +++ b/server/functions/binary/minus.go @@ -27,8 +27,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '-' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryMinus registers the functions to the catalog. +func initBinaryMinus() { framework.RegisterBinaryFunction(framework.Operator_BinaryMinus, float4mi) framework.RegisterBinaryFunction(framework.Operator_BinaryMinus, float48mi) framework.RegisterBinaryFunction(framework.Operator_BinaryMinus, float8mi) diff --git a/server/functions/binary/mod.go b/server/functions/binary/mod.go index e447566a54..8b1192338a 100644 --- a/server/functions/binary/mod.go +++ b/server/functions/binary/mod.go @@ -26,8 +26,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '%' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryMod registers the functions to the catalog. +func initBinaryMod() { framework.RegisterBinaryFunction(framework.Operator_BinaryMod, int2mod) framework.RegisterBinaryFunction(framework.Operator_BinaryMod, int4mod) framework.RegisterBinaryFunction(framework.Operator_BinaryMod, int8mod) diff --git a/server/functions/binary/multiply.go b/server/functions/binary/multiply.go index 29f1125f7a..d7cf76bb9b 100644 --- a/server/functions/binary/multiply.go +++ b/server/functions/binary/multiply.go @@ -27,8 +27,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '*' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryMultiply registers the functions to the catalog. +func initBinaryMultiply() { framework.RegisterBinaryFunction(framework.Operator_BinaryMultiply, float4mul) framework.RegisterBinaryFunction(framework.Operator_BinaryMultiply, float48mul) framework.RegisterBinaryFunction(framework.Operator_BinaryMultiply, float8mul) diff --git a/server/functions/binary/plus.go b/server/functions/binary/plus.go index 249cfa55a5..e87cb54c67 100644 --- a/server/functions/binary/plus.go +++ b/server/functions/binary/plus.go @@ -27,8 +27,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '+' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryPlus registers the functions to the catalog. +func initBinaryPlus() { framework.RegisterBinaryFunction(framework.Operator_BinaryPlus, float4pl) framework.RegisterBinaryFunction(framework.Operator_BinaryPlus, float48pl) framework.RegisterBinaryFunction(framework.Operator_BinaryPlus, float8pl) diff --git a/server/functions/binary/shift_left.go b/server/functions/binary/shift_left.go index e2c61d6ea7..84c8be9f44 100644 --- a/server/functions/binary/shift_left.go +++ b/server/functions/binary/shift_left.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '<<' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryShiftLeft registers the functions to the catalog. +func initBinaryShiftLeft() { framework.RegisterBinaryFunction(framework.Operator_BinaryShiftLeft, int2shl) framework.RegisterBinaryFunction(framework.Operator_BinaryShiftLeft, int4shl) framework.RegisterBinaryFunction(framework.Operator_BinaryShiftLeft, int8shl) diff --git a/server/functions/binary/shift_right.go b/server/functions/binary/shift_right.go index 9b42a54856..06747f842d 100644 --- a/server/functions/binary/shift_right.go +++ b/server/functions/binary/shift_right.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '>>' ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initBinaryShiftRight registers the functions to the catalog. +func initBinaryShiftRight() { framework.RegisterBinaryFunction(framework.Operator_BinaryShiftRight, int2shr) framework.RegisterBinaryFunction(framework.Operator_BinaryShiftRight, int4shr) framework.RegisterBinaryFunction(framework.Operator_BinaryShiftRight, int8shr) diff --git a/server/functions/bit_length.go b/server/functions/bit_length.go index cad7133b51..33294b5ac5 100644 --- a/server/functions/bit_length.go +++ b/server/functions/bit_length.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initBitLength registers the functions to the catalog. +func initBitLength() { framework.RegisterFunction(bit_length_varchar) } diff --git a/server/functions/btrim.go b/server/functions/btrim.go index 5e8b5020cd..c687ce9bd5 100644 --- a/server/functions/btrim.go +++ b/server/functions/btrim.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initBtrim registers the functions to the catalog. +func initBtrim() { framework.RegisterFunction(btrim_varchar_varchar) } diff --git a/server/functions/cbrt.go b/server/functions/cbrt.go index 49a668c04a..e315059a6c 100644 --- a/server/functions/cbrt.go +++ b/server/functions/cbrt.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCbrt registers the functions to the catalog. +func initCbrt() { framework.RegisterFunction(cbrt_float64) } diff --git a/server/functions/ceil.go b/server/functions/ceil.go index 3918a85b36..936b780013 100644 --- a/server/functions/ceil.go +++ b/server/functions/ceil.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCeil registers the functions to the catalog. +func initCeil() { framework.RegisterFunction(ceil_float64) framework.RegisterFunction(ceil_numeric) // Register aliases diff --git a/server/functions/char_length.go b/server/functions/char_length.go index 86c3a4d641..0e1d52b492 100644 --- a/server/functions/char_length.go +++ b/server/functions/char_length.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCharLength registers the functions to the catalog. +func initCharLength() { framework.RegisterFunction(char_length_varchar) // Register alias character_length_varchar := char_length_varchar diff --git a/server/functions/chr.go b/server/functions/chr.go index a5ab8d299e..72e7ba9102 100644 --- a/server/functions/chr.go +++ b/server/functions/chr.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initChr registers the functions to the catalog. +func initChr() { framework.RegisterFunction(chr_int32) } diff --git a/server/functions/cos.go b/server/functions/cos.go index adc4d76911..809343ee94 100644 --- a/server/functions/cos.go +++ b/server/functions/cos.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCos registers the functions to the catalog. +func initCos() { framework.RegisterFunction(cos_float64) } diff --git a/server/functions/cosd.go b/server/functions/cosd.go index 9e83291ed9..0fa95137ba 100644 --- a/server/functions/cosd.go +++ b/server/functions/cosd.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCosd registers the functions to the catalog. +func initCosd() { framework.RegisterFunction(cosd_float64) } diff --git a/server/functions/cosh.go b/server/functions/cosh.go index 96e63abf61..77eaa70f3a 100644 --- a/server/functions/cosh.go +++ b/server/functions/cosh.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCosh registers the functions to the catalog. +func initCosh() { framework.RegisterFunction(cosh_float64) } diff --git a/server/functions/cot.go b/server/functions/cot.go index b5d4a67e26..d357d340d8 100644 --- a/server/functions/cot.go +++ b/server/functions/cot.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCot registers the functions to the catalog. +func initCot() { framework.RegisterFunction(cot_float64) } diff --git a/server/functions/cotd.go b/server/functions/cotd.go index 56cc6130d6..75c8da4f7e 100644 --- a/server/functions/cotd.go +++ b/server/functions/cotd.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initCotd registers the functions to the catalog. +func initCotd() { framework.RegisterFunction(cotd_float64) } diff --git a/server/functions/degrees.go b/server/functions/degrees.go index 4d05b06832..bb3144ddde 100644 --- a/server/functions/degrees.go +++ b/server/functions/degrees.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initDegrees registers the functions to the catalog. +func initDegrees() { framework.RegisterFunction(degrees_float64) } diff --git a/server/functions/div.go b/server/functions/div.go index b995c3c4a5..f670ba454f 100644 --- a/server/functions/div.go +++ b/server/functions/div.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initDiv registers the functions to the catalog. +func initDiv() { framework.RegisterFunction(div_numeric) } diff --git a/server/functions/exp.go b/server/functions/exp.go index a5a01900e7..4a5f079a52 100644 --- a/server/functions/exp.go +++ b/server/functions/exp.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initExp registers the functions to the catalog. +func initExp() { framework.RegisterFunction(exp_float64) framework.RegisterFunction(exp_numeric) } diff --git a/server/functions/factorial.go b/server/functions/factorial.go index e7115b2e07..46742d1b62 100644 --- a/server/functions/factorial.go +++ b/server/functions/factorial.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initFactorial registers the functions to the catalog. +func initFactorial() { framework.RegisterFunction(factorial_int64) } diff --git a/server/functions/floor.go b/server/functions/floor.go index 8fec757551..0cbeed8cc1 100644 --- a/server/functions/floor.go +++ b/server/functions/floor.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initFloor registers the functions to the catalog. +func initFloor() { framework.RegisterFunction(floor_float64) framework.RegisterFunction(floor_numeric) } diff --git a/server/functions/gcd.go b/server/functions/gcd.go index 711a8eff7e..0d3b98d894 100644 --- a/server/functions/gcd.go +++ b/server/functions/gcd.go @@ -20,8 +20,8 @@ import ( "github.com/dolthub/doltgresql/utils" ) -// init registers the functions to the catalog. -func init() { +// initGcd registers the functions to the catalog. +func initGcd() { framework.RegisterFunction(gcd_int64_int64) } diff --git a/server/functions/init.go b/server/functions/init.go new file mode 100644 index 0000000000..ee6ccacdcc --- /dev/null +++ b/server/functions/init.go @@ -0,0 +1,91 @@ +// Copyright 2024 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package functions + +// Init initializes all functions in this package. +func Init() { + initAbs() + initAcos() + initAcosd() + initAcosh() + initAscii() + initAsin() + initAsind() + initAsinh() + initAtan() + initAtan2() + initAtan2d() + initAtand() + initAtanh() + initBitLength() + initBtrim() + initCbrt() + initCeil() + initCharLength() + initChr() + initCos() + initCosd() + initCosh() + initCot() + initCotd() + initDegrees() + initDiv() + initExp() + initFactorial() + initFloor() + initGcd() + initInitcap() + initLcm() + initLeft() + initLength() + initLn() + initLog() + initLog10() + initLower() + initLpad() + initLtrim() + initMd5() + initMinScale() + initMod() + initOctetLength() + initPi() + initPower() + initRadians() + initRandom() + initRepeat() + initReplace() + initReverse() + initRight() + initRound() + initRpad() + initRtrim() + initScale() + initSign() + initSin() + initSind() + initSinh() + initSplitPart() + initSqrt() + initStrpos() + initSubstr() + initTan() + initTand() + initTanh() + initToHex() + initTrimScale() + initTrunc() + initUpper() + initWidthBucket() +} diff --git a/server/functions/initcap.go b/server/functions/initcap.go index cce48f8211..74bcf1b762 100644 --- a/server/functions/initcap.go +++ b/server/functions/initcap.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initInitcap registers the functions to the catalog. +func initInitcap() { framework.RegisterFunction(initcap_varchar) } diff --git a/server/functions/lcm.go b/server/functions/lcm.go index e17a2112d9..866c75252e 100644 --- a/server/functions/lcm.go +++ b/server/functions/lcm.go @@ -22,8 +22,8 @@ import ( "github.com/dolthub/doltgresql/utils" ) -// init registers the functions to the catalog. -func init() { +// initLcm registers the functions to the catalog. +func initLcm() { framework.RegisterFunction(lcm_int64_int64) } diff --git a/server/functions/left.go b/server/functions/left.go index 16059aa13d..9d14c5e1e3 100644 --- a/server/functions/left.go +++ b/server/functions/left.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLeft registers the functions to the catalog. +func initLeft() { framework.RegisterFunction(left_varchar_int32) } diff --git a/server/functions/length.go b/server/functions/length.go index 0a696e286c..4cc5f3e4de 100644 --- a/server/functions/length.go +++ b/server/functions/length.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLength registers the functions to the catalog. +func initLength() { framework.RegisterFunction(length_varchar) } diff --git a/server/functions/ln.go b/server/functions/ln.go index 82029135aa..5f70743874 100644 --- a/server/functions/ln.go +++ b/server/functions/ln.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLn registers the functions to the catalog. +func initLn() { framework.RegisterFunction(ln_float64) framework.RegisterFunction(ln_numeric) } diff --git a/server/functions/log.go b/server/functions/log.go index 6a4b5e4166..db1c2f60be 100644 --- a/server/functions/log.go +++ b/server/functions/log.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLog registers the functions to the catalog. +func initLog() { framework.RegisterFunction(log_float64) framework.RegisterFunction(log_numeric) framework.RegisterFunction(log_numeric_numeric) diff --git a/server/functions/log10.go b/server/functions/log10.go index 974350c5ba..c26eb314c1 100644 --- a/server/functions/log10.go +++ b/server/functions/log10.go @@ -16,8 +16,8 @@ package functions import "github.com/dolthub/doltgresql/server/functions/framework" -// init registers the functions to the catalog. -func init() { +// initLog10 registers the functions to the catalog. +func initLog10() { log10_float64 := log_float64 log10_numeric := log_numeric log10_float64.Name = "log10" diff --git a/server/functions/lower.go b/server/functions/lower.go index d6d98c6d0c..bf83d7bc12 100644 --- a/server/functions/lower.go +++ b/server/functions/lower.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLower registers the functions to the catalog. +func initLower() { framework.RegisterFunction(lower_varchar) } diff --git a/server/functions/lpad.go b/server/functions/lpad.go index 87c08cb396..62c5f00611 100644 --- a/server/functions/lpad.go +++ b/server/functions/lpad.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLpad registers the functions to the catalog. +func initLpad() { framework.RegisterFunction(lpad_varchar_int32) framework.RegisterFunction(lpad_varchar_int32_varchar) } diff --git a/server/functions/ltrim.go b/server/functions/ltrim.go index ee3d4814b8..233ffd6dba 100644 --- a/server/functions/ltrim.go +++ b/server/functions/ltrim.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initLtrim registers the functions to the catalog. +func initLtrim() { framework.RegisterFunction(ltrim_varchar) framework.RegisterFunction(ltrim_varchar_varchar) } diff --git a/server/functions/md5.go b/server/functions/md5.go index f28f44511f..80301a181e 100644 --- a/server/functions/md5.go +++ b/server/functions/md5.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initMd5 registers the functions to the catalog. +func initMd5() { framework.RegisterFunction(md5_varchar) } diff --git a/server/functions/min_scale.go b/server/functions/min_scale.go index 7e1f6fb2ca..d4ef48425f 100644 --- a/server/functions/min_scale.go +++ b/server/functions/min_scale.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initMinScale registers the functions to the catalog. +func initMinScale() { framework.RegisterFunction(min_scale_numeric) } diff --git a/server/functions/mod.go b/server/functions/mod.go index e9d5e9ca8b..df00cc2ae3 100644 --- a/server/functions/mod.go +++ b/server/functions/mod.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initMod registers the functions to the catalog. +func initMod() { framework.RegisterFunction(mod_int16_int16) framework.RegisterFunction(mod_int32_int32) framework.RegisterFunction(mod_int64_int64) diff --git a/server/functions/octet_length.go b/server/functions/octet_length.go index d5df7f3d85..8c603c89b1 100644 --- a/server/functions/octet_length.go +++ b/server/functions/octet_length.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initOctetLength registers the functions to the catalog. +func initOctetLength() { framework.RegisterFunction(octet_length_varchar) } diff --git a/server/functions/pi.go b/server/functions/pi.go index 946cdf58e0..5aa1ddb434 100644 --- a/server/functions/pi.go +++ b/server/functions/pi.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initPi registers the functions to the catalog. +func initPi() { framework.RegisterFunction(pi) } diff --git a/server/functions/power.go b/server/functions/power.go index 2f43e4af04..c66f4182d2 100644 --- a/server/functions/power.go +++ b/server/functions/power.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initPower registers the functions to the catalog. +func initPower() { framework.RegisterFunction(power_float64_float64) framework.RegisterFunction(power_numeric_numeric) } diff --git a/server/functions/radians.go b/server/functions/radians.go index 081313e6ad..7d96b0fd3f 100644 --- a/server/functions/radians.go +++ b/server/functions/radians.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRadians registers the functions to the catalog. +func initRadians() { framework.RegisterFunction(radians_float64) } diff --git a/server/functions/random.go b/server/functions/random.go index 216866d772..bc1a9c3f03 100644 --- a/server/functions/random.go +++ b/server/functions/random.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRandom registers the functions to the catalog. +func initRandom() { framework.RegisterFunction(random) } diff --git a/server/functions/repeat.go b/server/functions/repeat.go index 5536ab89b0..e04be41c41 100644 --- a/server/functions/repeat.go +++ b/server/functions/repeat.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRepeat registers the functions to the catalog. +func initRepeat() { framework.RegisterFunction(repeat_varchar_int32) } diff --git a/server/functions/replace.go b/server/functions/replace.go index 119d928141..4dce7a884f 100644 --- a/server/functions/replace.go +++ b/server/functions/replace.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initReplace registers the functions to the catalog. +func initReplace() { framework.RegisterFunction(replace_varchar_varchar_varchar) } diff --git a/server/functions/reverse.go b/server/functions/reverse.go index a66fb8068a..72446e8c62 100644 --- a/server/functions/reverse.go +++ b/server/functions/reverse.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initReverse registers the functions to the catalog. +func initReverse() { framework.RegisterFunction(reverse_varchar) } diff --git a/server/functions/right.go b/server/functions/right.go index 8699bc4199..349a4f76c5 100644 --- a/server/functions/right.go +++ b/server/functions/right.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRight registers the functions to the catalog. +func initRight() { framework.RegisterFunction(right_varchar_int32) } diff --git a/server/functions/round.go b/server/functions/round.go index de1a111ad3..93777d6f02 100644 --- a/server/functions/round.go +++ b/server/functions/round.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRound registers the functions to the catalog. +func initRound() { framework.RegisterFunction(round_float64) framework.RegisterFunction(round_numeric) framework.RegisterFunction(round_numeric_int64) diff --git a/server/functions/rpad.go b/server/functions/rpad.go index c52e2cfe84..e776c78506 100644 --- a/server/functions/rpad.go +++ b/server/functions/rpad.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRpad registers the functions to the catalog. +func initRpad() { framework.RegisterFunction(rpad_varchar_int32) framework.RegisterFunction(rpad_varchar_int32_varchar) } diff --git a/server/functions/rtrim.go b/server/functions/rtrim.go index 16e9a23bab..1758465f8c 100644 --- a/server/functions/rtrim.go +++ b/server/functions/rtrim.go @@ -19,8 +19,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initRtrim registers the functions to the catalog. +func initRtrim() { framework.RegisterFunction(rtrim_varchar) framework.RegisterFunction(rtrim_varchar_varchar) } diff --git a/server/functions/scale.go b/server/functions/scale.go index 77a0e087c6..02ae7454df 100644 --- a/server/functions/scale.go +++ b/server/functions/scale.go @@ -20,8 +20,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initScale registers the functions to the catalog. +func initScale() { framework.RegisterFunction(scale_numeric) } diff --git a/server/functions/sign.go b/server/functions/sign.go index 411ee82eee..937f2c592a 100644 --- a/server/functions/sign.go +++ b/server/functions/sign.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initSign registers the functions to the catalog. +func initSign() { framework.RegisterFunction(sign_float64) framework.RegisterFunction(sign_numeric) } diff --git a/server/functions/sin.go b/server/functions/sin.go index c8e4d41f50..7a207354b7 100644 --- a/server/functions/sin.go +++ b/server/functions/sin.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initSin registers the functions to the catalog. +func initSin() { framework.RegisterFunction(sin_float64) } diff --git a/server/functions/sind.go b/server/functions/sind.go index ad90aa7bbc..8f4307e7d9 100644 --- a/server/functions/sind.go +++ b/server/functions/sind.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initSind registers the functions to the catalog. +func initSind() { framework.RegisterFunction(sind_float64) } diff --git a/server/functions/sinh.go b/server/functions/sinh.go index 57bfb2832c..b117692444 100644 --- a/server/functions/sinh.go +++ b/server/functions/sinh.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initSinh registers the functions to the catalog. +func initSinh() { framework.RegisterFunction(sinh_float64) } diff --git a/server/functions/split_part.go b/server/functions/split_part.go index 685036ed81..161124acfa 100644 --- a/server/functions/split_part.go +++ b/server/functions/split_part.go @@ -23,8 +23,8 @@ import ( "github.com/dolthub/doltgresql/utils" ) -// init registers the functions to the catalog. -func init() { +// initSplitPart registers the functions to the catalog. +func initSplitPart() { framework.RegisterFunction(split_part_varchar_varchar_int32) } diff --git a/server/functions/sqrt.go b/server/functions/sqrt.go index 5e1fdfb3f8..5ee15ed212 100644 --- a/server/functions/sqrt.go +++ b/server/functions/sqrt.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catasqrt. -func init() { +// initSqrt registers the functions to the catasqrt. +func initSqrt() { framework.RegisterFunction(sqrt_float64) framework.RegisterFunction(sqrt_numeric) } diff --git a/server/functions/strpos.go b/server/functions/strpos.go index f2d36ee48c..55cc836292 100644 --- a/server/functions/strpos.go +++ b/server/functions/strpos.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initStrpos registers the functions to the catalog. +func initStrpos() { framework.RegisterFunction(strpos_varchar) } diff --git a/server/functions/substr.go b/server/functions/substr.go index b71abd1b97..baef0307d8 100644 --- a/server/functions/substr.go +++ b/server/functions/substr.go @@ -21,8 +21,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initSubstr registers the functions to the catalog. +func initSubstr() { framework.RegisterFunction(substr_varchar_int32) framework.RegisterFunction(substr_varchar_int32_int32) } diff --git a/server/functions/tan.go b/server/functions/tan.go index 6733a6f7a6..d1a973bac6 100644 --- a/server/functions/tan.go +++ b/server/functions/tan.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initTan registers the functions to the catalog. +func initTan() { framework.RegisterFunction(tan_float64) } diff --git a/server/functions/tand.go b/server/functions/tand.go index 3232231048..ba3765aef1 100644 --- a/server/functions/tand.go +++ b/server/functions/tand.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initTand registers the functions to the catalog. +func initTand() { framework.RegisterFunction(tand_float64) } diff --git a/server/functions/tanh.go b/server/functions/tanh.go index 08ed2c396d..71f8827d02 100644 --- a/server/functions/tanh.go +++ b/server/functions/tanh.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initTanh registers the functions to the catalog. +func initTanh() { framework.RegisterFunction(tanh_float64) } diff --git a/server/functions/to_hex.go b/server/functions/to_hex.go index b05b5380ba..5ffc90e48e 100644 --- a/server/functions/to_hex.go +++ b/server/functions/to_hex.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initToHex registers the functions to the catalog. +func initToHex() { framework.RegisterFunction(to_hex_int64) } diff --git a/server/functions/trim_scale.go b/server/functions/trim_scale.go index baeedd6bfe..b04f3ffeef 100644 --- a/server/functions/trim_scale.go +++ b/server/functions/trim_scale.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initTrimScale registers the functions to the catalog. +func initTrimScale() { framework.RegisterFunction(trim_scale_numeric) } diff --git a/server/functions/trunc.go b/server/functions/trunc.go index 9b3b82bf6b..f7552dc6ce 100644 --- a/server/functions/trunc.go +++ b/server/functions/trunc.go @@ -23,8 +23,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initTrunc registers the functions to the catalog. +func initTrunc() { framework.RegisterFunction(trunc_float64) framework.RegisterFunction(trunc_numeric) framework.RegisterFunction(trunc_numeric_int64) diff --git a/server/functions/unary/init.go b/server/functions/unary/init.go new file mode 100644 index 0000000000..3aa2ec7288 --- /dev/null +++ b/server/functions/unary/init.go @@ -0,0 +1,21 @@ +// Copyright 2024 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package unary + +// Init initializes all unary operators in this package. +func Init() { + initUnaryMinus() + initUnaryPlus() +} diff --git a/server/functions/unary/minus.go b/server/functions/unary/minus.go index ca8ea3d231..3b7ab0510b 100644 --- a/server/functions/unary/minus.go +++ b/server/functions/unary/minus.go @@ -24,8 +24,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '-' AND o.oprleft = 0 ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initUnaryMinus registers the functions to the catalog. +func initUnaryMinus() { framework.RegisterUnaryFunction(framework.Operator_UnaryMinus, float4um) framework.RegisterUnaryFunction(framework.Operator_UnaryMinus, float8um) framework.RegisterUnaryFunction(framework.Operator_UnaryMinus, int2um) diff --git a/server/functions/unary/plus.go b/server/functions/unary/plus.go index c3b31cf381..4ce969ab80 100644 --- a/server/functions/unary/plus.go +++ b/server/functions/unary/plus.go @@ -22,8 +22,8 @@ import ( // These functions can be gathered using the following query from a Postgres 15 instance: // SELECT * FROM pg_operator o WHERE o.oprname = '+' AND o.oprleft = 0 ORDER BY o.oprcode::varchar; -// init registers the functions to the catalog. -func init() { +// initUnaryPlus registers the functions to the catalog. +func initUnaryPlus() { framework.RegisterUnaryFunction(framework.Operator_UnaryPlus, float4up) framework.RegisterUnaryFunction(framework.Operator_UnaryPlus, float8up) framework.RegisterUnaryFunction(framework.Operator_UnaryPlus, int2up) diff --git a/server/functions/upper.go b/server/functions/upper.go index 536106835d..0635547279 100644 --- a/server/functions/upper.go +++ b/server/functions/upper.go @@ -22,8 +22,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initUpper registers the functions to the catalog. +func initUpper() { framework.RegisterFunction(upper_varchar) } diff --git a/server/functions/width_bucket.go b/server/functions/width_bucket.go index 6d80c84a9b..1cd95cc2b6 100644 --- a/server/functions/width_bucket.go +++ b/server/functions/width_bucket.go @@ -24,8 +24,8 @@ import ( pgtypes "github.com/dolthub/doltgresql/server/types" ) -// init registers the functions to the catalog. -func init() { +// initWidthBucket registers the functions to the catalog. +func initWidthBucket() { framework.RegisterFunction(width_bucket_float64_float64_float64_int64) framework.RegisterFunction(width_bucket_numeric_numeric_numeric_int64) } diff --git a/server/initialization/initialization.go b/server/initialization/initialization.go new file mode 100644 index 0000000000..068520e687 --- /dev/null +++ b/server/initialization/initialization.go @@ -0,0 +1,42 @@ +// Copyright 2024 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package initialization + +import ( + "sync" + + "github.com/dolthub/doltgresql/server/cast" + "github.com/dolthub/doltgresql/server/config" + "github.com/dolthub/doltgresql/server/functions" + "github.com/dolthub/doltgresql/server/functions/binary" + "github.com/dolthub/doltgresql/server/functions/framework" + "github.com/dolthub/doltgresql/server/functions/unary" + pgtypes "github.com/dolthub/doltgresql/server/types" +) + +var once = &sync.Once{} + +// Initialize initializes each package across the project. This function should be used instead of an init() function. +func Initialize() { + once.Do(func() { + config.Init() + pgtypes.InitBaseIDs() + binary.Init() + unary.Init() + functions.Init() + cast.Init() + framework.Initialize() + }) +} diff --git a/server/listener.go b/server/listener.go index 50989fd222..4cbf76ff12 100644 --- a/server/listener.go +++ b/server/listener.go @@ -22,8 +22,6 @@ import ( "github.com/dolthub/go-mysql-server/server" "github.com/dolthub/vitess/go/mysql" - - _ "github.com/dolthub/doltgresql/server/functions" ) var ( diff --git a/server/server.go b/server/server.go index 54a26fe2d3..7c7a58780b 100644 --- a/server/server.go +++ b/server/server.go @@ -36,8 +36,7 @@ import ( "github.com/dolthub/go-mysql-server/server" "github.com/dolthub/go-mysql-server/sql" - _ "github.com/dolthub/doltgresql/server/config" - "github.com/dolthub/doltgresql/server/functions/framework" + "github.com/dolthub/doltgresql/server/initialization" "github.com/dolthub/doltgresql/server/logrepl" ) @@ -126,7 +125,6 @@ func init() { server.DefaultProtocolListenerFunc = NewListener sqlserver.ExternalDisableUsers = true dfunctions.VersionString = Version - framework.Initialize() } // RunOnDisk starts the server based on the given args, while also using the local disk as the backing store. @@ -155,7 +153,7 @@ func RunInMemory(args []string) (*svcs.Controller, error) { // runServer starts the server based on the given args, using the provided file system as the backing store. // The returned WaitGroup may be used to wait for the server to close. func runServer(ctx context.Context, args []string, dEnv *env.DoltEnv) (*svcs.Controller, error) { - //doltgresconfig.InitConfigParameters() + initialization.Initialize() sqlServerCmd := sqlserver.SqlServerCmd{} if serverArgs, err := sqlServerCmd.ArgParser().Parse(append([]string{"sql-server"}, args...)); err == nil { diff --git a/server/types/base_ids.go b/server/types/base_ids.go index d5d1bb3043..900ae742fd 100644 --- a/server/types/base_ids.go +++ b/server/types/base_ids.go @@ -73,8 +73,8 @@ const ( // baseIDArrayTypes contains a map of all base IDs that represent array variants. var baseIDArrayTypes = map[DoltgresTypeBaseID]DoltgresArrayType{} -// init reads the list of all types and creates a mapping of the base ID for each array variant. -func init() { +// InitBaseIDs reads the list of all types and creates a mapping of the base ID for each array variant. +func InitBaseIDs() { for _, t := range typesFromBaseID { if dat, ok := t.(DoltgresArrayType); ok { baseIDArrayTypes[t.BaseID()] = dat diff --git a/testing/generation/function_coverage/main.go b/testing/generation/function_coverage/main.go index c0d700eb86..18e148c70c 100644 --- a/testing/generation/function_coverage/main.go +++ b/testing/generation/function_coverage/main.go @@ -20,8 +20,8 @@ import ( "github.com/dolthub/go-mysql-server/sql" - _ "github.com/dolthub/doltgresql/server/functions" "github.com/dolthub/doltgresql/server/functions/framework" + "github.com/dolthub/doltgresql/server/initialization" "github.com/dolthub/doltgresql/testing/generation/utils" ) @@ -33,7 +33,7 @@ type Assertion struct { } func main() { - framework.Initialize() + initialization.Initialize() rootFolder, err := utils.GetRootFolder() if err != nil { fmt.Printf("%s\n", err.Error())