您的位置:首页 > 其它

SODBASE CEP学习(十三):EPL常用函数

2016-01-21 21:10 351 查看
本节介绍一下EPL中常用到的自带函数,用户也可以直接在EPL中调用Java自定义函数。

1. 时间类函数

(1)unix_timestamp

获取距离1970年1月1日后的毫秒数,例如

SELECT unix_timestamp()  输出1453381554400

SELECT unix_timestamp('2008-08-01 10:00:00')

(2)获取当前时间戳now

例如:SELECT now()  输出 2012-08-01 10:00:00

(3)date_format()

例如:获取昨天的日期

SELECT date_format((unix_timestamp(now())-86400000),'yyyy-MM-dd')

2. 字符串类函数

(1) 子字符串substring(str,pos,len)

例如:SELECT substring('hello','0','2')  输出 he

(2)字符串连接 concat

例如:SELECT concat('a','b') 输出ab

(3)字符串包含 contains

例如:SELECT contains('abcd','bc') 输出 true

(4)字符串替换

例如:SELECT replace('abcd','ab','bc') 输出 bccd

(5)正则匹配

例如:SELECT matches('aaaaab','a*b') 输出 true

3. 类型转换类函数

(1)字符串转数字 atoi(str)

例如: 在条件中判断大于8点

WHERE atoi(date_format(T1._start_time_,'HH'))>8

4. Kleen Closure中的聚合函数

(1)sum(class.attribute)     求和

(2)average(class.attribute) 求平均值

(3)tostring(class.attribute) 聚合为一个字符串

(4)count(class.attribute)   计数

(5)first(class.attribute)   取第一个值

(6)countdistinct(class.attribute) 去重计数

(7)tostringdistinct(class.attribute)    去重聚合为一个字符串   

(8)max(class.attribute)     求最大值

(9)min(class.attribute)     求最小值

5. 寄存器类函数

(1)autoincrement('name','initialvalue')   自动计数
(2)clearincrement('name')          清除计数器
(3)set('name','value')         设置寄存器
(4)get('name')         取寄存器值
例:
CREATE QUERY onbatchinput 

SELECT T1.price AS price,T1.name AS name,autoincrement('onbatch.inc1','0') AS _end_time_,T1._end_time_ AS timestamp,'data' AS type 

FROM T1:stock 

PATTERN T1 

WITHIN 0 

6. 布尔函数

expr1、expr2为不包含'AND'的逻辑表达式
(1)and(expr1,expr2)     与
(2)or(expr1,expr2)      或
(3)xor(expr1,expr2)     异或
布尔函数可以嵌套,如or(and(T1.a<30,T1.b='foo'),and(T1.a1>1,T1.b='bar')), and(true,T1.b='foo')

7. 数学函数

一些是系统自带的Java函数,arg1、arg2都是字符串类型
整数除法 JAVASTATIC:f.Math:i_divide(arg1,arg2)  

例如:JAVASTATIC:f.Math:i_divide('621','50') 结果为 12

三角函数JAVASTATIC:f.Math:sin(arg1) JAVASTATIC:f.Math:cos(arg1) JAVASTATIC:f.Math:tan(arg1)
反三角函数JAVASTATIC:f.Math:asin(arg1) JAVASTATIC:f.Math:acos(arg1) JAVASTATIC:f.Math:atan(arg1)
最大值 JAVASTATIC:f.Math:max(arg1,arg2)
最小值 JAVASTATIC:f.Math:min(arg1,arg2)

绝对值 JAVASTATIC:f.Math:abs(arg1)
指数 JAVASTATIC:f.Math:pow(arg1)

圆周率 JAVASTATIC:f.Math:PI()

自然对数的基 JAVASTATIC:f.Math:E()

8. 数组最大最小值

如果以逗号分隔的字符串表示数组,可以用系统带的f.Top类来实现最大最小值相关操作

JAVASTATIC:f.Top:getByIndex(arg1,arg2)
例 JAVASTATIC:f.Top:getByIndex('[h,x,j]','2') 结果是j
JAVASTATIC:f.Top:getByIndex('h,x,j','2') 结果是j
JAVASTATIC:f.Top:getByIndex('[h,x,j]','0') 结果是h

JAVASTATIC:f.Top:indexOfMax(arg1)
例 JAVASTATIC:f.Top:indexOfMax('[1,1,2]') 结果是2

JAVASTATIC:f.Top:max(arg1)

例 JAVASTATIC:f.Top:max('10,1,2,7') 结果是10

JAVASTATIC:f.Top:min(arg1)

例 JAVASTATIC:f.Top:min('10,1,2,7') 结果是1

9.条件函数

expr为不包含'AND'的逻辑表达式,ret1、ret2是字符串。expr为真时返回ret1 否则返回ret2。
ifthenelse(expr,ret1,ret2)

10. XML解析函数

JAVASTATIC:xml.XML:xpath(arg1,arg2)

其中arg1是XML字符串,arg2是xpath表达式
例 JAVASTATIC:xml.XML:xpath('<root><t1><t2>bar</t2></t1></root>','//t2/text()') 结果是bar

11. 加密函数

JAVA:f.Security:MD5(arg1)

生成arg1的MD5哈希值
JAVA:f.Security:SHA1(arg1)

生成arg1的SHA1加密值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: