Evaluate Arithmatic Expression coming in input string
Moderators: chulett, rschirm, roy
Evaluate Arithmatic Expression coming in input string
HI All,
I have an input column which holds arithmetic expressions e.g. [(20*5)+9], [(30/5)+4]. I need to evaluate them and send the final value to target system. Any way to achieve this ?
I have an input column which holds arithmetic expressions e.g. [(20*5)+9], [(30/5)+4]. I need to evaluate them and send the final value to target system. Any way to achieve this ?
Goutam Sahoo
Seems like an unusual requirement...
The first thing that comes to mind is to take the expression and put in into a UNIX Korn shell for evaluation inside of the $(( )) syntax:
The first thing that comes to mind is to take the expression and put in into a UNIX Korn shell for evaluation inside of the $(( )) syntax:
Code: Select all
$ echo $((4+5))
9
$ echo $(((20*5)+9))
109
$ echo $(((30/5)+4))
10
$ echo $((7 / 0))
ksh: 7 / 0: 0403-056 Cannot divide by zero.
$ echo $((4 m 3))
ksh: 4 m 3: 0403-057 Syntax error
Choose a job you love, and you will never have to work a day in your life. - Confucius
Or perhaps "bc" at the command line? Or something using C++?
https://stackoverflow.com/questions/342 ... tring-form
In any case... not fun. Leverage the work of others.
https://stackoverflow.com/questions/342 ... tring-form
In any case... not fun. Leverage the work of others.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Premium Member
- Posts: 425
- Joined: Sat Nov 19, 2005 9:26 am
- Location: New York City
- Contact:
Play around to force the evaluation of the string input as arithmetic by using the AsInteger, AsDouble, AsFloat functions. Just pass the input column to one of these and that might do the trick... You might need to enforce the result by multiplying by a constant factor like below....just play around
AsFloat(input arithmetic) * 1
I wonder if in your site the use of Server jobs is allowed? In the old server job any string arithmetic expression will be evaluated as arithmetic plain and simple. You would only need the input column as a derivation to the target column.
Let us know how it goes
AsFloat(input arithmetic) * 1
I wonder if in your site the use of Server jobs is allowed? In the old server job any string arithmetic expression will be evaluated as arithmetic plain and simple. You would only need the input column as a derivation to the target column.
Let us know how it goes
Julio Rodriguez
ETL Developer by choice
"Sure we have lots of reasons for being rude - But no excuses
ETL Developer by choice
"Sure we have lots of reasons for being rude - But no excuses
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Somewhat unrelated. Recently I was installing 11.7 IIS with Enterprise Search, and the delivered Linux server did not have bc installed. That actually caused the installation to fail. Checking for it has since been updated into IBM's installation documentation.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Well, haven't put much thought into this to be honest but you may want to take a shot at seeing how shelling out to use "bc" on each row will work for you. 30K isn't really that large of a volume but the context switching or whatever overhead is added by leveraging something on the command line may or may not be acceptable to your load timings. But seems to me should be the easiest to test. If the overhead is too much then look into something more tightly coupled into the parallel framework, something custom in C++ for example.
What IS your source, by the way? You've not said. Flat file? If so then maybe you could work out a "filter" that would do that for you.
What IS your source, by the way? You've not said. Flat file? If so then maybe you could work out a "filter" that would do that for you.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers