github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/sql/util/udfRegister.go (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package util
    16  
    17  const (
    18  	// NumericBucketTypeBucketWidth is a NumericBucketType
    19  	NumericBucketTypeBucketWidth = "bucketWidth"
    20  	// NumericBucketTypeLogBase is a NumericBucketType
    21  	NumericBucketTypeLogBase = "logBase"
    22  	// NumericBucketTypeManualPartitions is a NumericBucketType
    23  	NumericBucketTypeManualPartitions = "manualPartitions"
    24  )
    25  
    26  type funcType int
    27  
    28  const (
    29  	// Timefilter is function type
    30  	Timefilter funcType = iota
    31  	// TimeNow is function type
    32  	TimeNow
    33  	// Timebucket is function type
    34  	Timebucket
    35  	// Numericbucket is function type
    36  	Numericbucket
    37  )
    38  
    39  type funcDef struct {
    40  	// Type is function type
    41  	Type funcType
    42  	// ArgsNum is #args
    43  	ArgsNum int
    44  	// Definition is the function's AQL expression
    45  	Definition string
    46  	// ArgsName is the args name
    47  	ArgsName []string
    48  }
    49  
    50  // UdfTable is function registration table. key: function name; value: function definition.
    51  var UdfTable = map[string]funcDef{
    52  	// Timefilter function table. "functionName":#args
    53  	"aql_time_filter": {Timefilter, 4, "timeFilter", []string{"column", "from", "to", "timezone"}},
    54  
    55  	// now => AQL query field Now which will override to=now field
    56  	"aql_now": {TimeNow, 2, "now", []string{"column", "now"}},
    57  
    58  	// Timebucketizer function table. "functionName":#args
    59  	// Supported timeUnit: "millisecond", "second", "minute", "hour"
    60  	// ISO-8601 date formats is returned if timeunit is set as ''
    61  	// AQL time_bucketizer detailed information can be found at https://code.uberinternal.com/w/projects/database/ares/aql/time_bucketizer/
    62  	"aql_time_bucket_minute":          {Timebucket, 3, "minute", []string{"column", "timeunit", "timezone"}},
    63  	"aql_time_bucket_minutes":         {Timebucket, 3, "minutes", []string{"column", "timeunit", "timezone"}},
    64  	"aql_time_bucket_hour":            {Timebucket, 3, "hour", []string{"column", "timeunit", "timezone"}},
    65  	"aql_time_bucket_hours":           {Timebucket, 3, "hours", []string{"column", "timeunit", "timezone"}},
    66  	"aql_time_bucket_day":             {Timebucket, 3, "day", []string{"column", "timeunit", "timezone"}},
    67  	"aql_time_bucket_week":            {Timebucket, 3, "week", []string{"column", "timeunit", "timezone"}},
    68  	"aql_time_bucket_month":           {Timebucket, 3, "month", []string{"column", "timeunit", "timezone"}},
    69  	"aql_time_bucket_quarter":         {Timebucket, 3, "quarter", []string{"column", "timeunit", "timezone"}},
    70  	"aql_time_bucket_year":            {Timebucket, 3, "year", []string{"column", "timeunit", "timezone"}},
    71  	"aql_time_bucket_time_of_day":     {Timebucket, 3, "time of day", []string{"column", "timeunit", "timezone"}},
    72  	"aql_time_bucket_minutes_of_day":  {Timebucket, 3, "minutes of day", []string{"column", "timeunit", "timezone"}},
    73  	"aql_time_bucket_hour_of_day":     {Timebucket, 3, "hour of day", []string{"column", "timeunit", "timezone"}},
    74  	"aql_time_bucket_hour_of_week":    {Timebucket, 3, "hour of week", []string{"column", "timeunit", "timezone"}},
    75  	"aql_time_bucket_day_of_week":     {Timebucket, 3, "day of week", []string{"column", "timeunit", "timezone"}},
    76  	"aql_time_bucket_day_of_month":    {Timebucket, 3, "day of month", []string{"column", "timeunit", "timezone"}},
    77  	"aql_time_bucket_day_of_year":     {Timebucket, 3, "day of year", []string{"column", "timeunit", "timezone"}},
    78  	"aql_time_bucket_month_of_year":   {Timebucket, 3, "month of year", []string{"column", "timeunit", "timezone"}},
    79  	"aql_time_bucket_quarter_of_year": {Timebucket, 3, "quarter of year", []string{"column", "timeunit", "timezone"}},
    80  
    81  	// Numericbucketizer function table. "functionName":#args
    82  	"aql_numeric_bucket_bucket_width":       {Numericbucket, 2, "bucketWidth", []string{"column", "expression"}},
    83  	"aql_numeric_bucket_logbase":            {Numericbucket, 2, "logBase", []string{"column", "expression"}},
    84  	"aql_numeric_bucket_mannual_partitions": {Numericbucket, 2, "mannualPartitions", []string{"column", "expression"}},
    85  }
    86  
    87  // AggregateFunctions is a set of call names that are aggregate functions
    88  var AggregateFunctions = map[string]bool{
    89  	"count": true,
    90  	"sum":   true,
    91  	"avg":   true,
    92  	"max":   true,
    93  	"min":   true,
    94  	"hll":   true,
    95  }