TypeScript, C#, .NET, ASP MVC, MonoTouch, WPF, Silverlight, Python (Google App Engine), Guitars and other shiny toys
Tuesday, May 26, 2009
Oracle list based queries ORA-00907
Needless to say... first check the parenthesis.
Next check if you are using sorting in the subquery.
E.g:
The following will not work:
select thedate,bsc,cell,ccalls, cmsestab
from
oss_cell_avg
where cell in
(
select cell from
oss_cell_avg
where
oss_cell_avg.ccalls > 0
and oss_cell_avg.cmsestab = 0
and oss_cell_avg.thedate >= (sysdate -2)
and oss_cell_avg.cell not like 'EC%'
order by cell asc
)
order by thedate desc,cmsestab asc
But the following will :
select thedate,bsc,cell,ccalls, cmsestab
from
oss_cell_avg
where cell in
(
select cell from
oss_cell_avg
where
oss_cell_avg.ccalls > 0
and oss_cell_avg.cmsestab = 0
and oss_cell_avg.thedate >= (sysdate -2)
and oss_cell_avg.cell not like 'EC%'
)
order by thedate desc,cmsestab asc
Enjoy!
Sunday, May 24, 2009
BIRT Report Scheduler
I already have a working system in place using what I learnt from the following:
http://digiassn.blogspot.com/2005/10/birt-report-server-pt-2.html
It works pretty neat. I did need to make a couple of modifications to make it work on solaris (needless to say). First wget is not in system path therefore I needed to do the following :
WGET="/usr/sfw/bin/wget"
And later on:
$WGET "$RUNURL=RegionDailyPeak.rptdesign&__format=doc&Region=Central" -O "$EXPORTDIR/CentralDailyPeak.doc" -q
I also hid the server birt viewer url into a variable as :
RUNURL="http://
and EXPORTDIR as the path where I want the download.
Also I wrote some code to send emails as well and used that as a script. Additionally I needed to used the zip command to zip large reports before mailing them :
e.g.:
zip $EXPORTDIR/TCHGPRSTraffic.zip $EXPORTDIR/TCHGPRSTraffic.xls
and then mailed the zip file. Its working fine . Any parameters needing any form of dynamic nature were put into the report using a method I posted previously.
I am thinking of encapsulating all these cool things into a web server application using flex?
Anyone interested in such an application?
The following is a list of the features:
- A simple admin login screen
- Server Settings
- adminusername / adminpassword.
- BIRT report viewer url (the run url... to which only report and further parameters will be passed as shown above)
- The report folder url.
- Notification email address
- mailer settings:
- A simple report schedules list screen.:
- Options for scheduling:
- crontab string,
- Select report from a combo box
- outputfolder
- zip or not to zip
- notify of running by email
- format : valid formats : pdf, doc, ppt, xls..... but not html. A simple downloader that will download a single url will be used. (KISS)
- mail to. (comma seperated destination addresses)
- append a date string to ( low priority )
- A parameters table. Which lists parameter vs. value. Nothing dynamic about it. You need to know the paramter names yourself to be able to use it. (low priority .... make parameters list available once you select the report)
- A reports management screen:
Seems simple enough :) But requires dedicated time.... which I am short on right now.... I need motivation... anyone interested in giving me some?
Optimizing Birt Viewer for solaris in simple steps
Here is how I improved the performance: (Note that I prefer jetty to tomcat due to its lightweight nature ..... Actually I use hightide ... but that's another story)
- Make the default memory allocation greater:
# JAVA_OPTIONS
# Extra options to pass to the JVM
TO:
JAVA_OPTIONS="-server -Xmx3800 -Xms3800"
this basically tells the JVM to run in server mode i.e. -server (slower startup time.... faster execution time :)) and to start of with a default of 4GB ram with a max of 4GB ram (Xmx and Xms) . Change this to how much RAM you want allocated to JVM by default
- Update your BIRT runtime to the latest and greatest version
- Update your JDK to the latest version
After installation it note the location of your installation dir
e.g. /home/bla/Desktop/1.6.13_10
or whatever.
again modify jetty.sh (or hightide.sh) changing:
# JAVA_HOME
# Home of Java installation.
to :
JAVA_HOME="/home/bla/Desktop/1.6.13_10"
Thats all. Now give BIRT a spin. My runtime went from 10 secs to 7 secs :)!!
Monday, May 18, 2009
BIRT dynamic parameters
This post is about a particular scenario in reporting. It relates to time reporting. Most commonly we need trend analysis of the past week to better analyze the data. But you dont want to put in the date / time of the last week manaually. Using oracle BI Publisher I am used to taking care of these using sysdate inside of SQL Queries. But BIRT provides a better way.
Heres a step by step howto.
Create two report parameters. One for start and one for the stop time:
Remeber to uncheck the Is Required property:
This is because we are going to generate the value dynamically in case the parameters are not set :)
Needless to say you need to link these to your query (data set) parameters:
Now click the main surface of your report in the layout tab:
Then click the script tab and add the following code to the initialze event handler as shown:
function getdateBehindByDays(days)
{
var cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.DAY_OF_MONTH, -days);
return (cal.get(java.util.Calendar.MONTH) + 1 ) + "/" + cal.get(java.util.Calendar.DAY_OF_MONTH) + "/" + cal.get(java.util.Calendar.YEAR);
}
if (params["StartTime"].value == null)
{
params["StartTime"].value = getdateBehindByDays(7);
}
if (params["StopTime"].value==null)
{
params["StopTime"].value = getdateBehindByDays(0);
}
What this code is doing is that it is sending the start date back by one week and the stop time to today :). Just change the values '7' and '0' to what you require :)
Now just run the report and set the parameters you want to be made dynamic to null:
Viola! welcome to the wonderful world of automated reporting :)
Solaris Crontab exporting an environment variable
If your bash script has the following code:
export JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide
You would get the following error:
JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide: is not an identifier
This is because cron is run by bourne shell and for that this is not a valid syntax. Bascially you are telling it to export a variable identified as "JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide:" where all you wanted was to export the variable JETTY_HOME.
Resolution: Use two lines instead of one. Modify your script to :
JETTY_HOME=/opt/os/home/efaitan/Desktop/hightide
export JETTY_HOME
Further detail:
The default shell opened for my solaris system was KSH. You can determine the default shell using the $SHELL environment variable. The above export and set in one line in valid for ksh but not valid for bourne shell (normal sh).
It is suggested that you test your scripts in sh before adding them in crontab entries.
Here is a screen shot explaining the root cause of the error:
Enjoy!
Tuesday, May 12, 2009
Oracle Create a table using a query
Joins in LARGE tables are always expensive. Whenever possible they should be catered for in your ETL.
Here's what happened. Ericsson OSS has a table with time and another table with cell stats (many other tables in fact :) ). First I decided to copy the data as it is. However later on I wanted daily averages of counters. The plan was to use a simple view over these two tables for the stats. And then another view which averages this over every day.
The query performance = 54 secs
This is pretty fast considering its all cells for all hours of all days.
But then I read about Oracle function based indices (FBI)! Amazing stuff. I could add the day as an index to the table (using trunc(time,'DD')) . Cool. That should really boast the performance.
However VIEWs don't support indices. (Only materialized views do ... but a materialized view would consume too much space and be an overkill .. just to add indices). So I needed to convert the two tables into a single table.
Using function based index which truncates date I get a query performance = 21 secs.
SQL
So I decided to move the data from those two tables to the new table.
create table yourtable as select * from whatever
This will create the table from the results of your query. Quick and neat way to move data. Love SQL.... Love Oracle!
Monday, May 11, 2009
Oracle Materialized View Refresh using JDBC
I am a big fan of Materialized views. When used effectively it somewhat decreases the requirement to use Oracle Analysis (if all you want is queries and not pivots).
You can refresh a materialized view using the following SQL Script :
execute DBMS_SNAPSHOT.REFRESH('VIEWNAME','c');
Where VIEWNAME is the view you want to refresh.
For a detailed note one the parameters take a look at :
However this is not a valid sql statement.
Using Oracle SQL developer you can execute it using the "Run script" button as shown:
The same error is observed if you were to do the following with jdbc:
stmt = connection.createStatement();
stmt.executeQuery("execute DBMS_SNAPSHOT.REFRESH('VIEWNAME','c')") ;
This is because statements cannot contain calls to stored procedures :). Don't know why, but that's the way it is.
Instead you should do the following:
stmt = connection.prepareCall("call DBMS_SNAPSHOT.REFRESH('VIEWNAME','c')");
stmt.execute();
For sql developer you can just do :
call DBMS_SNAPSHOT.REFRESH('VIEWNAME','c');
It should work like a charm :)
Enjoy!
Saturday, May 9, 2009
getOutputStream() Error in Oracle BI Publisher
getOutputStream() has already been called for this response
This error occurs when you have a user with roles assigned other than administrator and that user tries to access the shared folder.
Anyways got around to fixing it so I thought I'd mention it just in case anyone else encouters the same issue. I guess it is due to a bug in the security error redirector code.
Resolution: You need to share at least one folder to the user.
Stepwise guide :) :
Create new folder in the shared folders directory.
name it whatever you like.
Now go to admin interface and goto Roles and permissions. Create a new role.
Add datasources and any of the preconfigured roles to the newly created role.
Click on Add Folders and add the newly created folder:
Next assign the role to your user :). All set !
Enjoy :)
Friday, May 8, 2009
Crontab Basics on Solaris
First some key useful information.
- Looking at current crons:
- Editing crons:
- Changing the crontab Editor
I prefer gedit to vim or pico :)
- Crontab format
2. hour (from 0 to 23)
3. day of month (from 1 to 31)
4. month (from 1 to 12)
5. day of week (from 0 to 6) (0=Sunday)
e.g:
* * * * * /bin/something.sh
means run something.sh every minute of every hour of every day of every month on all weekdays :)
PERMANENTLY changing your crontab editor preference:
Login using CDE. Open your home folder:
Right click in the open browser and select "Show Hidden Objects" :
Find .profile and add the following line as shown:
export EDITOR="gedit"
Leave anything else intact (unless you want to change something)
Now when you start editor using crontab -e you should get gedit
Enjoy!
Thursday, May 7, 2009
Splitting a string into an array using Oracle
http://www.orafaq.com/forum/t/11692/0/
Suppose you want to say :
select * from oss_cell_view where cell in (:cells)
Running this query in sql developer you get a dialog as:
But here is what sql developer does. Seeing that it is a string input it turn the query into:
select * from oss_cell_view where cell in ('asdf,fdsa')
Whereas what you expect is :
select * from oss_cell_view where cell in ('asdf','fdsa')
(notice the ',' in the middle :) )
Here is the solution:
Create a simple table type:
create or replace type myTableType as table of varchar2(255);
Create a string splitting function (default delimiter is , ):
(p_str in varchar2,
p_delim in varchar2 default ',')
return myTableType
as
l_str long default p_str || p_delim;
l_n number;
l_data myTableType := myTabletype();
begin
loop
l_n := instr( l_str, p_delim );
exit when (nvl(l_n,0) = 0);
l_data.extend;
l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
l_str := substr( l_str, l_n+length(p_delim) );
end loop;
return l_data;
end;
You can test the newly created function:
SELECT column_value
FROM TABLE (CAST (str2tbl ('10,01,03,04,234') AS mytabletype))
Finally you can rewrite your query as :
select * from oss_cell_view where cell in (SELECT column_value FROM TABLE (CAST(str2tbl (:cells) AS mytabletype)))
Enjoy!
Displaying report parameters in Word using BI Publisher
I explain how to do it in oracle. Your SQL Query will vary depeding on your database server e.g oracle uses ':' for named parameters, TopN queries are done using where rownum <>
Things to note:
- put all your parameters in the query e.g. above you see I put BSC (:BSC) and DaysBack (:DaysBack) into the query
- select from a table that has at least one entry :) otherwise no data will be returned from the query. Basically we are selecting the first row but putting are parameters as a column and not showing any of the the original tables columns.
you should do:
select :BSC from dual
- Parameters are case sensitive. Therefore it should be :BSC and not :bsc as shown in the screenshot.
Enjoy!
Wednesday, May 6, 2009
Flex BIRT Report Viewer
This is a simple BIRT report viewer (basically hides BIRT under your customized view).
It uses the famous IFrame code to show a simple web page (retrieved from the BIRT runtime) under a flex application.
It also determines where you are viewing the report (on my pc or on the server) and points to the appropriate location.
Here is a screen shot for you enjoyment. While it runs:
After completion:
All you need to do is change the following in the code :
ReportViewerUrl = "http://localhost:8400/ReportXViewer/"
to point to your server.
Then after deployment you can simply call appending ?__report=yourreport.rptdesign as you normally would with the servlet based report viewer.
Enjoy.
Of course you should change the logo to your own ;)
http://code.google.com/p/birtreportviewer/downloads/list
Major JAVA reporting toolkits review
All of these are great and I have a deep appreciation of the efforts made by open source. Just so you know :
- Jasper : Best open source solution.
Of all these evaluations this was the BEST performing (render speed)
I do not have much need for analysis (since I prefer view / materialized views) and therefore this was ultimate.
Great formating error detection.
Scheduling / email works.
Great (best) Parameter / programmed parameter support.
Clean code ( in case you were wondering about what is under the hood )
My concerns :
No DEFINED table structure. You need to put fields into the details region to make a table. Alignment etc can become an issue.
Comes pre configured with a mysql instance. Moving to a different database is an involved process.
- Pentaho: Really nice and has gathered the most momentum in open source for now.
Analysis. Like I mentioned I do not have much need for this.
Scheduling.
Disadvantages:
The report designers does not (as of version 2. It is planned soon though) have support to preview report with parameters. As far as I know, I see no use of a report without parameters. You need to upload the report to the server to preview such a report.
Update: They have a design studio where it is possible to preview the report in an integrated way (without opening the browser) as well as define action flows .... cool
Query designer kept giving errors (but that didn't bother me since I use SQL Developer anyways). The jasper query designer was much better. It uses netbeans data sources which are highly stable.
- BIRT
By far the most comprehensive report designer. Simply the best!
Disadvantages:
Not the best programmed parameter support. Although much more powerful than jasper (due to its use of java script) but takes a bit of hacking. It does work though ;). Also you need to put parameters as ? in the SQL query and cannot name them till afterwords. (Jasper had a better concept $P ;))
No free scheduling support.
Speed was the major concern. I was close to writing my own scheduling framework when preliminary testing by users was not satisfactory.
- XML Publisher
Disadvantages:
Report design experience: Although they have the best idea (use word!) it keeps hanging from time to time.
Online query designer: I prefer an offline version where queries can be moved from place to place (you can do this by coping the xdo file from the server. But still)
No mouse over chart support like you get with BIRT. Like I said for small number of users with small number of reports. BIRT IS THE BEST.
Advantages:
BEST FORMATING OPTIONS (its word... enough said)
Awesome scheduling. You can send to printer/ fax/ ftp / email and more :). You can also check history etc. Nice admin interface. You can also install the scheduling repository from the web interface (unlike jasper where you need to manually run sql scripts)
Scheduling seems vital to the project. Along with oracle, easy cross platform, and easy template based support. XML Publisher it is :). Not to mention that once I have my oracle backup procedures in place I need to worry a lot less. :). Also the export to excel by XMLP was the best.
PS: I deployed the XMLP war to tomcat (blazeds). It works.