Tuesday, September 26, 2006

Optimistic Sums

Suppose you are developing reports for the Sales team. Your reports are providing insight into the sales channel. Your reports aggregate the sales estimates rolling the estimates up to the executive vice president of sales. The management team wants to see a bit more optimistic view of the sales forecasts. They ask you, "is there any way that you can manipulate the reports to provide a more optimistic view of the sales estimates."

Now my initial reaction would be one of alarm, "you want me to do what?" But then my curiosity would get a hold of me, is there a good way to do this? What is the best way?

First, you could create custom Birt Script sprinkled through out your reports that would round up the numbers as they are imported. Second, you could manipulate the data in the database either when you query it, or in the raw data. Third, you could create custom java functions to that you would integrate into your BIRT script. Fourth, you could make a Bugzilla entry and ask the BIRT team to add the new function.

Yes, there are a lot of ways that you could solve this problem, but there are issues with each method. None of them provide a really seamless way to customize your implementation of BIRT. Fortunately, BIRT ships with a standard way to add new aggregate functions to the basic BIRT Total functions. It is all done through the org.eclipse.birt.data.aggregation extension point.  This post will walk you through the process of using the aggregation extension point to create your own OptimisticSum function and add it to your BIRT implementation.

The entire Eclipse Platform is built through a common extendable framework. In short Eclipse is made of a large number of plug-ins. Each plug-in can provide the ability to customize or extend its behavior through an extension point. When you create an implementation of an extension point, you are creating an extension. So BIRT is made up all of the BIRT plug-ins. Each BIRT plug-in has defined extension points where you can define new BIRT functions. What we are going to do is extend the org.eclipse.birt.data.aggregation extension point.

If you are interested in Eclipse extensions, there are a number of resources that you can use. In the standard Eclipse help, there are three guides that you may find useful: Platform Plug-in Developer Guide, JDT Plug-in Developer Guide, and the Plug-in Development Environment Guide all provide great information on plug-in development. In addition, "The Java Developer's Guide to Eclipse" provides a complete overview of the entire Eclipse plug-in development process.

Fortunately, you don't need to know that much to do a simple BIRT aggregate extension. I have created an eleven minute screen-cast that walks you through the entire process of creating a BIRT aggregate extension. You can find it here.

I also have a plug-in project that demonstrates the OptimisticSum control available here.

Here is an outline of the high level steps that are required to create a BIRT data aggregate extension:

1) Create a plug-in project

2) Add a dependency on the org.eclipse.birt.data plugin

3) Create an extension of the org.eclipse.birt.data.aggregation extension point

4) Configure the plugin.xml, here is a sample

<extension  id="com.innoventsolutions.aggregate" name="TotalPlus" point="org.eclipse.birt.data.aggregation">
  
<aggregations>
      <Aggregation aggregationClass="com.innoventsolutions.aggregate.OptimisticSum"
name="OptimisticSum">
         <UIInfo parameterMetaInfo="String a, String b, String c" textData="Total.OptimisticSum()" tip="New Optimistic Sum tip~"/>
      </aggregation>
   </aggregations>
</extension>

5) Create an aggregationClass which either extends:
org.eclipse.birt.data.engine.api.aggregation.Aggregation
or implement the following interface:
org.eclipse.birt.data.engine.api.aggregation.IAggregation
If you are creating a single pass aggregate (one trip through the data) just extend the Aggregation class. If you need to do multiple passes over the data use implement the IAggregation interface.

6) In your aggregationClass implement the following methods
getName = name of the function
getType = 0 for Summary function, or 1 for Running function
getParameterDefn = is a boolean array, set to true for each required parameter.
newAccumulator = instantiate an instance of an Accumulator (see next step)

7) Create an extension of the
org.eclipse.birt.data.engine.api.aggregation.Accumulator

8) Implement the following methods in your Accumulator
getValue = returns the value that you have been accumulating
onRow = receives an array of parameters that you use to fulfill your function.  For each row of data returned by your DataStream, the onRow event will be called one time. 

9) Test / Debug your new plugin by running the project as an Eclipse Application. This will open a new instance of Eclipse. This new 'Runtime' instance of Eclipse will allow you to open up report designs and test your code.  If you use the Debug Eclipse Application option when you test your plugin project, you will be able to step through your code, just like in standard Java development with Eclipse.

10) When you have completed your testing you can create a plugin jar by using the export feature on the project and export your project as a Plug-in Development => Deployable Plug-ins and fragments options to create a jar file.  Simply dropping that jar file into the plugins directory of your BIRT deployment, and you custom function will be available.

Good luck creating your own BIRT Functions.

Scott

Tuesday, August 29, 2006

Building a Combination Chart with BIRT

A new screen cast has been added to the BIRT web site that demonstrates building a Combination Chart. This example uses a bar chart with a line chart superimposed. It also illustrates how drill to details can be implemented within a chart.

It can be viewed here.

Additionally the Charting FAQ is now available in the Eclipse Wiki.
The Charting FAQ explains many details on how the Charting Engine can be deployed, customized and manipulated.

Thursday, July 20, 2006

BIRT 2.1 New Features Webinar

We are putting together a webinar to demonstrate some of the new features in BIRT 2.1.
Joint Data Sets, Multi Data Set Cascaded parameters, New Charting features are just some of the topics that will be covered.
This webinar will be presented on Wednesday July 26, 2006. If interested
sign up and join us.

Wednesday, July 05, 2006

BIRT 2.1 New and Notable

As part of the Callisto release train, BIRT 2.1 is now available.

BIRT 2.1 expands on the 2.0 release, by adding features such as joined data sets, connection pooling, better drill through support, improved cascaded parameters, and enhanced charting. BIRT 2.1 also offers many improvements in internationalization, accessibility, and context sensitive help.

To read more about the new and improved featrues in BIRT 2.1 take a look at:
http://www.eclipse.org/birt/phoenix/project/notable2.1.php

Friday, June 16, 2006

Callisto Webinar Example Available

The source for the example covered in the first Callisto Webinar, Building Data Centric RCP Applications, is now available.

This example covers using the DTP and BIRT tools within an RCP application and illustrates this with an example that accesses an iPod library XML file.

Thanks to the Adobe team the recording can be accessed here.

Tuesday, May 30, 2006

Callisto Webinar

The Eclipse team will be starting a series or Webinars in June focused on the Callisto release. The BIRT and DTP teams have the pleasure of doing the first on June 5. We will be focusing on DTP, BIRT, and RCP integration.

If you haven't already signed up, check out Ian's Blog or go to the Eclipse site and register.

Wednesday, May 24, 2006

Joined Data Sets with BIRT 2.1

With the upcoming Callisto release BIRT 2.1 will support Joined Data Sets. Up to this point BIRT has supported multiple data sources, but did not present an easy way to join data from these data sources. If I were building a BIRT report that encapsulated HR data from an Oracle database and Financial data from a MS-SQL server, combining the data in a single output table was very cumbersome.

To address this problem the BIRT team has developed a new type of BIRT Data Set that allows joining of traditional data sets. The Joined Data Set allows the above scenario to be accomplished using Inner and Outer Joins between two data sets. A common key is defined, for join purposes, in the Data Set wizard.

Eg.
For simplicity I will use two CSV files as data sources. The CSV files have the following structure.

Rep_Region.csv
region, sales_repr
East, Rep_A
East, Rep_B
Central, Rep_C


Rep_Sold.csv
sales_rep,quantity_sold,quantity_purchased
Rep_A, 20, 22
Rep_B, 33, 44
Rep_D, 10, 10

The first file, lists the region and the sales rep. The second file lists the sales rep, the quantity of widgets sold and the quantity of widgets purchased from a supplier. Rep_C exists in the first file and not the second. Rep_D exists in the second but not the first. Also notice that the sales rep column name is different in the two files.



Create the first data set in BIRT using the CSV data source.



Create the second data set in BIRT using the CSV data source.




Create the new joined data set by right clicking on Data Sets and choosing “New Joined Data Set”.




In the Data Set Wizard, map the sales_rep column from our first CSV file to the sales_repr column in the second CSV file. The data sets can then be joined using an Inner, Left Outer, or Right Outer Join.



Additionally, joined data sets support Computed columns and Filters.

After dragging the new data set onto the report the following output is displayed.


Inner Join.


Left Outer Join.


Right Outer Join.

This feature is available today in the 2.1 RC3 download.