lightdb周边-聚合查询多服务连接、分组、排序、聚合(fwd直连库方式)

前言

使用聚合查询中间件,多个http、t3、fdw服务的结果聚合,同时利用SQL引擎的能力对结果进行连接、分组、排序、聚合

安装聚合查询

试用版本安装见 lightdb周边-聚合查询试用包指引_星辰bitone的博客-CSDN博客

场景

假设业务应用分为用户域微服务、订单域微服务、产品域微服务,每个微服务拥有单独的数据库。 如下图所示:

在场景用户认购理财产品后,会在订单域里面产生下单记录,产品域中会有用户购买理财产品中的每日收益情况。

用户库

产品库:

订单库

聚合查询开发配置

服务配置

聚合查询配置fdw,规则见:lightdb周边-聚合查询参考手册_星辰bitone的博客-CSDN博客 中外部表聚合章节

用户外部表

lightdb@postgres=# CREATE foreign table f_users ( 
lightdb@postgres(# user_id VARCHAR(100), 
lightdb@postgres(# user_name VARCHAR(100) 
lightdb@postgres(# ) server oradb OPTIONS (schema 'ZHANGLIANG', table 'USERS' );

订单外部表

lightdb@postgres=# create foreign table f_order ( 
lightdb@postgres(# order_id VARCHAR(100), 
lightdb@postgres(# user_id VARCHAR(100), 
lightdb@postgres(# product_id VARCHAR(100), 
lightdb@postgres(# status VARCHAR(1) 
lightdb@postgres(# ) server oradb OPTIONS (schema 'ZHANGLIANG', table 'USER_ORDERS' );

产品外部表

lightdb@postgres=# create foreign table f_products ( 
lightdb@postgres(# user_id VARCHAR(100), 
lightdb@postgres(# product_id VARCHAR(100), 
lightdb@postgres(# product_name VARCHAR(100), 
lightdb@postgres(# amount_date VARCHAR(100), 
lightdb@postgres(# amount numeric(16,2) 
lightdb@postgres(# ) server oradb OPTIONS (schema 'ZHANGLIANG', table 'USER_PRODUCTS' );

mybatiis xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hundsun.easysearch.TestMapper">
    <select  id="getUserTradeTrendFDW" resultType="map">
        SELECT * FROM
            (
                SELECT u.user_id, u.user_name, o.product_id, p.product_name, p.amount_date, sum(p.amount)
                FROM
                    f_products p ,
                    f_order o ,
                    f_users u
                WHERE
                    u.user_id = o.user_id and o.status = 'S' and o.product_id = p.product_id
                GROUP BY u.user_id, u.user_name, o.product_id, p.product_name, p.amount_date
            ) t
        ORDER BY t.amount_date DESC, t.product_name DESC limit #{pageSize} offset #{pagePos};
    </select>
</mapper>

上述mybatis xml配置内容放到TestMaper.xml中,并放到聚合查询接入层easysearch.mapper-locations指定的目录下。

[fcperf@hs-10-20-30-193 easysearch]$ cat config/application.properties | grep locations easysearch.mapper-locations=./mapper 
[fcperf@hs-10-20-30-193 easysearch]$ ls 
mapper/TestMapper.xml

启动聚合查询接入层

[fcperf@hs-10-20-30-193 easysearch]$ ls arthas-output config easy-search.jar logs mapper start.sh stdout.log stop.sh 
[fcperf@hs-10-20-30-193 easysearch]$ ./start.sh 
[fcperf@hs-10-20-30-193 easysearch]$ tail -f logs/easy-search-app.log

可以直接请求接口getUserTradeTrendFDW

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值