Birt Report Multiple Input Parameter - eclipse

My problem are same with this question
here
I tried the solution at that question but it only work if all the parameter has value, but when there are no value the Birt Report output this error
The following items have errors:
Table (id = 4):
+ Can not load the report query: 4. Errors occurred when generating the report document for the report element with ID 4. (Element ID:4)
Can you guys help me?
Thanks

In that example when the parameter has no value the query is not modified from what you put in the query text box. You could also do something like:
1- put a query in like select * from mytable
2 - Then put a beforeOpen script like:
if( params["myparameterval"] ){
this.queryText = this.queryText + " where col1 = " + params["myparameterval"].value;
}else{
this.queryText = this.queryText + " where col1 = hardcodedvalue"
}

Related

How to get strings separated by commas from a list to a query in PySpark?

I want to generate a query by using a list in PySpark
list = ["hi#gmail.com", "goodbye#gmail.com"]
query = "SELECT * FROM table WHERE email IN (" + list + ")"
This is my desired output:
query
SELECT * FROM table WHERE email IN ("hi#gmail.com", "goodbye#gmail.com")
Instead I'm getting: TypeError: cannot concatenate 'str' and 'list' objects
Can anyone help me achieve this? Thanks
If someone's having the same issue, I found that you can use the following code:
"'"+"','".join(map(str, emails))+"'"
and you will have the following output:
SELECT * FROM table WHERE email IN ('hi#gmail.com', 'goodbye#gmail.com')
Try this:
Dataframe based approach -
df = spark.createDataFrame([(1,"hi#gmail.com") ,(2,"goodbye#gmail.com",),(3,"abc#gmail.com",),(4,"xyz#gmail.com")], ['id','email_id'])
email_filter_list = ["hi#gmail.com", "goodbye#gmail.com"]
df.where(col('email_id').isin(email_filter_list)).show()
Spark SQL based approach -
df = spark.createDataFrame([(1,"hi#gmail.com") ,(2,"goodbye#gmail.com",),(3,"abc#gmail.com",),(4,"xyz#gmail.com")], ['id','email_id'])
df.createOrReplaceTempView('t1')
sql_filter = ','.join(["'" +i + "'" for i in email_filter_list])
spark.sql("SELECT * FROM t1 WHERE email_id IN ({})".format(sql_filter)).show()

npgsql : Selecting a null data throws exception with error "Column is Null"

I am running npgsql v3.7 with .NetCore on Ubuntu.
When I execute a select query and a cell in any row in the results is null, an exception is thrown with the error message "Column is null".
I am having to work around this by putting every column in the select clause inside a case statement which tests for NULL
"CASE WHEN " + fieldName + " IS NULL THEN '' ELSE " + fieldName + " END "
This seems a bit extreme and should not be necessary. Has anyone else come across this.
Thanks.
You are probably trying to read the column like this:
using (var reader = cmd.ExecuteReader()) {
reader.Next();
var o = reader.GetString(0); // Or any other of the Get methods on reader
...
}
This code will fail if the column contains a null, and is the expected behavior. In ADO.NET, you need to check for a null value with reader.IsDBNull(0) before actually getting the value. That's just how the database API works.
I don't know why NULL values are giving you errors, but you can do away with the ugly CASE statement in favor of using COALESCE:
"COALESCE(" + fieldName + ", '')"
Ideally you should make a configuration change such that NULL values do not cause this problem.

Updating values in real time Talend

I'm trying to update my data with talend.I'm using tOracleOutput with the option 'update or insert' but my problem is that when there is an update i want to sum the older and the newer value of a row because my app is executing in real time.There is any help? (sorry for my bad english)
You can use a tOracleRow component containing a SQL update statement . Take the new value (from context, row, or globalMap) and use that in the update statement within tOracleRow, adding it to the existing value of the desired record.
Ex
"
UPDATE target_table
SET target_field = target_field " + globalMap.get("newVal") + "
WHERE target_id = " + globalMap.get("id") + "
"

How to implement raw sql query in Tastypie

