How to check if value in field is decimal and not string (DATASTAGE)? - datastage

How to check if value in field is decimal and not string (DATASTAGE) ?
I am using with Datastage Version 8.

Try using IsValid() with the 'decimal' sub-type on the incoming string.
If IsValid("decimal" , in.value_string ) Then in.value_tring Else SetNull()

You can use Alpha & num function inside transformer which gives you whether the given value contains only alphabets.
If alpha(column) is 1 then its purely alphabetical.
Else check if Num(column) is 1, if this true then it is purely a number.
Reference to official doc-https://www.ibm.com/support/knowledgecenter/SSZJPZ_11.5.0/com.ibm.swg.im.iis.ft.usage.doc/topics/r_deeref_String_Functions.html

Related

How to interpret indexof expression and functions in Azure Data Factory

I'm trying to understand the indexof expression(function) of Azure Data Factory.
Example
This example finds the starting index value for the "world" substring in the "hello world" string:
indexOf('hello world', 'world')
And returns this result: 6
I'm confused by what is meant by the 'index value' and how the example arrived at the result 6.
Also, using the above example, can someone let me know what would be the answer for the following expression?
#if(greater(indexof(string(pipeline().parameters.Config),'FilenameMask'),0),pipeline().parameters.Config.FilenameMask,'')
indexof
{"FilenameMask":"accounts*."}
'Config' represents a field in sql database
Per the docs:
Return the starting position or index value for a substring. This function is not case-sensitive, and indexes start with the number 0.
hello world
01234567890
^
+--- "world" found starting at position 6
Regarding the 2nd part of your question. Here's the expression re-written for a bit of clarity:
#if( greater(indexof(string(pipeline().parameters.Config),'FilenameMask'),0)
,pipeline().parameters.Config.FilenameMask
,'')
which can be read as follows:
if the index of the string "FilenameMask" within x is greater than 0 then
return x.Filenamemask
else
return an empty string
where x is pipeline().parameters.Config, which is the value of your "Config" column from the database table. It will hold values such as
{"sparkConfig":{"header":"true"},"FilenameMask":"cashsales*."}
and
{"FilenameMask":"accounts*."}
The ADF expression can also be read as follows:
if the JSON in the Config column contains a "FilenameMask" key then
return the value of the FilenameMask key
else
return an empty string

Issue with conversion from string to double

I am not able to convert my string to double.I am getting below error
conversion from string to double is not valid
I have tried below approach but all are giving me same error. I am using Assign activity in uipath with intvalue defined as double and row.Item("TaxResult") retrieves the value from excel
intval = Val(row.Item("Tax Result").ToString.Trim)
intVal = Double.Parse(row.Item("Tax Result").ToString.Trim , double)
intVal = cDbl(row.Item("Tax Result").ToString.Trim)
Out of the above three first one is returning to me 0 value while the below two is giving me an error
"conversion from string to double is not valid"
Tax Result column in excel stores the value like (5.2, 19.8, 98.87). I want to sum all these value as part of my requirement
First, you don't need the .Item after row, it should just be row("Tax Result")
Ideally you should use a Double.TryParse() to try and avoid any exceptions if it cant convert to Double.
This can be achieved using an If Statement as seen below, if the Try Parse is successful the string can be converted using Double.Parse(row("Tax Result").ToString.Trim) and on failure I have assigned intval to 0 but you could put handling here to handle if it can't convert the number

SSRS nested IIF/CStr explanation

Could someone let me know if the IIF statement below means output any value that starts with a 4 please?
=IIF(LEFT(CStr(Fields!CLOCK_NUMBER.Value),1)="4",Fields!JOB_NO.Value, "")
The short answer is yes.
Starting from the middle and working outwards this expression is doing the following..
Get the value of the field CLOCK_NUMBER
Convert this to a string (the CSTR function)
Take the 1st character (LEFT function with 1 as the seconds parameter)
If the equals "4" return the Value that is in JOB_NO
Otherwise return an empty string
If this is not working for some reason, try converting the job_no to a string before returning, that way you ensure you always return a string (in case JOB_NO is numeric). You can simply wrap the job_no in a CSTR like this CSTR(Fields!JOB_NO.Value)
Translates to..."try to" convert the field CLOCK_NUMBERS's native value to a string and take the LEFT(1) most significant digit(s) and if that value is "4" then return the JOB_NO Fields's value. else return empty string.
So, it is, if the first digit is 4 then return JOB_NO.

String to Integer (atoi) [Leetcode] gave wrong answer?

String to Integer (atoi)
This problem is implement atoi to convert a string to an integer.
When test input = " +0 123"
My code return = 123
But why expected answer = 0?
======================
And if test input = " +0123"
My code return = 123
Now expected answer = 123
So is that answer wrong?
I think this is expected result as it said
Requirements for atoi:
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
Your first test case has a space in between two different digit groups, and atoi only consider the first group which is '0' and convert into integer

how to change display in gtk.spinbutton

I have a gtk.spinbutton and I want to set the digits according to the locale
format.
like say I have a locale installed hungarian so my decimal separator is
'.'(dot) and thousand separator is ','(comma) eg: my spinbutton value is
1131191 so after the user focus out of the gtk.spinbutton my value should
convert to 11,311.91 . the conversion is made by me but I am not able to set
it to gtk.spinbutton either using set_text / set_value method.
Any help is appreciated !
Thanks
Formatting a SpinButton can be done by handling the output signal.
locale.setlocale(locale.LC_ALL, '')
def output(spin):
digits = int(spin.props.digits)
value = spin.props.value
text = locale.format('%.*f', (digits, value), True)
spin.props.text = text
return True
spin.connect('output', output)
If you also want to let users enter values in the localised format (e.g. let the user type "1,000" instead of "1000"), handle the input signal.
def input(spin, new_value):
text = spin.props.text
try:
value = locale.atof(text)
except ValueError:
return -1
p = ctypes.c_double.from_address(hash(new_value))
p.value = value
return True
spin.connect('input', input)
(This code is longer than it should be because PyGTK does not properly wrap input, hence the ctypes hack. It's just parsing the text and then assigning the numeric value to a pointer location.)
Credits: The ctypes hack and digits formatting are inspired by Tim Evans's post in the PyGTK mailing list.