gpt4 book ai didi

java - 在 Java 中创建管道式 SQL/NOSQL 查询

转载 作者:太空宇宙 更新时间:2023-11-04 08:21:11 25 4
gpt4 key购买 nike

我正在尝试用 Java 创建一个框架,它支持链式/管道式查询,其中一个查询的输出将被转换为用作另一个查询的输入。类似于 PyCascading这些查询将在运行时进行。我查看了一些框架并发现了 Apache Camel& Spring Integration因为它们提供了链接和路由的概念(企业集成模式)。我发现 Apache Camel 比 Spring Integration 更好(恕我直言)。

<小时/>

我应该为我的框架选择 Apache Camel 还是有更好的方法可以实现这一目标?

我的查询语法是

Query query1 = "select customer.id from customer where customer.name = 'ABC'";
Query query2 = "select account.id from account where account.custid in {$1}";
// $1 will be the input of second query
from(query1).inputto(query2).printOutput();

最佳答案

这可以使用camel-jdbc来实现以及一些基本的 Camel 功能(如 simple ),允许您内联结果解析...

The [CAMEL-JDBC] result is returned in the OUT body as an ArrayList[HashMap[String,Object]] The List object contains the list of rows and the Map objects contain each row with the String key as the column name.

此结果可用于动态构建后续查询...

from("direct:start")
.setBody(constant("select customer.id as ID from customer where customer.name = 'ABC'"))
.to("jdbc:myDataSource")

//now, use simple/ognl to extract the first result and the 'ID' from the Map in the body
.setBody(simple("select account.id from account where account.custid in ${body[0][ID]}"))
.to("jdbc:myDataSource")

.log("ACCOUNT IDS = ${body}");

关于java - 在 Java 中创建管道式 SQL/NOSQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9513026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com