builtins

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Builtin functions are a library of functions natively available in qlbridge expression evaluation although adding your own is easy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterEval

func FilterEval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool)

func FilterMatchEval

func FilterMatchEval(ctx expr.EvalContext, vals []value.Value) (value.Value, bool)

func FiltersFromArgs

func FiltersFromArgs(filterVals []value.Value) []string

FilterFromArgs given set of values

func HostEval

func HostEval(ctx expr.EvalContext, args []value.Value) (value.Value, bool)

func HostsEval

func HostsEval(ctx expr.EvalContext, args []value.Value) (value.Value, bool)

func LoadAllBuiltins

func LoadAllBuiltins()

func UrlWithQueryEval

func UrlWithQueryEval(include []*regexp.Regexp) expr.EvaluatorFunc

UrlWithQueryEval pass reg-expressions to match qs args. Must match one regexp or else the qs param is dropped.

Types

type All

type All struct{}

All Answers True/False if all of the arguments evaluate to truish (javascripty) type definintion of true. Non-Nil, non-Error, values.

Rules for if True:

int != 0
string != ""
boolean natively supported true/false
time != time.IsZero()

Examples:

all("hello",2, true) => true
all("hello",0,true)  => false
all("",2, true)      => false

func (*All) Type

func (m *All) Type() value.ValueType

Type is BoolType for All function

func (*All) Validate

func (m *All) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Any

type Any struct{}

Any Answers True/False if any of the arguments evaluate to truish (javascripty) type definintion of true

Rules for if True:

int != 0
string != ""
boolean natively supported true/false
time != time.IsZero()

Examples:

any(item,item2)  => true, true
any(not_field)   => false, true

func (*Any) Type

func (m *Any) Type() value.ValueType

Type bool

func (*Any) Validate

func (m *Any) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ArrayIndex

type ArrayIndex struct{}

ArrayIndex array.index choose the nth element of an array

// given context input of
"items" = [1,2,3]

array.index(items, 1)     =>  1, true
array.index(items, 5)     =>  nil, false
array.index(items, -1)    =>  3, true

func (*ArrayIndex) Type

func (m *ArrayIndex) Type() value.ValueType

Type unknown - returns single value from SliceValue array

func (*ArrayIndex) Validate

func (m *ArrayIndex) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ArraySlice

type ArraySlice struct{}

array.slice slice element m -> n of a slice. First arg must be a slice.

// given context of
"items" = [1,2,3,4,5]

array.slice(items, 1, 3)     =>  [2,3], true
array.slice(items, 2)        =>  [3,4,5], true
array.slice(items, -2)       =>  [4,5], true

func (*ArraySlice) Type

func (m *ArraySlice) Type() value.ValueType

Type Unknown for Array Slice

func (*ArraySlice) Validate

func (m *ArraySlice) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

Validate must be at least 2 args, max of 3

type Avg

type Avg struct{}

Avg average of values. Note, this function DOES NOT persist state doesn't aggregate across multiple calls. That would be responsibility of write context.

avg(1,2,3) => 2.0, true
avg("hello") => math.NaN, false

func (*Avg) IsAgg

func (m *Avg) IsAgg() bool

func (*Avg) Type

func (m *Avg) Type() value.ValueType

Type is NumberType

func (*Avg) Validate

func (m *Avg) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Cast

type Cast struct{}

Cast type coercion, cast to an explicit type.

cast(identity AS <type>) => 5.0
cast(reg_date AS string) => "2014/01/12"

Types: [char, string, int, float]

func (*Cast) Type

func (m *Cast) Type() value.ValueType

Type one of value types

func (*Cast) Validate

func (m *Cast) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Contains

type Contains struct{}

Contains does first arg string contain 2nd arg?

contains("alabama","red") => false

func (*Contains) Type

func (m *Contains) Type() value.ValueType

Type is Bool

func (*Contains) Validate

func (m *Contains) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Count

type Count struct{}

Count Return int value 1 if non-nil/zero. This should be renamed Increment and in general is a horrible, horrible function that needs to be replaced with occurrences of value, ignores the value and ensures it is non null

