I'm trying to create a calculated field in an Ad Hoc view.
I'm using Jasper Report Sever 6.0.1.
I'm not trying to create a calculated measure but a calculated field.
So in my Ad Hoc view, I am selecting "Create calculated field".
In Formula I'm tiping : Mid("Account Id",1,4)
where "Account Id" return a string made of numbers.
I click on validate button and reached a "Validation successful!" message.
So I save it.
Once I'm trying to use it in the Ad Hoc view it raises message :
"An error occured while performing the previous request".
I really don't know what happens.
I've noticed that if I created by using feature "Create Calculated Measure" it works better.
I can integrate it as a measure but it's not working as I want cause it is not a measure but a dimension.
Any idea on how it should work ?
Thanks in advance.
The definition of the Mid function is in the form of a Groovy language snippet which is part of the SQLGenerator bean.
This definition is in WEB-INF/applicationContext-semanticLayer.xml.
There is a defaultSQLGenerator bean which defines the Mid function this way:
<entry key="Mid"> <value>"substr(" + sqlArgs + ", " + sqlArgs + (sqlArgs.size() == 3 ? (", " + sqlArgs) : "") + ")"</value> </entry>
If you only need to get Redshift working for domains, then you can change this default definition so it uses "substring" instead of "substr".
If you need to get other data sources working, then this config change may affect the Mid function for other datasources, and you would have to configure a Redshift-specific SQLGenerator. Try changing the default and see how that works.
After some more investigations I've retrieved the full error message.
Here is the interesting part :
org.postgresql.util.PSQLException: ERROR: function SUBSTR does not exist (Hint: use SUBSTRING instead)
We are using Jasper in Amazon and our data source is stored in a Redshift DB.
Recomendations for Redshift access is to use PostgreSql JDBC driver.
In Jasper Mid function is mapped to SUBSTR PostgreSql function, when in Redshift SUBSTR doesn't exist and should be repaced by SUBSTRING, exactly what I got in error message.
Now I will have to look for the function template file dedicated to Postgresql on Jasper Server and change function definition.
I will try to comment this ticket if it works.