I have a FILTER BY component with this select-expression: switch (${FILTER_ID}) /* switch (‘${FILTER_ID}’) better? */ case ‘407’ : business_line == ‘400’ ; case ‘427’ : business_line == ‘400’ ; case ‘457’ : business_line == ‘450’ ; case ‘507’ : business_line == ‘500’ ; default : ‘0’ ; end FILTER_ID is something I created via Edit->Parameters as a parameter global to the whole graph. It is a String and under advanced attributes, I have chosen $ substitution instead of $ {substitution). I dont really know what the two options actually matter. But continuing, since FILTER_ID is a string, I am using case ‘407’ instead of case 407. Using 407 without quotes was actually parsed as a valid expression, but that doesnt make sense because FILTER_ID is a string. The error I am getting when validating is ““Invalid Expression: Type mismatch. Can’t combine string(3) and long in switch statement”” And the error perplexes me. There is no long anywhere from what I can see. And if FILTER_ID is a string then it should combine with the string(3), '407 in this case.
metaperl via abinitio-l wrote:
FILTER_ID is something I created via Edit->Parameters as a
parameter global to the whole graph. It is a String and under
advanced attributes, I have chosen $ substitution instead of $
{substitution). I dont really know what the two options actually
matter.
If you are not using references to other values in your parameter
FILTER_ID you can set interpretation to constant. Use the ${} for the FBE.
Ok, see your need now. Did you try using a string literal for the switch
clause, eg switch( ‘407’ ) ?
IT appears that this is exactly what he is looking for - whenever the
filter ID is X then only keep the record where the business_line is also
X - the switch provides for a mapping scenario -
Whew!
This solution screams for a lookup file - put the lookup values in the
lookup file and if you get a “hit” then keep the record - this allows
you to change the “hit” values without having to edit the graph. I have
a personal aversion for hard-wiring “magic numbers” into the code like
this.
sigsev - what would you use in a FILTER BY expression? wouldn’t you use == to decide whether or not to filter based on some rule.
all i am trying to say is:
The acceptable records will be chosen based on business_line’s value on the input port. The appropriate value of business_line is a function of FILTER_ID.
so, switch(“${FILTER_ID}”)
case “this” : business_line == “400”
is saying:
if FILTER_ID is “this” then business_line must be “400” for this record to pass the filter component.
sigsev - I dont want an assignment. business_line comes in on the input port. The previous component did a SELECT business_line from table.
So this component is a FILTER BY component which only lets through records where
business_lines == ‘value’
so == is needed instead of =
There is a difference between a switch expression and a switch statement.
Chris is giving an example of a switch expression. I guess your example
should be a switch statement(change the == to =)
regards Eric
Chris - first off your syntax
switch ($‘{FILTER_ID}’)
did not parse… it looks odd. if FILTER_ID is something that is set via
Edit → Parameters as a string, then either ${FILTER_ID} or $FILTER_ID
would make sense.
Chris - first off your syntax
switch ($‘{FILTER_ID}’)
did not parse… it looks odd. if FILTER_ID is something that is set via Edit → Parameters as a string, then either ${FILTER_ID} or $FILTER_ID would make sense.
But anyway maybe some background would help. The component prior to this is an input table. The SELECT statement pulls out several fields from a table, one of which is a string field called business_line.
So the idea is that this graph is being run and only records with a certain value of business line should continue in the dataflow.
In other words if I were doing pure Python or a standard agile language this component and the prior would simply be:
bizline = dict(
‘407’ : ‘400’,
‘427’ : ‘400’,
‘457’ : ‘450’,
‘507’ : ‘500’
)
bl = bizline[fid]
SELECT * FROM table
WHERE business_line = bl
but instead I have one component which is an input table which read all records regardless of business_line and then the next component only allows records of a particular business_line to continue in the flow based on the Parameter FILTER_ID…
and FILTER_ID is set for the whole graph via Edit → Parameters.
So my boolean tests for the value of business_line are designed to do what one would normally do in the WHERE part of a normal SQL query so you only get certain rows.
The expression business_line == ‘400’ evaluates to an integer, can be the
source of your problem. Did you by mistake write the == instead of the
single assignment business_line = ‘400’ ?
Hi Metaperl -
Looks like an assignment, rather than an expression that would decide if to
filter or not ?
Maybe this is what you want
switch ($‘{FILTER_ID}’) /* switch (‘${FILTER_ID}’) better? /
case ‘407’ : 1; / business_line == ‘400’ /
case ‘427’ : 2; / business_line == ‘400’ /
case ‘457’ : 3; / business_line == ‘450’ /
case ‘507’ : 4; / business_line == ‘500’ */
default : ‘0’ ;
end
Cheers
Chris
Pinky Ltd - Big Data Done Right
Ab Initio Certified
Ab Initio-l Community Leader
c: +44 7930 909 297
w: www.pinky.co.uk