function

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Distinct     = 0x8000000000000000
	DistinctMask = 0x7FFFFFFFFFFFFFFF
)
View Source
const (
	EQUAL           = iota // =
	NOT_EQUAL              // <>
	GREAT_THAN             // >
	GREAT_EQUAL            // >=
	LESS_THAN              // <
	LESS_EQUAL             // <=
	BETWEEN                // BETWEEN
	UNARY_PLUS             // UNARY_PLUS
	UNARY_MINUS            // UNARY_MINUS
	PLUS                   // +
	MINUS                  // -
	MULTI                  // *
	DIV                    // /
	INTEGER_DIV            // Div
	BIT_SHIFT_LEFT         // <<
	BIT_SHIFT_RIGHT        // >>
	MOD                    // %
	CONCAT                 // ||
	AND                    // AND
	OR                     // OR
	XOR                    // XOR
	NOT                    // NOT
	CAST                   // CAST
	IS                     //IS
	ISNOT                  //ISNOT
	ISNULL                 //ISNULL
	ISNOTNULL              //ISNOTNULL

	ABS            // ABS
	ACOS           // ACOS
	ADDDATE        // ADDDATE
	ADDTIME        // ADDTIME
	AES_DECRYPT    // AES_DECRYPT
	AES_ENCRYPT    // AES_ENCRYPT
	ANY_VALUE      // ANY_VALUE
	ARRAY_AGG      // ARRAY_AGG
	ARRAY_APPEND   // ARRAY_APPEND
	ARRAY_CAT      // ARRAY_CAT
	ARRAY_CONTAINS // ARRAY_CONTAINS
	ARRAY_POSITION // ARRAY_POSITION
	ARRAY_SIZE     // ARRAY_SIZE
	ASCII          // ASCII
	ASIN           // ASIN
	ATAN           // ATAN
	ATAN2          // ATAN2
	AVG            // AVG
	BASE64_DECODE  // BASE64_DECODE
	BASE64_ENCODE  // BASE64_ENCODE
	BIT_AND        // BIT_AND
	BIT_LENGTH     // BIT_LENGTH
	BIT_NOT        // BIT_NOT
	BIT_OR         // BIT_OR
	BIT_XOR        // BIT_XOR
	BITAGG_AND     // BITAGG_AND
	BITAGG_OR      // BITAGG_OR
	BOOLAGG_AND    // BOOLAGG_AND
	BOOLAGG_OR     // BOOLAGG_OR
	CASE           // CASE
	CEIL           // CEIL
	CHR            // CHR
	COALESCE       // COALESCE
	CONCAT_WS
	CONTAINS          // CONTAINS
	CORR              // CORR
	COS               // COS
	COT               // COT
	COUNT             // COUNT
	COUNT_IF          // COUNT_IF
	COVAR_POP         // COVAR_POP
	COVAR_SAMPLE      // COVAR_SAMPLE
	CUME_DIST         // CUME_DIST
	CURRENT_DATE      // CURRENT_DATE
	CURRENT_TIMESTAMP // CURRENT_TIMESTAMP
	DATE_FROM_PARTS   // DATE_FROM_PARTS
	DATE_PART         // DATE_PART
	DATEADD           // DATEADD
	DATEDIFF          // DATEDIFF
	DENSE_RANK        // DENSE_RANK
	EMPTY
	ENDSWITH // ENDSWITH
	EXP      // EXP
	FINDINSET
	FIRST_VALUE // FIRST_VALUE
	FLOOR       // FLOOR
	GREATEST    // GREATEST
	GROUPING_ID // GROUPING_ID
	HASH        // HASH
	HASH_AGG    // HASH_AGG
	HEX_DECODE  // HEX_DECODE
	HEX_ENCODE  // HEX_ENCODE
	IFF         // IFF
	IFNULL      // IFNULL
	ILIKE       // ILIKE
	ILIKE_ALL   // ILIKE_ALL
	ILIKE_ANY   // ILIKE_ANY
	IN          // IN
	LAG         // LAG
	LAST_VALUE  // LAST_VALUE
	LEAD        // LEAD
	LEAST       // LEAST
	LEFT        // LEFT
	LENGTH      // LENGTH
	LENGTH_UTF8
	LIKE     // LIKE
	LIKE_ALL // LIKE_ALL
	LIKE_ANY // LIKE_ANY
	LN       // LN
	LOG      // LOG
	LOWER    // LOWER
	LPAD     // LPAD
	LTRIM    // LTRIM
	MAX      // MAX
	MEDIAN   // MEDIAN
	MIN      // MIN
	MODE     // MODE
	MONTH
	NORMAL         // NORMAL
	NTH_VALUE      // NTH_VALUE
	NTILE          // NTILE
	NULLIF         // NULLIF
	PERCENT_RANK   // PERCENT_RANK
	PI             // PI
	POSITION       // POSITION
	POW            // POW
	RADIAN         // RADIAN
	RANDOM         // RANDOM
	RANK           // RANK
	REGEXP         // REGEXP
	REGEXP_REPLACE // REGEXP_REPLACE
	REGEXP_SUBSTR  // REGEXP_SUBSTR
	REPEAT         // REPEAT
	REPLACE        // REPLACE
	REVERSE
	RIGHT      // RIGHT
	ROUND      // ROUND
	ROW_NUMBER // ROW_NUMBER
	RPAD       // RPAD
	RTRIM      // RTRIM
	SIGN       // SIGN
	SIN        // SIN
	SINH       //SINH
	SPACE
	SPLIT         // SPLIT
	STARCOUNT     // STARTCOUNT
	STARTSWITH    // STARTSWITH
	STDDEV_POP    // STDDEV_POP
	STDDEV_SAMPLE // STDDEV_SAMPLE
	SUBSTR        // SUBSTR
	SUM           // SUM
	TAN           // TAN
	TO_DATE
	TO_INTERVAL // TO_INTERVAL
	TRANSLATE   // TRANSLATE
	TRIM        // TRIM
	UNIFORM     // UNIFORM
	UTC_TIMESTAMP
	UNIX_TIMESTAMP
	FROM_UNIXTIME
	UPPER      // UPPER
	VAR_POP    // VAR_POP
	VAR_SAMPLE // VAR_SAMPLE

	EXISTS // EXISTS
	ALL    // ALL
	ANY    // ANY

	DATE      // DATE
	DAY       //DAY
	DAYOFYEAR // DAYOFYEAR
	INTERVAL  // INTERVAL
	EXTRACT   // EXTRACT
	OCT
	SUBSTRING // SUBSTRING
	WEEK      //WEEK
	WEEKDAY
	YEAR // YEAR

	DATE_ADD              // DATE_ADD
	DATE_SUB              // DATE_SUB
	APPROX_COUNT_DISTINCT // APPROX_COUNT_DISTINCT, special aggregate

	//information functions
	//Reference to : https://dev.mysql.com/doc/refman/8.0/en/information-functions.html
	DATABASE
	USER
	CONNECTION_ID
	CHARSET
	CURRENT_ROLE
	FOUND_ROWS
	ICULIBVERSION
	LAST_INSERT_ID
	ROLES_GRAPHML
	ROW_COUNT
	VERSION
	COLLATION

	TIMESTAMP // TIMESTAMP

	// FUNCTION_END_NUMBER is not a function, just a flag to record the max number of function.
	// TODO: every one should put the new function id in front of this one if you want to make a new function.
	FUNCTION_END_NUMBER
)

