oracle equivalent 'IN' function in informatica - informatica

I can't believe it's so hard to find an example in informatica documentation.
I would like to check if a string column that matches any of the following strings: 'A', 'B', 'C'
In Oracle, it would be as simple as:
where column in ('A', 'B', 'C')
I have the following in the expression component
iif(column in ('1','2','3'), 'apple', iif(column in ('4','5','6','7','8'), 'orange', 'Unknown'))
and I got syntax error

Informatica has in() clause. Here is the syntax in (data_col, 'val1','val2', [case_flag]).
case_flag - This can be 0 for case insensitive comparison, and non zero/default int is case sensitive.
This returns 0 for false and 1 for True.
You can change your code like -
iif(in (column,'1','2','3')=1, 'apple',
iif(in (column , '4','5','6','7','8')=1, 'orange', 'Unknown')
)
This search is case sensitive and does an exact match.

Related

Unable to cast redshift column to integer due to empty values

I have a redshift table with a column which has empty values rarely. It is expected to have only integer values but some places empty values exist. When I try to cast it using :: it throws error -
[Code: 500310, SQL State: XX000] [Amazon](500310) Invalid operation: Invalid digit, Value 'B', Pos 0, Type: Integer
Details:
-----------------------------------------------
error: Invalid digit, Value 'B', Pos 0, Type: Integer
code: 1207
context: BEVEL_ON
query: 34112149
location: :0
process: query1_836_34112149 [pid=0]
-----------------------------------------------;
So to clarify you have a text column that contains numeric characters most of the time and you want to case this to integer, right? It also sounds like you believe that the only only non-numeric values are the empty string ''.
If this is the case then the solution is fairly simple - change the empty string to NULL before casting. The DECODE statement is my go to for this:
DECODE(col_X, '', NULL, col_X)::INT
If a more varied set of strings are in the column then using regexp_replace() to strip all the non-numeric characters would be needed.
text_to_int_alt(
case
when regexp_replace(convert(varchar, creative_id), '[^0-9]', '') <> '' then
regexp_replace(convert(varchar, creative_id), '[^0-9]', '')
end)

identify letter/number combinations using regex and storing in dictionary

import pandas as pd
df = pd.DataFrame({'Date':['This 1-A16-19 person is BL-17-1111 and other',
'dont Z-1-12 do here but NOT 12-24-1981',
'numbers: 1A-256-29Q88 ok'],
'IDs': ['A11','B22','C33'],
})
Using the dataframe above I want to do the following 1) Use regex to identify all digit + number combination e.g 1-A16-19 2) Store in dictionary
Ideally I would like the following output (note that 12-24-1981 intentionally was not picked up by the regex since it doesn't have a letter in it e.g. 1A-24-1981)
{1: 1-A16-19, 2:BL-17-1111, 3: Z-1-12, 4: 1A-256-29Q88}
Can anybody help me do this?
This regex might do the trick.
(?=.*[a-zA-Z])(\S+-\S+-\S+)
It matches everything between two spaces that has two - in it. Also there won't be a match if there is no letter present.
regex101 example
As you can see for the given input you provided only 1-A16-19, BL-17-1111, Z-1-12 & 1A-256-29Q88 are getting returned.
you could try :
vals = df['Date'].str.extractall(r'(\S+-\S+-\S+)')[0].tolist()
# extract your strings based on your condition above and pass to a list.
# make a list with the index range of your matches.
nums = []
for x,y in enumerate(vals):
nums.append(x)
pass both lists into a dictionary.
my_dict = dict(zip(nums,vals))
print(my_dict)
{0: '1-A16-19',
1: 'BL-17-1111',
2: 'Z-1-12',
3: '12-24-1981',
4: '1A-256-29Q88'}
if you want the index to start at one you can specify this in the enumerate function.
for x,y in enumerate(vals,1):
nums.append(x)
print(nums)
[1, 2, 3,4,5]

Informatica conditional

I am trying to add some logic to my expression table (exp_source). Basically, if the field o_field_digital__c is 'Yes' then change it to 'Y'. If its 'No' then change it to 'N' and if it's Null then just leave it blank. I put in the following and its showing syntax error
IIF(o_Field_DRC_Choice_Eligible__c = 'Yes', 'Y')
IIF(o_Field_DRC_Choice_Eligible__c = 'No', 'N')
Can you please fix this? Do I only need one IIF statement? this obviously has syntax errors
First you need to understand it is a transformation not a table.
Second, you can't change the value of an input port - you can only create a new calculated variable or output port
Last... IIF syntax is
IIF(condition, return true, return false)
As you can see you haven't provided a value for the return false argument which ironically is where you should have nested the subsequent IIF. Also you will have to specify to otherwise leave blank in the missing return part of the nested IIF.
to correct you will need to nest them so
IIF(o_Field_DRC_Choice_Eligible__c = 'Yes', 'Y', IIF(o_Field_DRC_Choice_Eligible__c = 'No', 'N', ''))
You can use the below logic for the purpose, if none of the condition is matched it will default the output to blank:
DECODE(true,
o_Field_DRC_Choice_Eligible__c = 'Yes','Y',
o_Field_DRC_Choice_Eligible__c = 'No', 'N',
ISNULL(o_Field_DRC_Choice_Eligible__c),'',
'')

Issue in Find in Python

I have to find some text in String using list comprehension but not getting my expected result
A = "BANANA"
[[b,a[b:]] for b in range(len(a)) if a[b:][0].lower() in ['a', 'e', 'i', 'o', 'u'] and 'ANA'.find(a[b:])>=0]
I am getting the following result -
[[3, 'ANA'], [5, 'A']]
But my expectation is as follows:
[[1, 'ANANA'], [3, 'ANA']]
Please help me where is am doing wrong.
Your list comprehension is very close, however the issue is with the if condition which checks for a character starting with A,E,I,O,U and has to check if ANA is also a part of the entire string.
In your condition if a[b:][0] in [....] evaluated to True hence there is an output of [5,'A']. Since you have a condition which translates as
Starts with a vowel in uppercase AND
Contains ANA in the string
Your comprehension should instead be as follows:
[[b,a[b:]] for b in range(len(a)) if a[b:][0] in ['A','E','I','O','U'] and 'ANA' in a[b:]]
The result for a='BANANA' with the above comprehension is
[[1, 'ANANA'], [3, 'ANA']]
Hope it helps.

django-haystack order_by not working

I have a query like
SearchQueryset().all().models(Show).order_by('title')
This will return list of objects. But in the title names there might be the special characters like ./hack:twilight and also numbers like 009:absolute.
According to order_by documentation, the priority goes to special characters. But when I see the output, it starts from the numbers.
Basically I need this output using that query
>> list = ['apple', 'zebra', '.hack', 'orange', 'car', 'funk', 'python']
>>> list.sort()
>>> list
['.hack', 'apple', 'car', 'funk', 'orange', 'python', 'zebra']
Any idea?