SpagoBI multi value parameter - java

I'm trying to create a multi-value parameter in SpagoBI.
Here is my data set query whose last line appears to be causing an issue.
select C."CUSTOMERNAME", C."CITY", D."YEAR", P."NAME"
from "CUSTOMER" C, "DAY" D, "PRODUCT" P, "TRANSACTIONS" T
where C."CUSTOMERID" = T."CUSTOMERID"
and D."DAYID" = T."DAYID"
and P."PRODUCTID" = T."PRODUCTID"
and _CITY_
I created before open script in my dataset which looks like this:
this.queryText = this.queryText.replace(_CITY_, " CUSTOMER.CITY in ( "+params["cp"].value+" ) ");
My parameter is set as string, display type dynamic list box.
When I run the report I'm getting that error.
org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "
this.queryText = this.queryText.replace(_CITY_, " CUSTOMER.CITY in ( "+params["cp"].value+" ) ");
":
Fail to execute script in function __bm_beforeOpen(). Source:
Could anyone please help me?

Hello I managed to solve the problem. Here is my code:
var substring = "" ;
var strParamValsSelected=reportContext.getParameterValue("citytext");
substring += "?," + strParamValsSelected ;
this.queryText = this.queryText.replace("'xxx'",substring);
As You can see the "?" is necessary before my parameter. Maybe It will help somebody. Thank You so much for Your comments.

If you are using SpagoBI server and High charts (JFreeChart Engine) / JSChat Engine you can just use ($P{param_url}) in query,
or build dynamic query using Java script / groovy Script
so your query could also be:
select C."CUSTOMERNAME", C."CITY", D."YEAR", P."NAME"
from "CUSTOMER" C, "DAY" D, "PRODUCT" P, "TRANSACTIONS" T
where C."CUSTOMERID" = T."CUSTOMERID"
and D."DAYID" = T."DAYID"
and P."PRODUCTID" = T."PRODUCTID"
and CUSTOMER."CITY" in ('$P{param_url}')

Related

How to generate runtime data using DB stored GString definitions

Hi how can I use database stored GString definitions for dynamically generated data. I was able to use GString for pick and choose row attributes if format is defined in the code
code_format = "${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}"
However if same definition is extracted from database my code is not working.
Sql sql = Sql.newInstance(url, login, password, driver);
sql.eachRow(SQL) { row ->
code_format = "${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}"
database_format = "${-> row.REPORT_ATTRIBUTES}"
println "1- " + code_format
println "2- " + database_format
println "CODE : " + code_format.dump()
println "DB : " + database_format.dump()
}
When I run this code I am getting following output;
1- FlowerHouse Joe
2- ${-> row.ACCOUNT} ${-> row.ACCOUNT_OWNER}
CODE : <org.codehaus.groovy.runtime.GStringImpl#463cf024 strings=[, , ] values=[GString$_run_closure1_closure2#44f289ee, GString$_run_closure1_closure3#f3d8b9f]>
DB : org.codehaus.groovy.runtime.GStringImpl#4f5e9da9 strings=[, ] values=[GString$_run_closure1_closure4#11997b8a]
row.REPORT_ATTRIBUTES returns String because database doesn't know groovy stings format.
GString is template, which can be created from string.
So you can do something like:
def engine = new groovy.text.SimpleTemplateEngine()
println engine.createTemplate(row.REPORT_ATTRIBUTES).make([row:row]).toString()

character of ms-access not found on java [duplicate]

I am executing following query from my web application and access 2007 query wizard. And I am getting two different result.
SELECT R.Rept_Name, D.Dist_Name,S.State_Name FROM (tblReporter AS R LEFT JOIN tblDist AS D ON R.Dist_Id=D.Dist_Id) LEFT JOIN tblState AS S ON S.State_Id=R.State_Id WHERE R.Rept_Name LIKE '*Ra*' ORDER BY R.Rept_Name;
Result from web application is with 0 rows and from query wizard 2 rows.If I remove where condition than both result are same. Please help me what is wrong with query. If any other info require please tell me.
Web application code ...
public DataTable getRept(string rept, string mobno)
{
DataTable dt = new DataTable();
using (OleDbConnection conn = new OleDbConnection(getConnection()))
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT R.Rept_Name, D.Dist_Name,S.State_Name FROM (tblReporter AS R LEFT JOIN tblDist AS D ON R.Dist_Id=D.Dist_Id) LEFT JOIN tblState AS S ON S.State_Id=R.State_Id WHERE R.Rept_Name LIKE '*" + rept + "*' ORDER BY R.Rept_Name;";
conn.Open();
using (OleDbDataReader sdr = cmd.ExecuteReader())
{
if (sdr.HasRows)
dt.Load(sdr);
}
}
}
return dt;
}
You are getting tripped up by the difference in LIKE wildcard characters between queries run in Access itself and queries run from an external application.
When running a query from within Access itself you need to use the asterisk as the wildcard character: LIKE '*Ra*'.
When running a query from an external application (like your C# app) you need to use the percent sign as the wildcard character: LIKE '%Ra%'.

How do I build a SPARQL list input using jena querybuilder?

I have a bunch of code that uses the Apache Jena querybuilder API (SelectBuilder class). I am trying to add a term like this to my existing SPARQL query:
(?a ?b ?c) :hasMagicProperty ?this .
I have verified that this query works in TopBraid, but I can't figure out how to represent (?a, ?b, ?c) in the Jena API. What do I have to do to convert this list of Vars into a valid Jena resource node?
I am willing to explore alternate SPARQL-building frameworks, if they have robust support for typed literals, IRIs, and filters, as well as this list construct. I have skimmed over several other frameworks for building up SPARQL queries, but none of them seem to have a list construct.
Edit
My query building code (in Groovy) looks something like this:
def selectBuilder = new SelectBuilder()
selectBuilder.addPrefixes(...)
def thisVar = Var.alloc('this')
selectBuilder.addOptional(thisVar, 'rdf:type', ':MyEntity')
def aVar = Var.alloc('a')
def bVar = Var.alloc('b')
def cVar = Var.alloc('c')
List<Var> abc = [aVar, bVar, cVar]
//this doesn't work!!!
selectBuilder.addWhere(abc, ':hasMagicProperty', thisVar)
selectBuilder.addWhere(aVar, ':hasACode', 'code A')
selectBuilder.addWhere(bVar, ':hasBCode', 'code B')
selectBuilder.addWhere(cVar, ':hasCCode', 'code C')
def sparqlQuery = selectBuilder.buildString()
I have spent a couple of hours trying to work with the RDFList class, and I haven't figured it out. I'll keep trying, and see if I can grok it. In the meantime, any help would be appreciated. :)
Edit
Here is an unsuccessful attempt to use RDFList:
//this code does not work!
def varNode = NodeFactory.createVariable('a')
def model = ModelFactory.createDefaultModel()
def rdfNode = model.asRDFNode(varNode)
def rdfList = new RDFListImpl(model.createResource().asNode(), model)
//this line throws an exception!!
rdfList.add(rdfNode)
selectBuilder.addWhere(rdfList, ':hasMagicProperty', thisVar)
//com.hp.hpl.jena.shared.PropertyNotFoundException: http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
The following method is a workaround, using multiple triples to recursively build up the RDF list:
/*
* Jena querybuilder does not yet support RDF lists. See:
* http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections
*/
private Node buildRdfCollection(SelectBuilder queryBuilder, List<?> itemList) {
if (itemList.isEmpty()) {
return RDF.nil.asNode()
}
def head = itemList.first()
def rest = buildRdfCollection(queryBuilder, itemList.subList(1, itemList.size()))
def listNode = NodeFactory.createAnon()
queryBuilder.addWhere(listNode, RDF.first, head)
queryBuilder.addWhere(listNode, RDF.rest, rest)
return listNode
}
...
def listNode = buildRdfCollection(queryBuilder, abc)
queryBuilder.addWhere(listNode, ':hasMagicProperty', thisVar)
The generated SPARQL code looks like this:
_:b0 rdf:first ?c ;
rdf:rest rdf:nil .
_:b1 rdf:first ?b ;
rdf:rest _:b0 .
_:b2 rdf:first ?a ;
rdf:rest _:b1 ;
:hasMagicProperty ?this .
This is a long-winded equivalent to:
(?a ?b ?c) :hasMagicProperty ?this .
I wrote the queryBuilder and I don't think that in it's current state it will do what you want. Query builder is based on (but does not yet fully implement) the w3c SPARQL 1.1 recommendation:
http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rQuery
However, I think you can create your query using the Jena QueryFactory
String queryString = "SELECT * WHERE { "+
" OPTIONAL { ?this a :MyEntity } ."+
" (?a ?b ?c) :hasMagicProperty ?result . "+
" ?a :hasACode 'code A' . "+
" ?b :hasACode 'code B' . "+
" ?c :hasACode 'code C' ."+
" }";
Query query = QueryFactory.create(queryString) ;
Unfortunately, I don't think this is what you really want. Notice that ?this is not bound to any of the other statements and so will produce a cross product of all :MyEntity type subjects with the ?a, ?b, ?c and `?result`` bindings.
If you can create the query with QueryFactory, I can ensure that QueryBuilder will support it.
UPDATE
I have updated QueryBuilder (the next Snapshot should contain the changes). You should now be able to do the following:
Var aVar = Var.alloc('a')
Var bVar = Var.alloc('b')
Var cVar = Var.alloc('c')
selectBuilder.addWhere(selectBuilder.list(aVar, bVar, cVar), ':hasMagicProperty', thisVar)
selectBuilder.addWhere(aVar, ':hasACode', 'code A')
selectBuilder.addWhere(bVar, ':hasBCode', 'code B')
selectBuilder.addWhere(cVar, ':hasCCode', 'code C')
If you can also simply add the standard text versions of values in the list parameters like:
selectBuilder.list( "<a>", "?b", "'c'" )

How to convert a string to camel case in phpstorms (velocity based) file tempates?

What I've tried so far is:
## $NAME is something like 'my_controller_c'
#set($NAME = $NAME.removeAndHump($NAME))
#set($NAME = $NAME.underscoresToCamelCase(String)
But that does not work. The first one does nothing, the second one throws an java error.
I also tried using regular expressions and to loop through the string, but my java knowledge is very basic.
The following works in PhpStorm 9 (and probably all of the other JetBrains IDEs, I would guess):
#set($new_name = ${StringUtils.removeAndHump(${NAME}, "-")})
class $new_name {
}
This is, what I ended up doing:
#set($ctrlName = $NAME.replaceAll("-c$", ""))
#set($ctrlNewName = "")
#foreach($str in $ctrlName.split("-"))
#set($str = $str.substring(0,1).toUpperCase()+$str.substring(1))
#set($ctrlNewName = $ctrlNewName + $str)
#end
#set ( $ctrlNewName = $ctrlNewName + "Ctrl" )

How can I do this inner join properly in Apache PIG?

I have two files, one called a-records
123^record1
222^record2
333^record3
and the other file called b-records
123^jim
123^jim
222^mike
333^joe
you can see in file A that I have the token 123 one time. In file B it's in there twice. Is there a way using Apache PIG I can join the data such that I only get ONE joined record from the A file?
here is my current script which outputs the following below
arecords = LOAD '$a' USING PigStorage('^') as (token:chararray, type:chararray);
brecords = LOAD '$b' USING PigStorage('^') as (token:chararray, name:chararray);
x = JOIN arecords BY token, brecords BY token;
dump x;
which yields:
(123,record1,123,jim)
(123,record1,123,jim)
(222,record2,222,mike)
(333,record3,333,joe)
when what I REALLY want is(notice token 123 is only in there once after the join)
(123,record1,123,jim)
(222,record2,222,mike)
(333,record3,333,joe)
any ideas? thanks so much
I would do something like this :
arecords = LOAD '$a' USING PigStorage('^') as (token:chararray, type:chararray);
brecords = LOAD '$b' USING PigStorage('^') as (token:chararray, name:chararray);
bdistinct = DISTINCT brecords;
x = JOIN arecords BY token, bdistinct BY token;
dump x;

Categories

Resources