All function IDs

View Source
const (
	// ScalarNull means of scalar NULL
	// which can meet each required type.
	// e.g.
	// if we input a SQL `select built_in_function(columnA, NULL);`, and columnA is int64 column.
	// it will use [types.T_int64, ScalarNull] to match function when we were building the query plan.
	ScalarNull = types.T_any
)

Variables

View Source
var (
	// GeneralBinaryOperatorTypeCheckFn1 will check if params of the binary operators need type convert work
	GeneralBinaryOperatorTypeCheckFn1 = func(overloads []Function, inputs []types.T) (overloadIndex int32, ts []types.T) {
		return generalBinaryOperatorTypeCheckFn(overloads, inputs, generalBinaryParamsConvert)
	}

	// GeneralBinaryOperatorTypeCheckFn2 will check if params of the DIV and INTEGER_DIV need type convert work
	GeneralBinaryOperatorTypeCheckFn2 = func(overloads []Function, inputs []types.T) (overloadIndex int32, ts []types.T) {
		return generalBinaryOperatorTypeCheckFn(overloads, inputs, generalDivParamsConvert)
	}
)
View Source
var (

	// AndFunctionEncodedID is the encoded overload id of And(bool, bool)
	// used to make an AndExpr
	AndFunctionEncodedID = EncodeOverloadID(AND, 0)
)

Functions

func DecodeOverloadID

func DecodeOverloadID(overloadID int64) (fid int32, index int32)

DecodeOverloadID convert overload id to be function-id and overload-index

