我正在尝试使用Java DSL编写一些伪代码,以连接来自两个不同数据库的两个相同表。
例如,我在MySQL和PostgreSQL数据库中有一个Person表。希望看到所有行的并集。有人可以提出建议吗?
更新:我尝试过的是下面的路由定义代码
SELECT
MIN(subscribers.customer_number) OVER (PARTITION BY customers.customer_number, customer_type) AS cusNo,
COUNT(subscribers.code) OVER (PARTITION BY customers.customer_number, customer_type) AS subscribes,
customer_type
FROM
customers
JOIN
subscribers ON subscribers.customer_number = customers.customer_number;
以上内容获取数据并合并到一个通道中,但是,我想执行删除重复项,过滤行等操作。我不确定该怎么做。也许需要聚合器组件?
答案 0 :(得分:2)
这似乎很容易做-您只需要记住两件事即可。
然后,然后才能将它们聚合在一起。
如果我要刺一针,那将是一个开始。我想利用SQL component的功能来指定应将SQL结果存储在其中的特定标头。从那里,我发现在聚合后处理两个记录后,使用简单的处理器会更容易一些并执行我想要的任何逻辑。
from("sql:select name, age from person?datasource=xyz&outputHeader=MySqlDataSet&outputType=Person")
.to("direct:foo");
from("sql:select name, age from person?datasource=abc&outputHeader=PostgresDataSet&outputType=Person")
.to("direct:foo");
from("direct:foo")
.aggregate(constant(true), new GroupedExchangeAggregationStrategy())
.completionFromBatchConsumer()
.process(exchange -> {
// now you have control over the exchange which has both exchanges
// which has both properties you require.
// manipulate, merge, and dedupe here to your heart's content.
});