. Subquery from different data source in BIRT Report
The requirement is to have a query that is something like the following:
SELECT * FROM table1 WHERE oid in ( SELECT * FROM table2 WHERE condition )
Table1 and table2 are on different databases. What can you do using the Eclipse Birt environment?
There are four traditional ways to solve the problem.
1). Use something like a database link - Oracle Database Link. This way, you move the problem to the database level.
2). Depending on the actual problem (read: the length of the “select oid FROM table2 where condition” results, you could use either a BIRT data cube or
3). Use two DataSets and a layout structure list-table like this:
The two DataSets need different DataSources.
- DataSet “T2_oids” with a query “select oid from table2 where condition”.
- DataSet “T1_object” with a single parameter param_oid and a query “select * from table1 where oid = ?”.
Layout structure: * Outer ListItem “T2_oids” bound to DataSet “T2_oids” * Inner TableItem or ListItem “T1_object” bound to DataSet “T1_object” with the parameter bound to row[“oid”](or row[“OID”], use the list box). This item must be placed inside the T2_oids detail section. Since T1_object will return a single row, you can even use a GridItem instead of a TableItem or ListItem.
But if you have to take more compute actions, for example, sort the data by column “date”, since they are sorted by key from original condition, even setting sorting filter on the birt output table doesn’t solve the problem. There’s a way around this sorting problem (by writing the outer results into a POJO (e.g. an ArrayList), then using a scripted dataset to finally sort the results. But this is getting too complicated.
4). Use esProc with BIRT.
Here is the SPL script.
A |
|
1 |
=connect("mysql1") |
2 |
=connect("mysql2") |
3 |
=A1.query(“select * from table1”) |
4 |
=A2.query(“select * from table2”) |
5 |
=A3.join@i(T1_oid, A4:T2_oid) |
6 |
=A5.sort(T1_date) |
7 |
/=A5.groups(T1_date;sum(T1_value1):Num) |
Your BIRT reports can have a query from two data sources no matter what kind of database and go on other computations that are not convenient on BIRT. For detail SPL integration with BIRT, see How to Call an SPL Script in BIRT.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL