0

我有一个要求,我的两个表位于两个不同的数据库中。

所以本质上我不能写连接查询。现在的问题是如何编写一个 ETL 文件,它基本上可以帮助我模拟内部连接scriptella

Order table
{OrderID, CustomerID, OrderDate}
Customer Table
{CustomerID, CustomerName}

想在 scriptella 中模拟以下查询:

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID

谢谢,迪帕克

4

1 回答 1

0

您基本上需要 2 个嵌套查询来模拟内部连接。第一个查询 (Q1) 从一个表中选择所有行。对于从 Q1 中找到的每个行,都会执行第二个查询 (Q2)。结果被发送到 Q2 内的内部脚本元素。

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <!-- db1 has Customers table -->
    <connection id="db1" url="jdbc:database1" user="user1" password="pwd1" classpath="external.jar"/>

    <!-- db2 has Orders table -->
    <connection id="db2" url="jdbc:database2" user="user2" password="pwd2" classpath="somedriver.jar"/>

    <!-- just for logging -->
    <connection id="log" driver="text"/>

    <query connection-id="db1">
         <!-- SELECT CustomerID/name for all rows from Customer -->
         SELECT CustomerID, CustomerName from Customer

         <!-- For each selected customer row, select matching orders -->
         <query connection-id="db2">
             SELECT OrderID, OrderDate FROM Orders WHERE CustomerID=?CustomerID
             <!-- Log each match. You can also make INSERT to any DB here -->
             <script connection-id="log">
                  Row $rownum: Orders.OrderID=$OrderID, Customers.CustomerName=$CustomerName, Orders.OrderDate=$OrderDate
             </script>
        </query>
    </query>
<etl>
于 2016-01-12T02:13:16.490 回答