Subquery From a Different Data Source in BIRT
In this brief article, see a solution to a problem involving a subquery from a different data source.
Join the DZone community and get the full member experience.Join For Free
The requirement is to have a query that is something like the following:
SELECT * FROM table1 WHERE oid in ( SELECT * FROM table 2 WHERE condition )
Table1 and table2 are on different databases. What can you do using the Eclipse BIRT environment?
You might also like: How to Use a Subquery in MySQL
There are three traditional ways to solve the problem.
Use something like a database link — Oracle Database Link. This way, you move the problem to the database level.
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
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.
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 a detailed SPL integration with BIRT, see How to Call an SPL Script in BIRT.
Published at DZone with permission of Jerry Cruise. See the original article here.
Opinions expressed by DZone contributors are their own.