Saiku通过更改源代码实现默认查询前一天数据

saiku在本地进行的编译的方式前面已有教程说明,接下来就是更改原代码了 (从网上学得教程,目前只了解到获取最新一天的数据信息)

参考博客地址: https://blog.csdn.net/zstao168/article/details/52818569

1. 主要更改的类信息:在saiku-web工程中的Query2Resource.java中,具体类路径为:  /saiku-web/src/main/java/org/saiku/web/rest/resources/Query2Resource.java

在该类的 public QueryResult execute(ThinQuery tq  ) 方法中添加  tq = this.restrictQueryByDate(tq);  (execute方法大概在该类的 185-220行左右)

 /**
*
* Execute a Saiku Query
* @summary Execute Query
* @param tq Thin Query model
* @return A query result set.
*/
@POST
@Consumes({"application/json" })
@Path("/execute")
public QueryResult execute(ThinQuery tq) { //add code to limit query date
tq = this.restrictQueryByDate(tq);
try {
if (thinQueryService.isMdxDrillthrough(tq)) {
Long start = (new Date()).getTime();
ResultSet rs = thinQueryService.drillthrough(tq);
QueryResult rsc = RestUtil.convert(rs);
rsc.setQuery(tq);
Long runtime = (new Date()).getTime()- start;
rsc.setRuntime(runtime.intValue());
return rsc;
} QueryResult qr = RestUtil.convert(thinQueryService.execute(tq));
ThinQuery tqAfter = thinQueryService.getContext(tq.getName()).getOlapQuery();
qr.setQuery(tqAfter);
return qr;
}
catch (Exception e) {
log.error("Cannot execute query (" + tq + ")",e);
String error = ExceptionUtils.getRootCauseMessage(e);
return new QueryResult(error);
}
}

 

在Query2Resource.java类中添加 ThinQuery  restrictQueryByDate(ThinQuery tq) 方法,内容如下

  // add code for query limit
private ThinQuery restrictQueryByDate(ThinQuery tq) { ThinQueryModel queryModel = tq.getQueryModel();
Map<AxisLocation, ThinAxis> axesMap = queryModel.getAxes(); NamedList<ThinHierarchy> namedList = new NamedListImpl<ThinHierarchy>(); ThinAxis filterAxis = axesMap.get(AxisLocation.FILTER);
List<ThinHierarchy> filterHie = filterAxis.getHierarchies(); namedList = this.resetThinHierachy(filterHie); //将修改后的Row重新set到queryModel
if(namedList.size() > 0) { ThinAxis newFilterAxis = new ThinAxis(
AxisLocation.FILTER,
namedList,
filterAxis.isNonEmpty(),
filterAxis.getAggregators()
); axesMap.put(AxisLocation.FILTER,newFilterAxis);
} //将修改后的Row重新set到queryModel
if(namedList.size() == 0) { ThinAxis rowAxis = axesMap.get(AxisLocation.ROWS);
List<ThinHierarchy> rowHie = rowAxis.getHierarchies(); namedList = this.resetThinHierachy(rowHie); if(namedList.size() > 0) {
ThinAxis newRowsAxis = new ThinAxis(
AxisLocation.ROWS,
namedList,
rowAxis.isNonEmpty(),
rowAxis.getAggregators()
); axesMap.put(AxisLocation.ROWS,newRowsAxis);
}
} //if columns contained date member
//if contained and have not set the limit ,then add limit to one day ,if do not hava then add this column and limit to one day;
if(namedList.size() == 0) { // namedList.clear(); ThinAxis colAxis = axesMap.get(AxisLocation.COLUMNS);
List<ThinHierarchy> colHie = colAxis.getHierarchies(); namedList = this.resetThinHierachy(colHie); if(namedList.size() == 0) { //if list is empty,then column don't hava date ,then add colHie to list and enfore to add date member;
namedList.addAll(colHie); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String yesterday = format.format(new Date(new Date().getTime() - 24 * 60 * 60 * 1000)); String newDateMdx = "[SaikuUseDate].[SaikuUseDate].["+yesterday+"]"; ThinMember thinMember = new ThinMember(yesterday,newDateMdx,yesterday);
ThinHierarchy thinHie = new ThinHierarchy(); thinHie.setName("[SaikuUseDate].[SaikuUseDate]"); List<ThinMember> thinMemberList = new ArrayList<ThinMember>();
thinMemberList.add(thinMember);
ThinSelection selection = new ThinSelection();
selection.setMembers(thinMemberList);
selection.setType(ThinSelection.Type.INCLUSION);
ThinLevel thinLevel = new ThinLevel(yesterday,yesterday,selection,null);
// thinLevel.setSelection(selection);
Map<String,ThinLevel> mapLevel = new LinkedHashMap<String,ThinLevel>();
mapLevel.put("SaikuUseDate", thinLevel); thinHie.setLevels(mapLevel); namedList.add(thinHie);
ThinAxis newColAxis = new ThinAxis(
AxisLocation.COLUMNS,
namedList,
colAxis.isNonEmpty(),
colAxis.getAggregators()
); axesMap.put(AxisLocation.COLUMNS,newColAxis);
}
} return tq;
} private NamedList<ThinHierarchy> resetThinHierachy(List<ThinHierarchy> hieList) { NamedList<ThinHierarchy> namedList = new NamedListImpl<ThinHierarchy>();
boolean flag = false; for(ThinHierarchy hie : hieList) {
if(hie.getName().equals("[SaikuUseDate].[SaikuUseDate]")) { if(hie.getLevels().get("SaikuUseDate").getSelection() == null) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String yesterday = format.format(new Date(new Date().getTime() - 24 * 60 * 60 * 1000)); String newDateMdx = "[SaikuUseDate].[SaikuUseDate].["+yesterday+"]"; ThinMember thinMember = new ThinMember(null,newDateMdx,yesterday); List<ThinMember> thinMemberList = new ArrayList<ThinMember>();
thinMemberList.add(thinMember);
ThinSelection selection = new ThinSelection();
selection.setMembers(thinMemberList); hie.getLevels().get("SaikuUseDate").setSelection(selection);
} flag = true;
} namedList.add(hie);
}
if(flag) return namedList; namedList.clear();
return namedList; }

 

ps:  如果 hie.getLevels().get("SaikuUseDate") 中得到的ThinLevel对象没有setSeletion(selection)方法,需要手工在ThinLevel中添加set方法

还有一点需要注意,就是加上这些代码之后,saiku的schame文件中cube需要有 SaikuUseDate 日期字段

最后将整个项目打包编译即可,将新的saiku-server启动,然后配置一些数据信息,便能获取最近一天的数据信息了。

Saiku更改源代码实现默认查询一天的数据(十)的更多相关文章

  1. Saiku根据入参日期查询出对应的数据(二十)

    Saiku根据入参日期查询出对应的数据 之前好像有写过一篇博客关于saiku date range的,现在进一步更新啦!!! 这里的日期筛选会更完善一些,需要提供两个参数 开始日期与结束日期(star ...

  2. Saiku更改導出文件的文件名(十九)

    Saiku更改導出文件的文件名 Saiku查询完数据之后,可以以excel,pdf,csv等格式将数据导出,这里我们来讲一下怎么更改导出的文件名. 找到对应的导出方法所在的js文件: saiku-se ...

  3. Informatica 常用组件Source Qualifier之二 默认查询

    2 默认查询 对于关系源,PowerCenter Server 将在运行会话时为每个源限定符转换生成查询.对于每个在映射中使用的源列,默认查询均为 SELECT 语句.也就是说,PowerCenter ...

  4. Windows10系统如何更改程序的默认安装目录?

    Windows10系统如何更改程序的默认安装目录? 在Windows10系统的使用中,软件程序的默认安装目录是:C:\Program Files\...或者C:\Program Files(x86)\ ...

  5. 如何在TFS中恢复系统默认查询”已指派给我”的设置(TFS 2013)

    故事是这样开始的,一天开发人员求助说,在浏览器中修改了系统默认的工作项查询"已指派给我"的后,发现这个查询每次都提示超时,并且没有办法恢复到初始的设置状态,因为出现超时提示以后,查 ...

  6. mysql数据库管理工具sqlyog在首选项里可以设置默认查询分页条数和字体,改写关键字大小写

    sqlyog设置一直习惯用sqlyog来管理mysql数据库,但有三个地方用得不是很爽:1.默认查询条数只有1000条经常需要勾选掉重新查询.2.自动替换关键字大小写,有时候字段名为关键字的搞成大写的 ...

  7. [saiku] 系统登录成功后查询Cubes

    一.系统启动时初始化ds和conn 1.查询出目前系统拥有的Datasources和Connections放入内存中 2.比对saiku-datasources中的ds是否有新增的,如果有,创建新的d ...

  8. 也可以使用如下命令更改您的默认 Shell

    也可以使用如下命令更改您的默认 Shell chsh -s /bin/zsh (需要输入您的密码)

  9. 更改git bash默认的路径

    更改git bash默认的路径   在打开git bash时,每次都是在C:\Uer路径下,每次都需要先用cd命令转换到自己需要工作的路径(cd  /f/dss).修改打开git bash 时的默认的 ...

随机推荐

  1. 微信内置安卓x5浏览器请求超时自动重发问题处理小记

    X5内核  请求超时后会自动阻止请求返回并由代理服务器将原参数重新发送请求到服务层代码.但由于第一次请求已经请求到服务器,会导致出现重复下单.支付等重大问题. 该问题由于腾讯x5浏览器会自动阻止第一次 ...

  2. 转载一篇较为详细的caffe-ssd编译环境的搭建

    这篇搭建的文章写得还是比较全面的,亲测有效:https://blog.csdn.net/lukaslong/article/details/81390276

  3. 第九篇——Struts2的拦截器

    拦截器: Struts2大多数核心功能都是通过拦截器实现的,每个拦截器完成某项功能: 拦截器方法在Action执行之前或之后执行. 工作原理: 拦截器的执行过程是一个递归的过程 action请求--& ...

  4. js 清空html input file的值

    在做上传图片预览时,利用input onchange事件触发函数,但是type=file时,一定记得新建要清空原来的图片,因为原来的图片还存在在input里面,再选重复的图片没有change,故不会触 ...

  5. MySQL5.7 编译安装

    准备 yum install cmake yum install -y bison yum install -y libaio-devel yum install -y boost 下载 percon ...

  6. Linux下执行Oracle的sql脚本

    (1)  启动监听: Root用户登录后,输入: $su – oracle 回车(Oracle为Oracle数据库安装用户,必须有横杠: - ) 启动监听: $lsnrctl start --启动 $ ...

  7. linux基础之find

    linux上文件查找工具: locate, find locate: 依赖于事先构建的索引,索引的构建在系统较为空闲时自动进行(周期性任务),手动更新数据库(updatedb) 索引构建过程需要遍历整 ...

  8. 线性回归(linear regression)

    基本形式 最小二乘法估计拟合参数 最小二乘法:基于均方误差最小化来进行模型求解的方法称为“最小二乘法”(least square method) 即(左边代表 $\mathbf{\omega }$ 和 ...

  9. 08.vue中样式-class

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 去除pt种里tracker的方法

    1.下载BEncode Editor,打开 2.把下载的种子拖进去,可以看到这样的: tracker就是箭头指的地方,这个包含了个人帐号独一无二的私钥,如果泄露给别人的话别人下载就是走的你的帐号,轻则 ...