Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Complex Filter Condition in BIRT
mihika.shah
<p>Hello Team,</p>
<p> </p>
<p>I created a dataset where I have two columns called BuildingClass and EventDate. I want to filter the dataset results based on below criteria.</p>
<p> </p>
<p>if (BuildingClass =='No' || BuildingClass =='' || BuildingClass ==null)</p>
<p>{</p>
<p> EventDate < (CurrentMonth +18)
18 months from now</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p> EventDate < (CurrentMonth +36)
36 months from now</p>
<p>}</p>
<p> </p>
<p>Hence my dataset should be filtered based on EventDate value if BuildingClass condition is met.</p>
<p> </p>
<p>Please suggest how this can be possible. Thanks in advance!</p>
Find more posts tagged with
Comments
jfranken
<p>Try the following for the condition and change the operator to "Is True":</p>
<p> </p>
<p> </p>
<p>var bc = row["BuildingClass"];</p>
<p>var ed = row["EventDate"];</p>
<p> </p>
<p>if (bc =='No' || bc =='' || bc ==null) {</p>
<p> if ( ed < BirtDateTime.addMonth(BirtDateTime.today(), 18) ) {</p>
<p> true</p>
<p> } else {</p>
<p> </p>
<p> false</p>
<p> }</p>
<p>} else {</p>
<p> if ( ed < BirtDateTime.addMonth(BirtDateTime.today(), 36) ) {</p>
<p> true</p>
<p> } else {</p>
<p> false</p>
<p> }</p>
<p>}</p>
<p> </p>
<p> </p>
<p>Regards,</p>
<p>Jeff</p>
mihika.shah
<p>Thanks Jeff for your quick response.</p>
<p> </p>
<p>I used below condition with operator as "Is True" as mentioned by you. </p>
<p> </p>
<p>var b=String(row["Location__triBuilding____triBuildingClassCL"]);</p>
<div>var d=Formatter.format(row["triItem__triOption____triDateDA"],"MM/dd/YYYY");</div>
<div>var e;</div>
<div>if( b=='No' || b=='' || b== null)</div>
<div>{</div>
<div>if(d < (Formatter.format((BirtDateTime.addMonth((Formatter.format(BirtDateTime.today(),"MM/dd/YYYY")), 18)),"MM/dd/YYYY")))</div>
<div>{</div>
<div>e=true;</div>
<div>}</div>
<div>else</div>
<div>{</div>
<div>e=false;</div>
<div>}</div>
<div>}</div>
<div>e;</div>
<div> </div>
<div> </div>
<div>For some reason, it still doesn't give me the correct results. For example, a record with BuildingClass set as '' has two EventDates "05/31/2018" and "04/30/2015". As per this condition, it should give me the results with date "04/30/2015" and filter out "05/31/2018" (as it exceeds 18 months of timeframe). But it gives the results exactly opposite to it i.e. gives me the results with date "05/31/2018" and filter out "04/30/2015". </div>
<div> </div>
<div>I'm using Formatter as EventDate field value doesn't have a timestamp with the date.</div>
<div> </div>
<div>Can you please check what can be wrong here?</div>
Matthew L.
<p>Could you provide some sample data in a CSV or Excel file that we can test?</p>
mihika.shah
<p>Hi Matthew,</p>
<p> </p>
<p>Please find the below sample data. Sorry I couldn't attach the file.</p>
<p> </p>
<p> Event Date Building Class </p>
<p> </p>
<p>3/31/2015 No</p>
<p>5/19/2018 No</p>
<p>8/18/2016 Branch</p>
<p>10/1/2018 Enterprise</p>
<p>2/18/2017 No</p>
<p>7/31/2014 Enterprise</p>
<p>1/26/2019 No</p>
<p>9/30/2015 Branch</p>
mihika.shah
<p>I was breaking the condition into small peices just for testing and found that the condition for comparing the dates is not working as expected. It's giving the dates even after 2019 though the timeframe is set as 18 months from now. </p>
<p> </p>
<p>Is it because my actual date field has type as Java object. And I'm formatting the date and getting the result.</p>
<p> </p>
<p>Can someone please look into this?</p>
jfranken
<p>I created a sample report and attached it to this post. The code is in the data set filter. Note that I changed the operator to "Is False" for this filter.</p>
mihika.shah
<p>Thanks a lot Jeff. I resolved the issue with the date comparision. My source date string was coming as Java Object data type as I'm using scripted data source. And hence when I used Formatter to change the date format, it returned me a string which wasn't allow me to compare the dates. So I converted string to date using new Date() and it worked as expected.</p>
<p> </p>
<p>But right now when I run my report, it gives me java.lang.NullPointerException and below is the stack trace. I'm not able to find out any issues.</p>
<p> </p>
<p> </p>
<div>java.lang.NullPointerException<br>
at org.eclipse.birt.core.archive.compound.ArchiveEntryOutputStream.flushBuffer(ArchiveEntryOutputStream.java:169)<br>
at org.eclipse.birt.core.archive.compound.ArchiveEntryOutputStream.write(ArchiveEntryOutputStream.java:125)<br>
at java.io.DataOutputStream.writeLong(Unknown Source)<br>
at org.eclipse.birt.core.util.IOUtil.writeLong(IOUtil.java:403)<br>
at org.eclipse.birt.data.engine.impl.document.RowSaveUtil.saveNullRowsBetween(RowSaveUtil.java:271)<br>
at org.eclipse.birt.data.engine.impl.document.RowSaveUtil.saveFinish(RowSaveUtil.java:215)<br>
at org.eclipse.birt.data.engine.impl.document.RDSave.saveFinish(RDSave.java:190)<br>
at org.eclipse.birt.data.engine.impl.ResultIterator$RDSaveHelper.doSave(ResultIterator.java:1258)<br>
at org.eclipse.birt.data.engine.impl.ResultIterator$RDSaveHelper.doSaveFinish(ResultIterator.java:1218)<br>
at org.eclipse.birt.data.engine.impl.ResultIterator.close(ResultIterator.java:971)<br>
at org.eclipse.birt.data.engine.impl.ResultIterator$1.dataEngineShutdown(ResultIterator.java:201)<br>
at org.eclipse.birt.data.engine.impl.DataEngineImpl.shutdown(DataEngineImpl.java:575)<br>
at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.shutdown(DataRequestSessionImpl.java:509)<br>
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.shutdown(AbstractDataEngine.java:348)<br>
at org.eclipse.birt.report.engine.data.dte.DataGenerationEngine.shutdown(DataGenerationEngine.java:151)<br>
at org.eclipse.birt.report.engine.executor.ExecutionContext.close(ExecutionContext.java:496)<br>
at org.eclipse.birt.report.engine.api.impl.EngineTask.close(EngineTask.java:1539)<br>
at org.eclipse.birt.report.engine.api.impl.RunTask.close(RunTask.java:309)<br>
at org.eclipse.birt.report.service.ReportEngineService.runReport(ReportEngineService.java:1335)<br>
at org.eclipse.birt.report.service.BirtViewerReportService.runReport(BirtViewerReportService.java:158)<br>
at org.eclipse.birt.report.service.actionhandler.BirtRunReportActionHandler.__execute(BirtRunReportActionHandler.java:81)<br>
at org.eclipse.birt.report.service.actionhandler.BirtChangeParameterActionHandler.runReport(BirtChangeParameterActionHandler.java:58)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractChangeParameterActionHandler.__execute(AbstractChangeParameterActionHandler.java:53)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)<br>
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleChangeParameter(BirtDocumentProcessor.java:100)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)<br>
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)<br>
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)<br>
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)<br>
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)<br>
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)<br>
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)<br>
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)<br>
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)<br>
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)<br>
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)<br>
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)<br>
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)<br>
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)<br>
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)<br>
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)<br>
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)<br>
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)<br>
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)<br>
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)<br>
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)<br>
at org.mortbay.jetty.Server.handle(Server.java:326)<br>
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)<br>
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:939)<br>
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)<br>
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)<br>
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)<br>
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)<br>
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)</div>
<div> </div>
<div> </div>
<div> </div>
<div>Please let me know if you can identify any issues from this stack trace.</div>
jfranken
<p>I can't tell what's going on from that message. Did the report run before you added the new code? If so, comment out lines in the code to narrow down the error, then post the offending line(s) here. </p>
<p> </p>
<p>If the issue isn't due to the new code, there might be more information in your log file. Go to the File menu, select Switch Workspace, and choose "Other". That will show you the path to your current workspace, In your workspace directory is a folder called .metadata. In that folder is a file called ".log" (the name will be blank if you hide file extensions). See if the log file has more information. Another option is to make a copy of your report and delete elements you've added recently until the error goes away.</p>
<p> </p>
<p>Sorry I can't provide more help on this issue,</p>
<p>Jeff</p>
mihika.shah
<p>Thanks Jeff. </p>
<p> </p>
<p>After my further analysis, I found that I'm able to run the report successfully without changing anything but with selected parameters. For example, when I run the report and select APAC/EMEA/AMERICAS (any one of them or combination of them) for the region (multi-select list) and the report works. But when I select all 3 of them together and run/view the report in internal browser, the report doesn't work and throws the above NullPointer Exception. And when I select all 3 of them together and run the report on Preview tab, it works as expected and doesn't throw any exception. Looks like there is no issue with the functionality/code of this report.</p>
<p> </p>
<p>Does it have to do anything with the number of records that it returns? It looks a bit strange to me. </p>
jfranken
<p>If you were getting an error message about "memory" I'd be more likely to suspect the number of records returned, but that's less likely for a null pointer exception. I recommend checking the log for more information.</p>
mihika.shah
<p>I observed that when the report returns less than 1000 records, it works as expected.But when it exceeds 1000 records, the report doesn't work and throws the above exception. </p>
<p> </p>
<p>I checked the log as well. But there is no entry for this exception at all. Is there any way we can change the limit of the report result count?</p>
jfranken
<p>I don't know of a 1000 record limit. If you can upload your report along with enough sample data to replicate the error, I'll take a look at it and see if I can find the source of the error.</p>
<p> </p>
<p>I'm not sure why you aren't seeing the error in the log. Maybe it is just difficult to find. You could make a backup copy of the log and clear out the original, then run the report again so that the error occurs. That will make the error message easier to spot. It's also possible to increase the logging level, but that shouldn't be necessary.</p>
mihika.shah
<p>Thanks Jeff for your help!</p>
<p> </p>
<p>I set one more filter on the dataset which then gives me less than 1000 records. Now when I run my report with parameter selected as "All", the report works as expected without any issues.</p>
<p> </p>
<p>So it seems like something was wrong with the resultset count. Do we have any limitation of Eclipse/BIRT for record limitation? I don't know of it any.</p>
jfranken
<p>I have a few questions:</p>
<p>What version of the software are you running? </p>
<p>How are you running the report?</p>
<p>When the 1000 row limit is exceeded, are you getting the "null pointer exception error" you posted above? </p>
<p>Are you able to run it without any filtering code? If so, do you still get the error?</p>
<p> </p>
<p>I don't know of any limit. I just ran a report in version 4.5.0 via the "View Report in Web Viewer" menu command that returned 40,000 rows. It's unlikely that the issue is related to system resources when the limit is precisely 1000. </p>
<p> </p>
<p>Regards,</p>
<p>Jeff</p>
mihika.shah
<p>Hi Jeff,</p>
<p> </p>
<p>1) I'm using BIRT version 2.6.2 with one of my third party tool - IBM TRIRIGA. </p>
<p>2) I'm running the report via <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> "View Report in Web Viewer" </span></p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">3) Yes, when it exceeds the result count, it throws the above posted NullPointer exception</span></p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">4) I haven't tried to run the report without any filters yet. I will let you know on this soon.</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Thanks,</span></p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Mihika</span></p>
jfranken
<p>I did a quick search and didn't see any issues related to Tririga's record limits. If you can create a sample report that reproduces the issue and post it here, that would be helpful in determining what's causing the error.</p>
<p> </p>
<p>Regards,</p>
<p>Jeff</p>
mihika.shah
<p>Hi Jeff,</p>
<p> </p>
<p>When I'm using the below condition as a filter, it doesn't work when my input date format is "dd-MMM-yyyy". Input data has data type set as Java Object.</p>
<p> </p>
<p> </p>
<div>var b=String(row["Location__triBuilding____triBuildingClassCL"]);</div>
<div>var d=new Date(Formatter.format(row["triItem__triOption____triDateDA"],"MM/dd/YYYY"));</div>
<div>var e=new Date(Formatter.format(BirtDateTime.addMonth(BirtDateTime.today(), 18),"MM/dd/YYYY"));</div>
<div>var f=new Date(Formatter.format(BirtDateTime.addMonth(BirtDateTime.today(), 36),"MM/dd/YYYY"));</div>
<div>if( b=='No' || b=='' || b== null)</div>
<div>{</div>
<div>if(BirtComp.lessThan(d,e))</div>
<div>{</div>
<div>true;</div>
<div>}</div>
<div>else</div>
<div>{</div>
<div>false;</div>
<div>}</div>
<div>}</div>
<div>else</div>
<div>{</div>
<div>if(BirtComp.lessThan(d,f))</div>
<div>{</div>
<div>true;</div>
<div>}</div>
<div>else</div>
<div>{</div>
<div>false;</div>
<div>}</div>
<div>}</div>
<div> </div>
<div> </div>
<div>Can anyone please look into this?</div>
Matthew L.
<p>Try placing the following code in the reports initialize method:</p>
<pre class="_prettyXprint _lang-js">
//
//Please note that all custom code received from Actuate Support is officially untested and unsupported.
//This is meant for guidance purposes only and should not be implemented in a production environment without proper testing.
//This custom code is provided to you "AS IS", It is your own responsibility to maintain it if changes are required.
//
//The following function converts a Date string ("MM-dd-yyyy") into a BIRT DateTime Object.
//Example:
// var dateString = "2015-01-01";
// var dateStringFormat = "yyyy-MM-dd"; //Optional param to change input format
// var dateObject = convertFormattedDateStringToDateObject(dateString,dateStringFormat);
//
function convertFormattedDateStringToDateObject(dateString,dateStringformat){
if(!dateStringformat){ dateStringformat = "MM-dd-yyyy"; } //MM-dd-yyyy
var separator = dateStringformat.match("[^A-Za-z0-9]"); //Get the separator
dateStringformat = dateStringformat.toString().toLowerCase().split(separator); //Lowercase format string and split
var tmp = dateString; //Get value
tmp = tmp.toString().split(separator); //Split into array
year = tmp[dateStringformat.indexOf("yyyy")]; //Get Year
month = tmp[dateStringformat.indexOf("mm")]; //Get Month
day = tmp[dateStringformat.indexOf("dd")]; //Get Day
return BirtDateTime.date(year, month-1, day); //Return Date object
}
//
</pre>
<p>Then use the following code in your filter:</p>
<pre class="_prettyXprint _lang-js">
var currentRowCheck = "" + row["Location__triBuilding____triBuildingClassCL"]; //Get row value into string
var currentRowValue = "" + row["triItem__triOption____triDateDA"]; //Get row value into string
var currentRowDateObj = convertFormattedDateStringToDateObject(currentRowValue,"mm/dd/yyyy"); //See custom conversion function in initialize method
var todayPlus18MonthsInTheFuture=BirtDateTime.addMonth(BirtDateTime.today(), 18); //Get 18 months from today
var todayPlus36MonthsInTheFuture=BirtDateTime.addMonth(BirtDateTime.today(), 36); //Get 36 months from today
if(currentRowCheck =='No'||currentRowCheck.length==0) //Other row check, true
BirtDateTime.diffDay(currentRowDateObj,todayPlus18MonthsInTheFuture)<0; //Return true/false
else //Other row check, false
BirtDateTime.diffDay(currentRowDateObj,todayPlus36MonthsInTheFuture)<0; //Return true/false
</pre>
mihika.shah
<p>Thanks a lot Matthew for providing the alternate way to change the date format. Very helpful.</p>