I am trying to do this simple query, but it does not work. Thanks.
SELECT * FROM TSimple where (start_date < '2012-04-20' and end_date is null) or
(end_date > '2012-04-20' and start_date < '2012-04-20')
class TSimple (models.Model):
start_date = models.DateTimeField()
end_date = models.DateTimeField(blank=True, null=True)
...
class TSimpleResource(ModelResource):
def dehydrate(self, bundle):
request_method = bundle.request.META['REQUEST_METHOD']
if request_method=='GET':
new_date = bundle.request.GET.get('new_date', '')
qs = TSimple.objects.raw(
'SELECT * FROM TSimple where (start_date<=\'' +
new_date + '\' and end_date>=\'' +
new_date + '\') or (start_date<=\'' + new_date +
'\' and end_date is null)')
ret_list = [row for row in qs]
// NOT WORK. Not able to get correct json data in javascript.
// It needs return bundle. HOW to replace bundle?
// Is this correct way to do it?
return ret_list
else:
// This is ok.
return bundle
I have following questions:
1) (raw sql method) If implementing in dehydrate method is correct way to do it? If it is, above does not work. It should return bundle object. How to construct new bundle?
If above method is ok, I noticed that bundle already constructed .data field with default query(?), which will be thrown away with new query. That raise the questions if this is right way to do it.
2) If there are other raw sql method to do it? Where to execute the sql?
3) How to do it in filter?
4) I know sql and not familiar with complex filter. That's why I am trying to use raw sql method to do quick prototype. What are the draw back? I noticed that using Tastypie has many unnecessary queries which I don't know how to get rid of it. Example, query on table with foreign key trigger query to another table's data, which I don't want to get.
I figure out the filter and it seems worked. But I am still interested in raw sql.
def apply_filters(self, request, applicable_filters):
base_filter = super(TSimpleResource, self).apply_filters(request,
applicable_filters)
new_date = request.GET.get('new_date', None)
if new_date:
qset = (
(
Q(start_date__lte=new_date) &
Q(end_date__gte=new_date)
) |
(
Q(start_date__lte=new_date) &
Q(end_date__isnull=True)
)
)
base_filter = base_filter.filter(qset)
return base_filter

how to call and add conditions in procedures while calling from Ireport?

I have created a report using Ireport 4.5 but report is running very slow I think just because of multiple UNION and JOINS.
I am copying a simple query for testing purpose:-
SELECT b.Project_Id,
b.Project_Manager,
b.project_title,
b.Project_location,
b.Project_Level,
SUM(COALESCE(b.Project_Budget, 0)) Projected,
SUM(COALESCE(c.Accounting, 0)) Actual
FROM t_authorized_budget a, t_project_c b,t_project_allocation c
WHERE a.Project_Id = b.Project_Id and b.project_id=c.`Key`
and a.Project_Id = c.`Key`
and $X{IN,b.project_location,p_project_location}
and $X{IN,b.project_manager,p_project_manager}
and $X{IN,b.project_id,p_project_id};
So I created a procedure CALL GetAllcompo() using this query but without
$X{IN,b.project_location,p_project_location}
and $X{IN,b.project_manager,p_project_manager}
and $X{IN,b.project_id,p_project_id};
Now i am trying to add these conditions in procedure while calling from Ireport.
How can I do that?
Do you need to use the procedure? I do this by adding another parameter. First, prompt the user to define what type of WHERE clause you're using:
$P{PROJECT_PROMPT}
And then create a second parameter ($P{PROJECT_SQL_DEF}) with a default expression that defines your WHERE clause:
$P{PROJECT_PROMPT} == 'SHORT' ?
" ' a.Project_Id = b.Project_Id
and b.project_id=c.Key
and a.Project_Id = c.Key '" :
" ' a.Project_Id = b.Project_Id and b.project_id=c.`Key`
and a.Project_Id = c.`Key`
and $X{IN,b.project_location,p_project_location}
and $X{IN,b.project_manager,p_project_manager}
and $X{IN,b.project_id,p_project_id} ' "
In your query:
SELECT b.Project_Id,
b.Project_Manager,
b.project_title,
b.Project_location,
b.Project_Level,
SUM(COALESCE(b.Project_Budget, 0)) Projected,
SUM(COALESCE(c.Accounting, 0)) Actual
FROM t_authorized_budget a, t_project_c b,t_project_allocation c
WHERE $P!{PROJECT_SQL_DEF}