Skip to content
Snippets Groups Projects
builtins.go 48.09 KiB
// Copyright 2021 - 2022 Matrix Origin
//
// 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 function

import (
	"github.com/matrixorigin/matrixone/pkg/container/types"
	"github.com/matrixorigin/matrixone/pkg/pb/plan"
	"github.com/matrixorigin/matrixone/pkg/sql/plan/function/builtin/binary"
	"github.com/matrixorigin/matrixone/pkg/sql/plan/function/builtin/multi"
	"github.com/matrixorigin/matrixone/pkg/sql/plan/function/builtin/unary"
)

func initBuiltIns() {
	var err error

	for fid, fs := range builtins {
		err = appendFunction(fid, fs)
		if err != nil {
			panic(err)
		}
	}
}

// builtins contains the builtin function indexed by function id.
var builtins = map[int]Functions{
	ABS: {
		Id: ABS,
		Overloads: []Function{
			{
				Index:     0,
				Flag:      plan.Function_STRICT,
				Layout:    STANDARD_FUNCTION,
				Args:      []types.T{types.T_int64},
				ReturnTyp: types.T_int64, Fn: unary.AbsInt64,
			},
			{
				Index:     1,
				Flag:      plan.Function_STRICT,
				Layout:    STANDARD_FUNCTION,
				Args:      []types.T{types.T_uint64},
				ReturnTyp: types.T_uint64, Fn: unary.AbsUInt64,
			},
			{
				Index:     2,
				Flag:      plan.Function_STRICT,
				Layout:    STANDARD_FUNCTION,
				Args:      []types.T{types.T_float64},
				ReturnTyp: types.T_float64, Fn: unary.AbsFloat64,
			},
		},
	},
	ACOS: {
		Id: ACOS,
		Overloads: []Function{
			{
				Index:     0,
				Flag:      plan.Function_STRICT,
				Layout:    STANDARD_FUNCTION,