I am setting up a project to take in a decision table as input and create the rules.
Error encountered is "mismatched input 'from' in rule".
Fact set is :
Class Member{
double salary;
List<Tag> tagList;
string ruleResult;
}
Class Tag{
string key;
string value;
}
Decision table:
-----------------------------------------
|| Condition || Condition||
-----------------------------------------
m:Member()
tg:Tag() from tagList
-----------------------------------------
|| key==$param || salary >$1 && salary <$2
-----------------------------------------
|| Tag Conditon || sal condition ||
-----------------------------------------
|| "key1" || 1000,2000 ||
-----------------------------------------
I didnt find much documentation on usage of "from". Any help here to proceed further is greatly appreciated.
DRL example: ( I am expecting this as the output for the rule)
rule "drl_rule"
salience 65535
when
m:Member(tg:tagList,salary>1000 && salary<2000)
Tag(key=="key1", value=="value1") from tg
then
m.setRuleResult("Rule Result1");
end
Related
i'm looking for SKU generator function to generate SKU based on product name, combination of letter and 5 digit unique number in Postgresql.
For example :
generate_sku('GREENFIELDS FULL CREAM MILK')
will return only 3 first word and random number :
GRE-FUL-CRE-987652
Any idea ?
As suggested create a sequence. Since you have a specific value range restrict the range of the sequence. Then create a function which take a single parameter, the name, and returns the SKU. See Fiddle.
create sequence sku_seq
as integer
increment 1
start with 10000
minvalue 10000
maxvalue 99999
no cycle;
create or replace
function item_sku(item_name_in text)
returns text
language sql
immutable strict
as $$
with parm (snam) as
( select string_to_array(item_name_in, ' '))
select sku || to_char(nextval('sku_seq'),'FM99999')
from ( select case
when array_length(snam,1) > 2
then substr(snam[1],1,3) ||'_' ||
substr(snam[2],1,3) ||'_' ||
substr(snam[3],1,3) ||'_'
when array_length(snam,1) = 2
then substr(snam[1],1,3) ||'_' ||
substr(snam[2],1,3) ||'_'
else substr(snam[1],1,3) || '_'
end sku
from parm
) s ;
$$;
We are trying to publish data from a table using U-SQL in ADLA. We are using below code to get substring for FirstName, as we want to restrict the length of FirstName to 50 characters.
SELECT (firstName == null || firstName.Length <= 50) ? firstName : firstName.Substring(0, 50) AS FirstName
But, we are getting below error:
E_RUNTIME_USER_EXPRESSION_EVALUATION >
E_RUNTIME_USER_SUBSTRING_OUT_RANGE
When we tried to perform substring using custom .NET Code, we are not getting exception. The job is completing successfully. We are not getting any error rows.
public static string DoSubString(string firstName)
{
string subFirstName;
try
{
subFirstName = (firstName == null || firstName.Length <= 50) ? firstName : firstName.Substring(0, 50);
}
catch(ArgumentOutOfRangeException ae)
{
subFirstName = string.Format("Argument Out of range Error {0} {1}",firstName,ae.Message);
}
catch(Exception Ex)
{
subFirstName = string.Format("Generic Error {0} {1}",firstName, Ex.Message);
}
return subFirstName;
}
We are not able to find out the error row. When we look into Profile.xml, we are not getting row dump.
Inner exception from user expression: \nCurrent row
dump: "
How to find out the error row causing this exception? How to troubleshoot these kinds of issues ?
For testing I used 10 characters, revise for 50.
#table =
SELECT * FROM
( VALUES
("appleJackss"),
("apple Jacks"),
("appleJacks"),
(" "),
(""),
((string)null)
) AS T(word);
#result =
SELECT //Method 1
CASE
WHEN word.Length <= 10 THEN word
ELSE word.Substring(0, 10)
END AS justTen,
// Method 2
(word.Length <= 10) ? word : word.Substring(0, 10) AS anotherTen
FROM #table;
OUTPUT #result
TO "/Temp/Example1.txt"
USING Outputters.Tsv();
We raised an issue with product group. It seems there is some problem with the substring operation in U-SQL. They asked us to apply the below fix for Substring calculation. We tried it and it is working properly.
SELECT (firstName == null || firstName.Length <= 50) ? firstName : firstName.Substring(0, Math.Min(firstName.Length, 50)) AS FirstName
I've result set from query select * from personal."phoneNumbers" like this
prefix
pref |number
-----|--------
"12 "|"4589524"
"077"|"7090701"
"050"|"2561024"
But I want to return data like
(12) 4589524;(077) 7090701; (050) 2561024
How to do this with postgresql ?
You can use the string operators and functions to construct a single phone number in the format that you want:
'(' || btrim(pref) || ') ' || number
This, obviously, yields a string for each record that you process. You can then use the aggregation function string_agg() to string (no pun intended) the extended phone numbers from all the records together into one, with the appropriate separator between phone numbers:
SELECT string_agg('(' || btrim(pref) || ') ' || number, '; ') AS pref_number
FROM personal."phoneNumbers"
I have a database table with two columns: StartDateTime and FinishDateTime. both are nullable datetime columns.
I'm wanting to calculate the Average time between both fields per row. ie the average duration of my recorded event.
I'm getting a "DbArithmeticExpression arguments must have a numeric common type."
Example EF code with a touch of simplification for the demo.
from p in new DbContext()
where p.user_id = 123
&& p.StartDateTime != null
&& p.FinishDateTime != null
select new {p.StartDateTime, p.FinishDateTime})
.Average(p=> (p.FinishDateTime.Value - p.StartDateTime.Value).Ticks)
I'd love an example of the above, as SQL makes this a breeze.
Its depends on your data provider, it may support DbFunctions and you could do something like this:
(from p in new DbContext()
where p.user_id = 123
&& p.StartDateTime != null
&& p.FinishDateTime != null
select new {p.StartDateTime, p.FinishDateTime})
.Average(x=> DbFunctions.DiffMilliseconds(p.FinishDateTime,p.StartDateTime))
if it doesn't, i think you have to go linq to objects after the select:
(from p in new DbContext()
where p.user_id = 123
&& p.StartDateTime != null
&& p.FinishDateTime != null
select new {p.StartDateTime, p.FinishDateTime})
.ToArray()
.Average(x=> (p.FinishDateTime -p.StartDateTime).Ticks)
I am trying to do log table in dynamodb and my table looks like
Pid[HashKey] || TableName[SecondaryIndex] || CreateDate[RangeKey] || OldValue || NewValue
10 || Product || 10.10.2013 00:00:01 || Shoe || Skirt
10 || Product || 10.10.2013 00:00:02 || Skirt || Pant
11 || ProductCategory || 10.10.2013 00:00:01 || Shoes || Skirts
19 || ProductCategory || 10.10.2013 00:00:01 || Tables || Armchairs
Pid = My main db tables primary key
TableName = My main db table names
CreateDate = Row created date
now I want to get list of
where (Pid = 10 AND TableName = "Product") OR (Pid = 11 AND
TableName="ProductCategory")
in a single request (it wouldn't be so short like this. It could include too many tables and pids)
I tried batchget but I didn't use it because I couldn't query with secondary index. It needs rangekey with equal operator.
I tried query but this time I couldn't send multiple hash key in a same query.
Any ideas or successions?
Thank you.
The problem here is the OR .... Generally you cannot get this where condition with a single query operation without modifying your row,
Solution 1: You have to issue 2 query operations, and append them to the same resultset.
where (Pid = 10 AND TableName = "Product")
union
where (Pid = 11 AND TableName = "ProductCategory")
Those operations should run in parallel to optimize performance.
Solution2: create a field xxx that describe your condition and maintain it on writes, than
you could create a global secondary index on it and perform a single query.