builtins

package
v0.0.0-...-c484601 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFunc

func AllFunc(ctx expr.EvalContext, vals ...value.Value) (value.BoolValue, bool)

All: Answers True/False if all of the arguments evaluate to truish (javascripty)

  type definintion of true

int > 0 = true
string != "" = true
boolean natively supported true/false

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

func AnyFunc

func AnyFunc(ctx expr.EvalContext, vals ...value.Value) (value.BoolValue, bool)

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

  type definintion of true

int > 0 = true
string != "" = true

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

func ContainsFunc

func ContainsFunc(ctx expr.EvalContext, lv, rv value.Value) (value.BoolValue, bool)

String contains

Will first convert to string, so may get unexpected results

func CountFunc

func CountFunc(ctx expr.EvalContext, val value.Value) (value.IntValue, bool)

Count: count occurences of value, ignores the value and ensures it is non null

count(anyvalue)     =>  1, true
count(not_number)   =>  -- Could not be evaluated

func DayOfWeek

func DayOfWeek(ctx expr.EvalContext, items ...value.Value) (value.IntValue, bool)

day of week [0-6]

func EmailDomainFunc

func EmailDomainFunc(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

email a string, parses email

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

func EmailFunc

func EmailFunc(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

email a string, parses email

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

func EmailNameFunc

func EmailNameFunc(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

emailname a string, parses email

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

func Eq

func Eq(ctx expr.EvalContext, itemA, itemB value.Value) (value.BoolValue, bool)

Equal function? returns true if items are equal

eq(item,5)

func Exists

func Exists(ctx expr.EvalContext, item interface{}) (value.BoolValue, bool)

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 Ge

func Ge(ctx expr.EvalContext, lv, rv value.Value) (value.BoolValue, bool)

>= GreaterThan or Equal

Must be able to convert items to Floats or else not ok

func Gt

func Gt(ctx expr.EvalContext, lv, rv value.Value) (value.BoolValue, bool)

> GreaterThan

Must be able to convert items to Floats or else not ok

func HostFunc

func HostFunc(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

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

host("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 HourOfDay

func HourOfDay(ctx expr.EvalContext, items ...value.Value) (value.IntValue, bool)

hour of day [0-23]

func HourOfWeek

func HourOfWeek(ctx expr.EvalContext, items ...value.Value) (value.IntValue, bool)

hour of week [0-167]

func JoinFunc

func JoinFunc(ctx expr.EvalContext, items ...value.Value) (value.StringValue, bool)

Join items together (string concatenation)

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

func LeFunc

func LeFunc(ctx expr.EvalContext, lv, rv value.Value) (value.BoolValue, bool)

<= Less Than or Equal

Must be able to convert items to Floats or else not ok

func LoadAllBuiltins

func LoadAllBuiltins()

func Lower

func Lower(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

String lower function

must be able to convert to string

func LtFunc

func LtFunc(ctx expr.EvalContext, lv, rv value.Value) (value.BoolValue, bool)

< Less Than

Must be able to convert items to Floats or else not ok

func MapFunc

func MapFunc(ctx expr.EvalContext, lv, rv value.Value) (value.MapValue, bool)

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 Match

func Match(ctx expr.EvalContext, items ...value.Value) (value.MapValue, bool)

match: Match a simple pattern match and return matched value

given input:
    {"score_value":24,"event_click":true}

   match("score_") => {"value":24}
   match("amount_") => false
   match("event_") => {"click":true}

func Mm

func Mm(ctx expr.EvalContext, items ...value.Value) (value.IntValue, bool)

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 Ne

func Ne(ctx expr.EvalContext, itemA, itemB value.Value) (value.BoolValue, bool)

Not Equal function? returns true if items are equal

ne(item,5)

func NotFunc

func NotFunc(ctx expr.EvalContext, item value.Value) (value.BoolValue, bool)

Not: urnary negation function

eq(item,5)

func Now

func Now(ctx expr.EvalContext, items ...value.Value) (value.TimeValue, bool)

Get current time of Message (message time stamp) or else choose current

server time if none is available in message context

func OneOfFunc

func OneOfFunc(ctx expr.EvalContext, vals ...value.Value) (value.Value, bool)

choose OneOf these fields, first non-null

func PowFunc

func PowFunc(ctx expr.EvalContext, val, toPower value.Value) (value.NumberValue, bool)

Pow: exponents, raise x to the power of y

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

func Qs

func Qs(ctx expr.EvalContext, urlItem, keyItem value.Value) (value.StringValue, bool)

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

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

func Replace

func Replace(ctx expr.EvalContext, vals ...value.Value) (value.StringValue, bool)

Replace a string(s), accepts any number of parameters to replace

replaces with ""

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

func SplitFunc

func SplitFunc(ctx expr.EvalContext, input value.Value, splitByV value.StringValue) (value.StringsValue, bool)

Split a string, accepts an optional with parameter

split(item, ",")

func SqrtFunc

func SqrtFunc(ctx expr.EvalContext, val value.Value) (value.NumberValue, bool)

Sqrt

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

func TimeExtractFunc

func TimeExtractFunc(ctx expr.EvalContext, items ...value.Value) (value.StringValue, bool)

func TimeSeconds

func TimeSeconds(ctx expr.EvalContext, val value.Value) (value.NumberValue, bool)

func ToDate

func ToDate(ctx expr.EvalContext, items ...value.Value) (value.TimeValue, bool)

todate: convert to Date

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

todate("01/02/2006", field )  uses golang date parse rules
   first parameter is the layout/format

func ToInt

func ToInt(ctx expr.EvalContext, item value.Value) (value.IntValue, bool)

Convert to Integer: Best attempt at converting to integer

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

func ToNumber

func ToNumber(ctx expr.EvalContext, item value.Value) (value.NumberValue, bool)

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 ToTimestamp

func ToTimestamp(ctx expr.EvalContext, item value.Value) (value.IntValue, bool)

totimestamp: convert to date, then to unix Seconds

func UrlDecode

func UrlDecode(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

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 UrlMain

func UrlMain(ctx expr.EvalContext, urlItem value.Value) (value.StringValue, bool)

urlmain remove the querystring and scheme from url

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

func UrlMinusQs

func UrlMinusQs(ctx expr.EvalContext, urlItem, keyItem value.Value) (value.StringValue, bool)

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 UrlPath

func UrlPath(ctx expr.EvalContext, item value.Value) (value.StringValue, bool)

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 UuidGenerate

func UuidGenerate(ctx expr.EvalContext) (value.StringValue, bool)

uuid generates a uuid

func Yy

func Yy(ctx expr.EvalContext, items ...value.Value) (value.IntValue, bool)

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 YyMm

func YyMm(ctx expr.EvalContext, items ...value.Value) (value.StringValue, bool)

Get yymm in 4 digits from argument if supplied, else uses message context ts

Types

This section is empty.

Jump to

Keyboard shortcuts

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