count(anyvalue)     =>  1, true
count(not_number)   =>  -- 0, false

func (*Count) IsAgg

func (m *Count) IsAgg() bool

func (*Count) Type

func (m *Count) Type() value.ValueType

Type is Integer

func (*Count) Validate

func (m *Count) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type DayOfWeek

type DayOfWeek struct{}

DayOfWeek day of week [0-6]

dayofweek() => 3, true
dayofweek("2016/07/04") => 5, true

func (*DayOfWeek) Type

func (m *DayOfWeek) Type() value.ValueType

Type int

func (*DayOfWeek) Validate

func (m *DayOfWeek) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Domain

type Domain struct{}

Extract Domain from a Value, or Values (must be urlish), doesn't do much/any validation. if input is a list of strings, only first is evaluated, for plural see domains()

domain("http://www.lytics.io/index.html") =>  "lytics.io"

func (*Domain) Type

func (m *Domain) Type() value.ValueType

Type string

func (*Domain) Validate

func (m *Domain) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Domains

type Domains struct{}

Domains Extract Domains from a Value, or Values (must be urlish), doesn't do much/any validation

domains("http://www.lytics.io/index.html") =>  []string{"lytics.io"}

func (*Domains) Type

func (m *Domains) Type() value.ValueType

Type strings

func (*Domains) Validate

func (m *Domains) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Email

type Email struct{}

email a string, parses email and makes sure it is valid

email("Bob <bob@bob.com>")  =>  bob@bob.com, true
email("Bob <bob>")          =>  "", false

func (*Email) Type

func (m *Email) Type() value.ValueType

Type string

func (*Email) Validate

func (m *Email) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type EmailDomain

type EmailDomain struct{}

emaildomain parses email and returns domain

emaildomain("Bob <bob@bob.com>") =>  bob.com

func (*EmailDomain) Type

func (m *EmailDomain) Type() value.ValueType

Type string

func (*EmailDomain) Validate

func (m *EmailDomain) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type EmailName

type EmailName struct{}

emailname a string, parses email

emailname("Bob <bob@bob.com>") =>  Bob

func (*EmailName) Type

func (m *EmailName) Type() value.ValueType

Type string

func (*EmailName) Validate

func (m *EmailName) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type EncodeB64Decode

type EncodeB64Decode struct{}

Base 64 encoding function

encoding.b64decode("aGVsbG8gd29ybGQ=")  =>  "hello world"

func (*EncodeB64Decode) Type

func (m *EncodeB64Decode) Type() value.ValueType

Type string

func (*EncodeB64Decode) Validate

func (m *EncodeB64Decode) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type EncodeB64Encode

type EncodeB64Encode struct{}

Base 64 encoding function

encoding.b64encode("hello world=")  =>  aGVsbG8gd29ybGQ=

func (*EncodeB64Encode) Type

func (m *EncodeB64Encode) Type() value.ValueType

Type string

func (*EncodeB64Encode) Validate

func (m *EncodeB64Encode) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Eq

type Eq struct{}

Equal function? returns true if items are equal

// given context   {"name":"wil","event":"stuff", "int4": 4}

eq(int4,5)  => false

func (*Eq) Type

func (m *Eq) Type() value.ValueType

Type bool

func (*Eq) Validate

func (m *Eq) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Exists

type Exists struct{}

Exists Answers True/False if the field exists and is non null

exists(real_field) => true
exists("value") => true
exists("") => false
exists(empty_field) => false
exists(2) => true
exists(todate(date_field)) => true

func (*Exists) Type

func (m *Exists) Type() value.ValueType

Type bool

func (*Exists) Validate

func (m *Exists) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Filter

type Filter struct{}

Filter Filter OUT Values that match specified list of match filter criteria

Operates on MapValue (map[string]interface{}), StringsValue ([]string), or string takes N Filter Criteria supports Matching: "filter**" // matches "filter_x", "filterstuff"

Filter a map of values by key to remove certain keys

filter(match("topic_"),key_to_filter, key2_to_filter)  => {"goodkey": 22}, true

Filter out VALUES (not keys) from a list of []string{} for a specific value

filter(split("apples,oranges",","),"ora*")  => ["apples"], true

Filter out values for single strings

filter("apples","app*")      => []string{}, true

func (*Filter) Type

func (m *Filter) Type() value.ValueType

Type unknown

func (*Filter) Validate

func (m *Filter) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type FilterMatch

type FilterMatch struct{}

FilterMatch Filter IN Values that match specified list of match filter criteria

Operates on MapValue (map[string]interface{}), StringsValue ([]string), or string takes N Filter Criteria

Wildcard Matching: "abcd*" // matches "abcd_x", "abcdstuff"

Filter a map of values by key to only keep certain keys

filtermatch(match("topic_"),key_to_filter, key2_to_filter)  => {"goodkey": 22}, true

Filter in VALUES (not keys) from a list of []string{} for a specific value

filtermatch(split("apples,oranges",","),"ora*")  => ["oranges"], true

Filter in values for single strings

filtermatch("apples","app*")      => []string{"apple"}, true

func (*FilterMatch) Type

func (m *FilterMatch) Type() value.ValueType

Type Unknown

func (*FilterMatch) Validate

func (m *FilterMatch) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Ge

type Ge struct{}

Ge GreaterThan or Equal func. Must be able to convert items to Floats.

func (*Ge) Type

func (m *Ge) Type() value.ValueType

Type bool

func (*Ge) Validate

func (m *Ge) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Gt

type Gt struct{}

Gt GreaterThan is left hand > right hand. Must be able to convert items to Floats.

gt(5,6)  => true, true

func (*Gt) Type

func (m *Gt) Type() value.ValueType

Type bool

func (*Gt) Validate

func (m *Gt) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HasPrefix

type HasPrefix struct{}

HasPrefix string evaluation to see if string begins with

hasprefix("apples","ap")   => true
hasprefix("apples","o")   => false

func (*HasPrefix) Type

func (m *HasPrefix) Type() value.ValueType

Type bool

func (*HasPrefix) Validate

func (m *HasPrefix) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HasSuffix

type HasSuffix struct{}

HasSuffix string evaluation to see if string ends with

hassuffix("apples","es")   => true
hassuffix("apples","e")   => false

func (*HasSuffix) Type

func (m *HasSuffix) Type() value.ValueType

Type bool

func (*HasSuffix) Validate

func (m *HasSuffix) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HashMd5

type HashMd5 struct{}

HashMd5Func Hash a value to MD5 string

hash.md5("/blog/index.html")  =>  abc345xyz

func (*HashMd5) Type

func (m *HashMd5) Type() value.ValueType

Type string

func (*HashMd5) Validate

func (m *HashMd5) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HashSha1

type HashSha1 struct{}

HashSha1Func Hash a value to SHA256 string

hash.sha1("/blog/index.html")  =>  abc345xyz

func (*HashSha1) Type

func (m *HashSha1) Type() value.ValueType

Type string

func (*HashSha1) Validate

func (m *HashSha1) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HashSha256

type HashSha256 struct{}

HashSha256Func Hash a value to SHA256 string

hash.sha256("/blog/index.html")  =>  abc345xyz

func (*HashSha256) Type

func (m *HashSha256) Type() value.ValueType

Type string

func (*HashSha256) Validate

func (m *HashSha256) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HashSha512

type HashSha512 struct{}

HashSha512Func Hash a value to SHA512 string

hash.sha512("/blog/index.html")  =>  abc345xyz

func (*HashSha512) Type

func (m *HashSha512) Type() value.ValueType

Type string

func (*HashSha512) Validate

func (m *HashSha512) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HashSip

type HashSip struct{}

hash.sip() hash a value to a 64 bit int

hash.sip("/blog/index.html")  =>  1234

func (*HashSip) Type

func (m *HashSip) Type() value.ValueType

Type int

func (*HashSip) Validate

func (m *HashSip) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Host

