说明:spl是esproc采用的脚本语言,dfx为脚本文件,相当于外置存储过程,报表通过jdbc接口传入spl语句实现结构化计算或执行脚本。
1 | select max(continuousdays)-1 |
2 | from (select count(*) continuousdays |
3 | from (select sum(changesign) over(order by tradedate) unrisedays |
4 | from (select tradedate, |
5 | case when closeprice>lag(closeprice) over(order by tradedate) |
6 | then 0 else 1 end changesign |
7 | from stock) ) |
8 | group by unrisedays) |
思考:按照自然思维怎么做?!
a | |
---|---|
1 | =stock.sort(tradedate) |
2 | =0 |
3 | =a1.max(a2=if(closeprice>closeprice[-1],a2 1,0)) |
语法体系更容易描述人的自然思维!
采用存储过程实现数据准备算法,会造成报表与数据库的耦合问题
根据参数动态切换数据库
${pds}.query("select * from t where f=?",pf)
动态生成算法,动态拼接sql
a | b | |
---|---|---|
1 | =sums.array().("sum(" ~ ") as " ~).string() | /把a,b变成sum(a) as a,sum(b) as b |
2 | =db.query("select g," a1 " from t group by g") |
结果集容量控制
a | b | c | |
---|---|---|---|
1 | =db.cursor("select * from t") | =a1.fetch(1000) | |
2 | if b1.fetch@0(1) | >b1.insert(0,"继续") | /未完成则插入标记 |
3 | >a1.close() | return b1 |
数据库jdbc性能较差,报表性能又严重依赖于取数环节;集算器可以采用多线程并行的方式同时建立多个数据库连接从数据库分段取数,可以获得数倍性能提升
a | b | c | |
---|---|---|---|
1 | fork 4 | =connect(db) | /分4线程,要分别建立连接 |
2 | =b1.query@x("select * from t where part=?",a1) | /分别取每一段 | |
3 | =a1.conj() | /合并结果 |
... connection con = null; class.forname("com.esproc.jdbc.internaldriver"); con= drivermanager.getconnection("jdbc:esproc:local://"); // calling stored procedures ,countname is the file name of dfx st =(com. esproc.jdbc.internalcstatement)con.preparecall("call countname()"); // execute stored procedures st.execute(); //get result set resultset rs = st.getresultset(); ...
... connection con = null; class.forname("com.esproc.jdbc.internaldriver"); con= drivermanager.getconnection("jdbc:esproc:local://"); // calling stored procedures ,countname is the file name of dfx st =(com. esproc.jdbc.internalcstatement)con.createstatement(); //query files using sql,get result set resultset rs = st.executequery("$select name,count(*) from /home/user/duty.txt group by name"); ...