Drool syntax: rule not fire with ',' syntax but works with ' ,' (with an additional space before comma) - drools

I'm running into a weird issue that the drool rule does not give exceptions if the line ends in ',' but gives exception if there are additional space before comma (' ,'). Does anyone know why this is happening? The data comes from kafka and I'm expecting an exception printout. Is this related to how drool parse the argument? Thank you! Below are two examples.
//Case 1: not giving anything
when
App(
AppId == $inputId,
source == "APP_STORE"
)
then
System.out.println("Exception Caught!");
//Case 2: Can print out exception
when
App(
AppId == $inputId ,
source == "APP_STORE"
)
then
System.out.println("Exception Caught!");

Just to close the conversation, not sure if this is exclusive to my case.
But the issue got resolved after adding a space before the comma
AppId == $inputId ,

Related

window functions( lag) implementation and the use of IsNotIn in pyspark

Below is the T-SQL code attached. I tried to convert it to pyspark using window functions which is also attached.
case
when eventaction = 'OUT' and lag(eventaction,1) over (PARTITION BY barcode order by barcode,eventdate,transactionid) <> 'IN'
then 'TYPE4'
else ''
end as TYPE_FLAG,
Pyspark code giving error using window function lag
Tgt_df = Tgt_df.withColumn(
'TYPE_FLAG',
F.when(
(F.col('eventaction')=='OUT')
&(F.lag('eventaction',1).over(w).isNotIn(['IN'])),
"TYPE4"
).otherwise(''))
But it's not working. What to do!?
It is giving you an error because there is no isNotIn method for columns object.
That would have been obvious if you just posted the error message...
Instead, use the ~ (not) operator.
&( ~ F.lag('eventaction',1).over(w).isin(['IN'])),
List of available methods are in the official documentation.

REGEXP_LIKE in DB2 v7r1 (7.1?)

From,
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/db2/rbafzregexp_like.htm
SELECT PID FROM PRODUCT
WHERE NOT REGEXP_LIKE(pid,'[0-9]{3}-[0-9]{3}-[0-9]{2}')
But when I run a similar command,
SELECT MYCOLUMN FROM MYTABLE
WHERE NOT REGEXP_LIKE(MYCOLUMN,'[0-9]{3}-[0-9]{3}-[0-9]{2}')
I get
SQL State: 42601 Vendor Code: -104 Message: [SQL0104] Token
was not valid. Valid tokens: < > = <> <= !< !> !=
= ¬< ¬> ¬= IN. Cause . . . . . : A syntax error was detected at token . Token is not a valid
token. A partial list of valid tokens is < > = <> <= !< !> != >= ¬<
¬> ¬= IN. This list assumes that the statement is correct up to the
token. The error may be earlier in the statement, but the syntax of
the statement appears to be valid up to this point. Recovery . . . :
Do one or more of the following and try the request again: -- Verify
the SQL statement in the area of the token .
Correct the statement. The error could be a missing comma or
quotation mark, it could be a misspelled word, or it could be related
to the order of clauses.
-- If the error token is , correct the SQL statement because it does not end with a valid clause.
Is there any reason why this example does not work? Is IBM v7r1 not the same as 7.1?
7.1 and v7r1 are the same thing...
The regular expression support was added as part of technology refresh (TR) level 9
From a command line, use the Work with PTF Groups (WRKPTFGRP) command
WRKPTFGRP PTFGRP(SF99707) PTFGRPLVL(*INSTALLED)
Also, you need to have 5770-SS1 Option #39 International Components for Unicode insallted. You can use the Display Software Resources (DSPSFWRSC) to check for that.
If that's not installed, you'd see a message:
SQL0204 - QQQSVREG in QSYS type *SRVPGM not found.

Hive query failing with analysis exception

hc.sql("select SpecialityId, IsAvailable from Provider_Speciality where ProviderId in ('330003','330004','333301') and SpecialityId = 'Splty101';");
The above query is failing with org.apache.spark.sql.AnalysisException: cannot recognize input near ''Splty101'' ';' '' in expression specification; line 1 pos 3195.
I am using Hive on Spark-scala here.
However, it is running fine when I run it from hive CLI, there is no issue at all.
Can anyone please help me finding the issue here.
Please remove the semi-colon (;) from the end of the query

Reuse of conditions (when) in Drool DSL statements

Is it possible to reuse a when/condition statement into another when/condition statement in a DSL file?
For example, I have two conditions:
[condition][]The client is invalid = Client( name == null || email == null )
[condition][]All the clients are invalid = forall( Client( name == null || email == null ) )
Note that the second condition just diff the first for the forall command, but the statement inside is equals. In these case, I want to reuse the first condition into the second.
Is it possible? How?
Thank you.
even the most recent version of drools will only let you substitute values into a template from pojo's or a corresponding map as per their documentation here.
This won't work for your use case though.
Since drool files are simply text files, there is nothing preventing you from considering a more powerful templating toolkit.
Possibilities include Apache Velocity, ANTLR or Scala!

postgres coldfusion concatenation of string inside cfquery tag

<cfquery name="LOCAL.qrySelEvents" datasource="#variables.datasourceSettings.getDatasourceName()#" result="LOCAL.qryData" >
SELECT evt_id,
acnt_dba_name,
form_id,
'#application.portals.data[request.applicationName].profileRootPath#form/index.cfm'
|| CHAR(63)
|| 'PKformID= '
|| #preserveSingleQuotes(LOCAL.formIdSql)# AS primaryFormURL,
FROM events
</cfquery>
I have to concat #application.portals.data[request.applicationName].profileRootPath#form/index.cfm with char(32) and PKformID= ' || #preserveSingleQuotes(LOCAL.formIdSql)#. I have used the || operator of postgres. But it is giving me an error:
ERROR: syntax error at or near "||"
Can you please help me in this?
The last line of your select clause has a comma at the end.
OK, as well as the error message, if you have ROBUST EXCEPTION HANDLING switched on (it's in CFAdmin), you should get back the SQL that CF was passing to the server. This should show you where the syntax error is in your SQL. You should also always post this info in your question, so even if you can't see the problem, someone else might be able to.
Now I suspect it's because this:
#preserveSingleQuotes(LOCAL.formIdSql)#
needs to be treated as a string (which it is), in which case you'll need to quote it for the DB to see it as a string. IE:
'#preserveSingleQuotes(LOCAL.formIdSql)#'
Given there is no DB-centric references in that whole value:
`'#application.portals.data[request.applicationName].profileRootPath#form/index.cfm' || CHAR(63) || 'PKformID= ' || '#preserveSingleQuotes(LOCAL.formIdSql)#'`
I question why you need to include it in your SELECT query. You're basically just passing the value to the SQL server, and just getting it back again afterwards. So I suspect something is amiss here. What are you actually trying to do here?
Ya finally got the answer of this , CHAR(63) is creating problem in this as in Sql-server CHAR is a function which gives Character from ASCII and in postgresql CHR() function is available in order to give character from ASCII. So , new Query is :
<cfquery name="LOCAL.qrySelEvents" datasource="#variables.datasourceSettings.getDatasourceName()#" result="LOCAL.qryData" >
SELECT evt_id,
acnt_dba_name,
form_id,
'#application.portals.data[request.applicationName].profileRootPath#form/index.cfm'
|| CHR(63)
|| 'PKformID= '
|| #preserveSingleQuotes(LOCAL.formIdSql)# AS primaryFormURL
FROM events
</cfquery>
Thanks for all your support.