type Host struct{}

Extract host from a String (must be urlish), doesn't do much/any validation In the event the value contains more than one input url, will ONLY evaluate first

host("http://www.lytics.io/index.html") =>  www.lytics.io

func (*Host) Type

func (m *Host) Type() value.ValueType

Type string

func (*Host) Validate

func (m *Host) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Hosts

type Hosts struct{}

Extract hosts from a Strings (must be urlish), doesn't do much/any validation

hosts("http://www.lytics.io", "http://www.activate.lytics.io") => www.lytics.io, www.activate.lytics.io

func (*Hosts) Type

func (m *Hosts) Type() value.ValueType

Type strings

func (*Hosts) Validate

func (m *Hosts) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HourOfDay

type HourOfDay struct{}

hourofday hour of day [0-23]

hourofday(field)
hourofday()  // Uses message time

func (*HourOfDay) Type

func (m *HourOfDay) Type() value.ValueType

Type integer

func (*HourOfDay) Validate

func (m *HourOfDay) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type HourOfWeek

type HourOfWeek struct{}

hour of week [0-167]

func (*HourOfWeek) Type

func (m *HourOfWeek) Type() value.ValueType

Type int

func (*HourOfWeek) Validate

func (m *HourOfWeek) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Join

type Join struct{}

Join items together (string concatenation)

join("apples","oranges",",")   => "apples,oranges"
join(["apples","oranges"],",") => "apples,oranges"
join("apples","oranges","")    => "applesoranges"

func (*Join) Type

func (m *Join) Type() value.ValueType

Type is string

func (*Join) Validate

func (m *Join) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type JsonPath

type JsonPath struct{}

JsonPath jmespath json parser http://jmespath.org/

json_field = `[{"name":"n1","ct":8,"b":true, "tags":["a","b"]},{"name":"n2","ct":10,"b": false, "tags":["a","b"]}]`

json.jmespath(json_field, "[?name == 'n1'].name | [0]")  =>  "n1"

func (*JsonPath) Type

func (m *JsonPath) Type() value.ValueType

func (*JsonPath) Validate

func (m *JsonPath) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Le

type Le struct{}

Le Less Than or Equal. Must be able to convert items to Floats.

func (*Le) Type

func (m *Le) Type() value.ValueType

Type bool

func (*Le) Validate

func (m *Le) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Length

type Length struct{}

len length of array types

len([1,2,3])     =>  3, true
len(not_a_field)   =>  -- NilInt, false

func (*Length) Type

func (m *Length) Type() value.ValueType

Type is IntType

func (*Length) Validate

func (m *Length) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type LowerCase

type LowerCase struct{}

LowerCase take a string and lowercase it. must be able to convert to string.

string.lowercase("HELLO") => "hello", true

func (*LowerCase) Type

func (m *LowerCase) Type() value.ValueType

Type string

func (*LowerCase) Validate

func (m *LowerCase) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Lt

type Lt struct{}

Lt Less Than Must be able to convert items to Floats

lt(5, 6)  => true

func (*Lt) Type

func (m *Lt) Type() value.ValueType

Type bool

func (*Lt) Validate

func (m *Lt) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type MapFunc

type MapFunc struct{}

Map Create a map from two values. If the right side value is nil then does not evaluate.

map(left, right)    => map[string]value{left:right}

func (*MapFunc) Type

func (m *MapFunc) Type() value.ValueType

Type is MapValueType

func (*MapFunc) Validate

func (m *MapFunc) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type MapInvert

type MapInvert struct{}

MapInvert: Take a map and invert key/values

// given input:
tags = {"1":"news","2":"sports"}

mapinvert(tags) => map[string]string{"news":"1","sports":"2"}

func (*MapInvert) Type

func (m *MapInvert) Type() value.ValueType

Type MapValue

func (*MapInvert) Validate

func (m *MapInvert) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type MapKeys

type MapKeys struct{}

MapKeys: Take a map and extract array of keys

//given input:
{"tag.1":"news","tag.2":"sports"}

mapkeys(match("tag.")) => []string{"news","sports"}

func (*MapKeys) Type

func (m *MapKeys) Type() value.ValueType

Type []string aka strings

func (*MapKeys) Validate

func (m *MapKeys) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type MapTime

type MapTime struct{}

MapTime() Create a map[string]time of each key

maptime(field)    => map[string]time{field_value:message_timestamp}
maptime(field, timestamp) => map[string]time{field_value:timestamp}

func (*MapTime) Type

func (m *MapTime) Type() value.ValueType

Type MapTime

func (*MapTime) Validate

func (m *MapTime) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type MapValues

type MapValues struct{}

MapValues: Take a map and extract array of values

// given input:
{"tag.1":"news","tag.2":"sports"}

mapvalue(match("tag.")) => []string{"1","2"}

func (*MapValues) Type

func (m *MapValues) Type() value.ValueType

Type strings aka []string

func (*MapValues) Validate

func (m *MapValues) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Match

type Match struct{}

Match a simple pattern match on KEYS (not values) and build a map of all matched values. Matched portion is replaced with empty string. - May pass as many match strings as you want. - Must match on Prefix of key.

given input context of:
   {"score_value":24,"event_click":true, "tag_apple": "apple", "label_orange": "orange"}

   match("score_") => {"value":24}
   match("amount_") => false
   match("event_") => {"click":true}
   match("label_","tag_") => {"apple":"apple","orange":"orange"}

func (*Match) Type

func (m *Match) Type() value.ValueType

Type is MapValueType

func (*Match) Validate

func (m *Match) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Mm

type Mm struct{}

mm Get month as integer from date

@optional timestamp (if not, gets from context reader)

mm()                =>  01, true  /// assuming message ts = jan 1
mm("2014-03-17")    =>  03, true

func (*Mm) Type

func (m *Mm) Type() value.ValueType

Type integer

func (*Mm) Validate

func (m *Mm) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Ne

type Ne struct{}

Ne Not Equal function? returns true if items are equal

// given   {"5s":"5","item4":4,"item4s":"4"}

ne(`5s`,5) => true, true
ne(`not_a_field`,5) => false, true
ne(`item4s`,5) => false, true
ne(`item4`,5) => false, true

func (*Ne) Type

func (m *Ne) Type() value.ValueType

Type bool

func (*Ne) Validate

func (m *Ne) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Not

type Not struct{}

Not urnary negation function

not(eq(5,5)) => false, true
not(eq("false")) => false, true

func (*Not) Type

func (m *Not) Type() value.ValueType

Type bool

func (*Not) Validate

func (m *Not) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Now

type Now struct{}

Now Get current time of Message (message time stamp) or else choose current server time if none is available in message context

func (*Now) Type

func (m *Now) Type() value.ValueType

Type time

func (*Now) Validate

func (m *Now) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type OneOf

type OneOf struct{}

OneOf choose the first non-nil, non-zero, non-false fields

oneof(nil, 0, "hello") => 'hello'

func (*OneOf) Type

func (m *OneOf) Type() value.ValueType

Type unknown

func (*OneOf) Validate

func (m *OneOf) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Pow

type Pow struct{}

Pow exponents, raise x to the power of y

pow(5,2)            =>  25, true
pow(3,2)            =>  9, true
pow(not_number,2)   =>  NilNumber, false

func (*Pow) Type

func (m *Pow) Type() value.ValueType

Type is Number

func (*Pow) Validate

func (m *Pow) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

Must have 2 arguments, both must be able to be coerced to Number

type Qs

type Qs struct{}

Qs Extract qs param from a string (must be url valid)

qs("http://www.lytics.io/?utm_source=google","utm_source")  => "google", true

func (*Qs) Type

func (m *Qs) Type() value.ValueType

Type string

func (*Qs) Validate

func (m *Qs) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type QsDeprecate

type QsDeprecate struct{}

Qs Extract qs param from a string (must be url valid)

qs("http://www.lytics.io/?utm_source=google","utm_source")  => "google", true

func (*QsDeprecate) Type

