Transform columns on Talend using TMAP - mapping

So I have this table as an input:
The "numero" column is either of "Type" 7 or 2.
What I want as an output is this
My tmap does not seem to work correctly. Can anybody suggest me a way to solve this?

If row1.Type is an integer, the condition in the expression that defines your variables should use the == operator and not the .equals("") method. For Var.Portable, row1.Type == 2 ? row1.Numero : null

Related

Rails + PostgreSQL: if value in one column is NULL, search by a value in a different column

In my model, I have these columns:
customer_invoiced_at: datetime
customer_invoice_at_custom: datetime
I am trying to search all records where the given date matches customer_invoiced_at:
scope :by_customer_invoiced_at_from, (lambda do |date_from|
self.where("customer_invoiced_at >= ?", date_from.to_datetime.beginning_of_day) if date_from.present?
end)
I'd need to tweak it a bit - if customer_invoice_at_custom exists (is not null or empty), I would need to use this field instead of customer_invoiced_at. However, if customer_invoice_at_custom is NULL or empty, I'd want to use customer_invoiced_at (as it is now in the shown scope).
How do I achieve that?
Thank you in advance
Can you use PostgreSQL's native COALESCE() function? This does exactly what you want:
.where("COALESCE(customer_invoiced_at, my_other_column) >= ?", date_from.to_datetime.beginning_of_day)

Having different count per key in jsonb

I have values in a table called Translation, that contains for every values per example:
=> {"fr"=>"Jaune", "de"=>"", "en"=>"", "bg"=>"", "hr"=>"", "es"=>"", "hu"=>"", "it"=>"", "lt"=>"", "lv"=>"", "nl"=>"", "pl"=>"", "pt"=>"", "ro"=>"", "cs"=>""}
and I'm looking to get the the number of the translation for each language:
I'm trying :
Translation.where("values->>'fr' IS NOT NULL").count
but it giving me 0, which is not correct, do anyone knows how to do it correctly?
The problem that you have is that the keys that don't have values, still exist in the json, so "is not null" will return all of them because the key exist. you have two options here, you can remove the empty keys from the database, so not null will work, or, change it to see if the key is empty
You can do it like this
Translation.where("values->>'fr' <> ''").count
and it will work with the structure that you have right now.

Denodo: How to aggregate varchar data types?

I'm creating an aggregate from a anstime column in a view table in Denodo and I'm using a Cast to convert it to float and it works only for those numbers with period (example 123.123) but does not work for the numbers without period (example 123). Here's my code which only works for those numbers with period:
SELECT row_date,
case
when sum(cast(anstime as float)) is null or sum(cast(anstime as float)) = 0
then 0
else sum(cast(anstime as float))
end as xans
FROM table where anstime like '%.%'
group by row_date
Can someone please help me how to handle those without period?
My guess is you've got values in anstime which are are not numeric, hence why not having the where anstime like '%.%' predicate causes a failure, as has been mentioned in other comments.
You could try adding in an intermediate view before this one which strips out any non numeric values (leaving the decimal point character of course) and this might then allow you to not have to use the where anstime like '%.%' filter.
Perhaps the REGEXP function which would possibly help there
Your where anstime like '%.%' clause is going to restrict possible responses to places where anstime has a period in it. Remove that if you want to allow all values.
I appreciate those who responded to my concern. In the end we had to reach out to our developers to fix the data type of the column from varchar to float rather than doing a workaround.

PIG field_name MATCHES string

say field_1 MATCHES 'a_string'
I would like select any entries with field_1 CONTAINING(if this exist) 'string' so that field_1 with 'a_string' will be included.
For an example
Entry Field_1
'a_string'
'string'
'strang'
Entries 1 and 2 will be selected.
May I know what is the most elegant way to do this?
The actual strings(chararray) I am dealing with are urls with different levels of depth i.e. www.abc.com/depth1/depth2/...
I was planning to parse the chararray using '/' as delimitter but its just too ugly. I will need to change the number for columns should a inner depth appeared.
Your assistance is deeply appreciated!!
I'm not sure if I understand your question correctly, but I think you can use the filter operation with matches for this. The second parameter is a regular expression.
X = FILTER A BY (field_1 matches '.*a_string.*');
See the Docs for more detail.

Generating a select tag with rails with range of numbers with steps

What is the simplest way to write a rails select tag that will generate a select for the numbers 1-15 stepped in .5 increments?
I know this has to be simple but i'm struggling with the syntax, i know there has to be a more elegant way to write it than how i did.
thanks!
select_tag "sizes", options_for_select((4..15).step(0.5))
This is how i wrote it... but is this the best way to approach?
also, if i wanted the 4.0/5.0/6.0 etc to read 4/5/6 as whole numbers, is there a way to do/include this on one line?
select_tag "sizes", options_for_select( (4..15).step(0.5).map{|n| n%1 == 0 ? n.to_i : n} )
The options_for_select method does what you want, but only if you can seed it with the correct data. This means you need an array with the appropriate values in it. For example:
options_for_select((0..28).to_a.collect { |v| v.to_f / 2 + 1 })

Resources