Jump to content
We've recently updated our Privacy Statement, available here ×

brice.montandon
Go to solution Solved by bobtins,

Recommended Posts

Hi,

 

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.

Brice

 

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

After some more investigations I've retrieved the full error message.

Here is the interesting part :

Error Message

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.

 

Brice

Link to comment
Share on other sites

  • Solution

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[0] + ", " + sqlArgs[1] + (sqlArgs.size() == 3 ? (", " + sqlArgs[2]) : "") + ")"</value>                </entry>[/code]

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...