func (m *QsDeprecate) Type() value.ValueType

Type string

func (*QsDeprecate) Validate

func (m *QsDeprecate) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Replace

type Replace struct{}

Replace a string(s). Replace occurences of 2nd arg In first with 3rd. 3rd arg "what to replace with" is optional

replace("/blog/index.html", "/blog","")  =>  /index.html
replace("/blog/index.html", "/blog")  =>  /index.html
replace("/blog/index.html", "/blog/archive/","/blog")  =>  /blog/index.html
replace(item, "M")

func (*Replace) Type

func (m *Replace) Type() value.ValueType

func (*Replace) Validate

func (m *Replace) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Split

type Split struct{}

Split a string with given separator

split("apples,oranges", ",") => []string{"apples","oranges"}

func (*Split) Type

func (m *Split) Type() value.ValueType

Type is Strings

func (*Split) Validate

func (m *Split) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Sqrt

type Sqrt struct{}

Sqrt square root function. Must be able to coerce to number.

sqrt(4)            =>  2, true
sqrt(9)            =>  3, true
sqrt(not_number)   =>  0, false

func (*Sqrt) Type

func (m *Sqrt) Type() value.ValueType

Type is NumberType

func (*Sqrt) Validate

func (m *Sqrt) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

Validate Must have 1 arg

type StrFromTime

type StrFromTime struct{}

StrFromTime extraces certain parts from a time, similar to Python's StrfTime See http://strftime.org/ for Strftime directives.

strftime("2015/07/04", "%B")      => "July"
strftime("2015/07/04", "%B:%d")   => "July:4"
strftime("1257894000", "%p")      => "PM"

func (*StrFromTime) Type

func (m *StrFromTime) Type() value.ValueType

Type string

func (*StrFromTime) Validate

func (m *StrFromTime) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type StringIndex

type StringIndex struct{}

StringIndex a string, removing leading/trailing whitespace

string.index("apples, oranges ", ",") => 6
string.index("apples, oranges ", "X") => -1, false

func (*StringIndex) Type

func (m *StringIndex) Type() value.ValueType

func (*StringIndex) Validate

func (m *StringIndex) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Strip

type Strip struct{}

Strip a string, removing leading/trailing whitespace

strip(split("apples, oranges ",",")) => {"apples", "oranges"}
strip("apples ")                     => "apples"

func (*Strip) Type

func (m *Strip) Type() value.ValueType

type is Unknown (string, or []string)

func (*Strip) Validate

func (m *Strip) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type SubString

type SubString struct{}

SubString from a given string, use integers to describe the start, [stop] of substring to extract.

string.substr("apples, oranges ", 0, 3) => "app", true
string.substr("apple", 3)               => "le", true
string.substr("apple", 30, 500)         => nil, false

func (*SubString) Type

func (m *SubString) Type() value.ValueType

func (*SubString) Validate

func (m *SubString) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Sum

type Sum struct{}

Sum function to add values. Note, this function DOES NOT persist state doesn't aggregate across multiple calls. That would be responsibility of write context.

sum(1, 2, 3) => 6
sum(1, "horse", 3) => nan, false

func (*Sum) IsAgg

func (m *Sum) IsAgg() bool

IsAgg yes sum is an agg.

func (*Sum) Type

func (m *Sum) Type() value.ValueType

Type is number

func (*Sum) Validate

func (m *Sum) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type TimeSeconds

type TimeSeconds struct{}

TimeSeconds time in Seconds, parses a variety of formats looking for seconds See github.com/araddon/dateparse for formats supported on date parsing

seconds("M10:30")      =>  630
seconds("M100:30")     =>  6030
seconds("00:30")       =>  30
seconds("30")          =>  30
seconds(30)            =>  30
seconds("2015/07/04")  =>  1435968000

func (*TimeSeconds) Type

func (m *TimeSeconds) Type() value.ValueType

Type number

func (*TimeSeconds) Validate

func (m *TimeSeconds) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type TimeTrunc

type TimeTrunc struct {
	// contains filtered or unexported fields
}

UnixDateTruncFunc converts a value.Value to a unix timestamp string. This is used for the BigQuery export since value.TimeValue returns a unix timestamp with milliseconds (ie "1438445529707") by default. This gets displayed in BigQuery as "47547-01-24 10:49:05 UTC", because they expect seconds instead of milliseconds. This function "truncates" the unix timestamp to seconds to the form "1438445529.707" i.e the milliseconds are placed after the decimal place. Inspired by the "DATE_TRUNC" function used in PostgresQL and RedShift: http://www.postgresql.org/docs/8.1/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

unixtrunc("1438445529707") --> "1438445529"
unixtrunc("1438445529707", "seconds") --> "1438445529.707"
unixtrunc("1438445529707123456", "secondsmicro") --> "1438445529.707123"

func (*TimeTrunc) Type

func (m *TimeTrunc) Type() value.ValueType

Type string

func (*TimeTrunc) Validate

func (m *TimeTrunc) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type TitleCase

type TitleCase struct{}

TitleCase take a string and uppercase it. must be able to convert to string.

string.uppercase("hello") => "HELLO", true

func (*TitleCase) Type

func (m *TitleCase) Type() value.ValueType

Type string

func (*TitleCase) Validate

func (m *TitleCase) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToBool

type ToBool struct{}

ToBool cast as boolean

func (*ToBool) Type

func (m *ToBool) Type() value.ValueType

Type bool

func (*ToBool) Validate

func (m *ToBool) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToDate

type ToDate struct{}

todate: convert to Date

// uses lytics/datemath
todate("now-3m")

// uses araddon/dateparse util to recognize formats
todate(field)

// first parameter is the layout/format
todate("01/02/2006", field )

func (*ToDate) Type

func (m *ToDate) Type() value.ValueType

Type time

func (*ToDate) Validate

func (m *ToDate) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToDateIn

type ToDateIn struct{}

todatein: convert to Date with timezon

// uses lytics/datemath
todate("now-3m", "America/Los_Angeles")

// uses araddon/dateparse util to recognize formats
todate(field, "America/Los_Angeles")

func (*ToDateIn) Type

func (m *ToDateIn) Type() value.ValueType

Type time

func (*ToDateIn) Validate

func (m *ToDateIn) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToInt

type ToInt struct{}

ToInt Convert to Integer: Best attempt at converting to integer.

toint("5")          => 5, true
toint("5.75")       => 5, true
toint("5,555")      => 5555, true
toint("$5")         => 5, true
toint("5,555.00")   => 5555, true

func (*ToInt) Type

func (m *ToInt) Type() value.ValueType

Type integer

func (*ToInt) Validate

func (m *ToInt) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToNumber

type ToNumber struct{}

ToNumber Convert to Number: Best attempt at converting to integer

tonumber("5") => 5.0
tonumber("5.75") => 5.75
tonumber("5,555") => 5555
tonumber("$5") => 5.00
tonumber("5,555.00") => 5555

func (*ToNumber) Type

func (m *ToNumber) Type() value.ValueType

Type number

func (*ToNumber) Validate

func (m *ToNumber) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToString

type ToString struct{}

ToString cast as string. must be able to convert to string

func (*ToString) Type

func (m *ToString) Type() value.ValueType

Type string

func (*ToString) Validate

func (m *ToString) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type ToTimestamp

type ToTimestamp struct{}

totimestamp: convert to date, then to unix Seconds

totimestamp() => int, true
totimestamp("Apr 7, 2014 4:58:55 PM") => 1396889935

func (*ToTimestamp) Type

func (m *ToTimestamp) Type() value.ValueType

Type integer

func (*ToTimestamp) Validate

func (m *ToTimestamp) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Unsign

type Unsign struct{}

Unsign converts a signed int to an unsigned int represented as a string for positive numbers this should simply convert the number to a string for negative numbers, converting to a uint adds the negative value to the max uint value (18446744073709551615).

unsign(-32847623329847) => 18446711226086221769
unsign(876) => 876
unsign("-70") => 18446744073709551546

func (*Unsign) Type

func (u *Unsign) Type() value.ValueType

Type number

func (*Unsign) Validate

func (u *Unsign) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UpperCase

type UpperCase struct{}

UpperCase take a string and uppercase it. must be able to convert to string.

string.uppercase("hello") => "HELLO", true

func (*UpperCase) Type

func (m *UpperCase) Type() value.ValueType

Type string

func (*UpperCase) Validate

func (m *UpperCase) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UrlDecode

type UrlDecode struct{}

url decode a string

urldecode("http://www.lytics.io/index.html") =>  http://www.lytics.io

In the event the value contains more than one input url, will ONLY evaluate first

func (*UrlDecode) Type

func (m *UrlDecode) Type() value.ValueType

Type string

func (*UrlDecode) Validate

func (m *UrlDecode) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UrlMain

type UrlMain struct{}

UrlMain remove the querystring and scheme from url

urlmain("http://www.lytics.io/?utm_source=google")  => "www.lytics.io/", true

func (*UrlMain) Type

func (m *UrlMain) Type() value.ValueType

Type string

func (*UrlMain) Validate

func (m *UrlMain) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UrlMinusQs

type UrlMinusQs struct{}

UrlMinusQs removes a specific query parameter and its value from a url

urlminusqs("http://www.lytics.io/?q1=google&q2=123", "q1") => "http://www.lytics.io/?q2=123", true

func (*UrlMinusQs) Type

func (m *UrlMinusQs) Type() value.ValueType

Type string

func (*UrlMinusQs) Validate

func (m *UrlMinusQs) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UrlPath

type UrlPath struct{}

UrlPath Extract url path from a String (must be urlish), doesn't do much/any validation

path("http://www.lytics.io/blog/index.html") =>  blog/index.html

In the event the value contains more than one input url, will ONLY evaluate first

func (*UrlPath) Type

func (m *UrlPath) Type() value.ValueType

Type string

func (*UrlPath) Validate

func (m *UrlPath) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UrlWithQuery

type UrlWithQuery struct{}

UrlWithQueryFunc strips a url and retains only url parameters that match the supplied regular expressions.

url.matchqs(url, re1, re2, ...)  => url_withoutqs

func (*UrlWithQuery) Type

func (m *UrlWithQuery) Type() value.ValueType

Type string

func (*UrlWithQuery) Validate

func (*UrlWithQuery) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UserAgent

type UserAgent struct{}

UserAgent Extract user agent features

useragent(user_agent_field,"mobile")  => "true", true

func (*UserAgent) Type

func (m *UserAgent) Type() value.ValueType

Type string

func (*UserAgent) Validate

func (m *UserAgent) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UserAgentMap

type UserAgentMap struct{}

UserAgentMap Extract user agent features

useragent.map(user_agent_field)  => {"mobile": "false","platform":"X11"}, true

func (*UserAgentMap) Type

func (m *UserAgentMap) Type() value.ValueType

Type MapString

func (*UserAgentMap) Validate

func (m *UserAgentMap) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type UuidGenerate

type UuidGenerate struct{}

uuid generates a new uuid

uuid() =>  "...."

func (*UuidGenerate) Type

func (m *UuidGenerate) Type() value.ValueType

Type string

func (*UuidGenerate) Validate

func (m *UuidGenerate) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type Yy

type Yy struct{}

Yy Get year in integer from field, must be able to convert to date

yy()                 =>  15, true    // assuming it is 2015
yy("2014-03-01")     =>  14, true

func (*Yy) Type

func (m *Yy) Type() value.ValueType

Type integer

func (*Yy) Validate

func (m *Yy) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

type YyMm

type YyMm struct{}

yymm convert date to 4 digit string from argument if supplied, else uses message context ts

yymm() => "1707", true
yymm("2016/07/04") => "1607", true

func (*YyMm) Type

func (m *YyMm) Type() value.ValueType

Type string

func (*YyMm) Validate

func (m *YyMm) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error)

Jump to

Keyboard shortcuts

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