func EncodeOverloadID

func EncodeOverloadID(fid int32, index int32) (overloadID int64)

EncodeOverloadID convert function-id and overload-index to be an overloadID the high 32-bit is function-id, the low 32-bit is overload-index

func GetFunctionByName

func GetFunctionByName(name string, args []types.Type) (int64, types.Type, []types.Type, error)

GetFunctionByName check a function exist or not according to input function name and arg types, if matches, return the encoded overload id and the overload's return type and final converted argument types( it will be nil if there's no need to do type level-up work).

func GetFunctionIsAggregateByName

func GetFunctionIsAggregateByName(name string) bool

func GetFunctionIsWinfunByName

func GetFunctionIsWinfunByName(name string) bool

Types

type FuncExplainLayout

type FuncExplainLayout int32
const (
	STANDARD_FUNCTION          FuncExplainLayout = 0 //standard function
	UNARY_ARITHMETIC_OPERATOR  FuncExplainLayout = 1 //unary arithmetic operator
	BINARY_ARITHMETIC_OPERATOR FuncExplainLayout = 2 //binary arithmetic operator
	UNARY_LOGICAL_OPERATOR     FuncExplainLayout = 3 // unary logical operator
	BINARY_LOGICAL_OPERATOR    FuncExplainLayout = 4 // binary logical operator
	COMPARISON_OPERATOR        FuncExplainLayout = 5 // comparison operator
	CAST_EXPRESSION            FuncExplainLayout = 6 // cast expression
	CASE_WHEN_EXPRESSION       FuncExplainLayout = 7 // case when expression
	BETWEEN_AND_EXPRESSION     FuncExplainLayout = 8
	IN_PREDICATE               FuncExplainLayout = 9  //query 'in' predicate
	EXISTS_ANY_PREDICATE       FuncExplainLayout = 10 //query predicate,such as exist,all,any
	IS_NULL_EXPRESSION         FuncExplainLayout = 11 // is null expression
	NOPARAMETER_FUNCTION       FuncExplainLayout = 12 // noparameter function
	DATE_INTERVAL_EXPRESSION   FuncExplainLayout = 13 // date expression,interval expression
	EXTRACT_FUNCTION           FuncExplainLayout = 14 // extract function,such as extract(MONTH/DAY/HOUR/MINUTE/SECOND FROM p)
	POSITION_FUNCTION          FuncExplainLayout = 15 // position function, such as POSITION(substr IN str)
	UNKNOW_KIND_FUNCTION       FuncExplainLayout = 16
)

type Function

type Function struct {
	// Index is the function's location number of all the overloads with the same functionName.
	Index int32

	// Volatile function cannot be fold
	Volatile bool

	Flag plan.Function_FuncFlag

	// Layout adapt to plan/function.go, used for `explain SQL`.
	Layout FuncExplainLayout

	Args      []types.T
	ReturnTyp types.T

	// Fn is implementation of built-in function and operator
	// it received vector list, and return result vector.
	Fn func(vs []*vector.Vector, proc *process.Process) (*vector.Vector, error)

	// AggregateInfo is related information about aggregate function.
	AggregateInfo int

	// Info records information about the function overload used to print
	Info string
}

Function is an overload of a built-in function or an aggregate function or an operator

func GetFunctionByID

func GetFunctionByID(overloadID int64) (Function, error)

GetFunctionByID get function structure by its index id.

func (Function) IsAggregate

func (f Function) IsAggregate() bool

func (Function) ReturnType

func (f Function) ReturnType() (typ types.T, nullable bool)

ReturnType return result-type of function, and the result is nullable if nullable is false, function won't return a vector with null value.

func (Function) VecFn

func (f Function) VecFn(vs []*vector.Vector, proc *process.Process) (*vector.Vector, error)

type Functions

type Functions struct {
	Id int

	// TypeCheckFn checks if the input parameters can satisfy one of the overloads
	// and returns its index id.
	// if type convert should happen, return the target-types at the same time.
	TypeCheckFn func(overloads []Function, inputs []types.T) (overloadIndex int32, ts []types.T)

	Overloads []Function
}

Functions records all overloads of the same function name and its function-id and type-check-function

func (*Functions) TypeCheck

func (fs *Functions) TypeCheck(args []types.T) (int32, []types.T)

TypeCheck do type check work for a function, if the input params matched one of function's overloads. returns overload-index-number, target-type just set target-type nil if there is no need to do implicit-type-conversion for parameters

Directories

Path Synopsis
builtin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL