how to put a char into a string with a condition - etl

I'm very new in informatica and I would like to add a port with a expression which adds a char based on a condition.
example:
ports that are going to be checked:
Input:
a: T
b: T
c: F
output:
Result example: "110"
How I try to resolve it: I added an Expression Transformation
T stands for 1
F stands for 0
IIF(a= 'J', result||'1', IIF(b='J', result||'1' , IIF(c='J', result||'1',result||'0')))
is this correct? Or is there a better solution, that someone could suggest?

Please use below condition,
IIF(a = 'T', '1', IIF(a = 'F', 'O')) ||
IIF(b = 'T', '1', IIF(b = 'F', 'O')) ||
IIF(c = 'T', '1', IIF(c = 'F', 'O'))
Not sure why you are concatenating result, is it an input/ variable port? If so you can concatenate along with the above function itself as below,
IIF(a = 'T', result||'1', IIF(a = 'F', result||'O')) ||
IIF(b = 'T', result||'1', IIF(b = 'F', result||'O')) ||
IIF(c = 'T', result||'1', IIF(c = 'F', result||'O'))

Related

How replace each accented characters with non-accented characters foreach word in array in clickhouse?

I have a array of words, ['camión', 'elástico', 'Árbol'] and I want replace accented characters with non-accented characters for each word in array (['camion', 'elastico', 'Arbol'])
I'm searching some as this
SELECT arrayMap(x -> replaceRegexpAll(x, ['á', 'é', 'í', 'ó', 'ú'], ['a', 'e', 'i', 'o', 'u']), ['camión', 'elástico', 'Árbol']) AS word
And I want this result:
['camion', 'elastico', 'arbol']
Replacing each characters accents to withouth accent, but this doesn't work...
Any idea from solve?
Thanks
SELECT arrayMap(x -> arrayStringConcat(
arrayMap(y -> if((indexOf(['á', 'é', 'í', 'ó', 'ú'],y) as i) = 0, y, ['a', 'e', 'i', 'o', 'u'][i] ), extractAll(x,'.'))),
['camión', 'elástico', 'Árbol']) r
┌─r─────────────────────────────┐
│ ['camion','elastico','Árbol'] │
└───────────────────────────────┘
New feature add functions translate(string, from_string, to_string) and translateUTF8(string, from_string, to_string).
These functions replace characters in the original string according to the mapping of each character in from_string to to_string.
SELECT arrayMap(y -> translateUTF8(y,'áéíóúÁÉÍÓÚ','aeiouAEIOU'), ['camión', 'elástico', 'Árbol']) r
r |
-----------------------------+
['camion','elastico','Arbol']|

Sort a dictionary into two different lists based on group

import requests
from operator import itemgetter
foods = [{'name': 'Daisy' , 'group': 'A', 'eating': 'yes', 'feasting': 'yes', 'fasting': 'no', 'sleeping': 'no'},
{'name': 'Donny', 'group': 'B', 'eating': 'maybe', 'feasting':'maybe', 'fasting':'maybe', 'sleeping': 'maybe'},
{'name': 'Dwane', 'group': 'A', 'eating': 'no', 'feasting':'yes', 'fasting': 'no', 'sleeping': 'yes'},
{'name': 'Diana', 'group': 'B', 'eating': 'never', 'feasting':'never', 'fasting':'never', 'sleeping':'never'}]
def main():
group = sorted(foods, key=itemgetter('group'))
group_a = []
group_b = []
print(group)
main()
Hi there, I need help with the next step of this code. I would like to place the two dictionaries with group "A" in the empty list group_a. I would also like to place the two dictionaries with group "B" in the empty list group_b.
I am not sure how to go about this. Previously I tried:
for row in foods:
if 'A' in row:
group_a.append(row)
else:
group_b.append(row)
How ever that did not work.
Does anyone have an idea of how to populate these two empty lists according to group?

How to delay sequence emitting in Rxjs

I have an observable:
messages: string[] = ['a', 'b', 'c'];
const source = from(messages)
How do you delay it so when anyone subscribes to it, it will delay for n second to emit the items?
So:
source.subscribe(i => console.log(i));
// output ...n seconds... 'a' ...n seconds... 'b' ...n seconds... 'c'
You can combine the stream with an interval using zip:
zip(
from(['a', 'b', 'c', 'd']),
interval(1000),
(a, b) => a
)
.subscribe(console.log);
zip would combine the nth elements of the each stream into an array. That's way we use a selector function: (a, b) => a. It ensures that only elements from the first stream are used. The interval stream is only used for delaying emission.
I had the same problem and I solved it as the following code
const {from, of} = rxjs;
const {concatMap, delay} = rxjs.operators;
from(['a', 'b', 'c'])
.pipe(concatMap((msg) => of(msg).pipe(delay(1000))))
.subscribe(console.log);
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.4.0/rxjs.umd.min.js"></script>
You can just use the .delay() operator:
messages: string[] = ['a', 'b', 'c'];
const source = from(messages).pipe(
delay(1000)//delay for 1 second
)
Remember to import delay:
import { delay } from 'rxjs/internal/operators';
const source = from(['a', 'b', 'c', 'd']);
const delayPerElements = source
.pipe(map(v => of(v).pipe(delay(1000))), concatAll());
delayPerElements.subscribe(it => console.log(it));
// ... a ... b ... c ... d
I don't know if this is the best way but it works for me. Hope this help someone in the future.
As #Igno Burk suggestion:
const source = from(['a', 'b', 'c', 'd']);
const delayPerElements = source
.pipe(concatMap(v => of(v).pipe(delay(1000))));
delayPerElements.subscribe(it => console.log(it));
// ... a ... b ... c ... d
return delayPerElements;

Change/Override Trinket (attiny85) USB identification name, device name

The AdaFruit 'Trinket' library identifies itself as "Trinket HID Combo" when using as USB Keyboard. Is it possible to change this name to more useful name (with some code, constant etc)?
I'm using Arduino 1.0.4 IDE. Take a look in the source of this library but cannot find this name hard coded.
Any ideas to override this?
You have to change the Trinket library.
Search for USB_CFG_DEVICE_NAME in usbconfig.h
#define USB_CFG_DEVICE_NAME 'T', 'r', 'i', 'n', 'k', 'e', 't', ' ', 'H', 'I', 'D', ' ', 'C', 'o', 'm', 'b', 'o',
Here is the reference to the adafruit library: Adafruit-Trinket-USB

Can I use inline views with the criteria API?

Does NHibernate support inline views using criterias? Google doesn't seem to return any relevant results. Here is the query I need to convert preferably using criterias.
SELECT COUNT (incident_count) AS incident_count,
SUM (total_customers) AS total_customers,
MAX (longest_etr) AS longest_etr,
COUNT (DISTINCT crew_count) AS crew_count
FROM (SELECT l.incident_id AS incident_count,
i.downstream_cust_qty_total AS total_customers,
TO_CHAR (MAX (l.etr_datetime),
'MM/DD/YYYY HH24:mi:ss'
) AS longest_etr,
ca.crew_no AS crew_count
FROM district d,
LOCATION l,
ZONE z,
incident_device ID,
incident i,
crew_action ca
WHERE l.dist_no = d.dist_no
AND d.zone_id NOT IN (1008, 1010)
AND ID.location_id = l.location_id
AND ID.incident_id = i.incident_id
AND l.location_id = i.location_id
AND ca.incident_id = i.incident_id
AND ca.location_id = l.location_id
AND ID.call_type_cd IN ('ELEC', 'PLAN')
AND ID.clue_cd NOT IN (248, 258, 975)
AND l.fac_job_status_cd IN ('A', 'D', 'F', 'G', 'P', 'U', 'W')
AND z.zone_id = d.zone_id
AND ca.crew_action_id = l.crew_action_id
AND l.dist_no = 24
AND l.primary_loc_flg = 'T'
GROUP BY l.incident_id, i.downstream_cust_qty_total, ca.crew_no)
I already have everything converted in the where clause. That part was no problem. Which translates into something like.
GetSession().CreateCriteria(typeof (Incident), () => incidentAlias)
// Projection
.SetProjection(
Projections.ProjectionList()
.Add(LambdaProjection.Count<Incident>(i => incidentAlias.IncidentId).As(() => IncidentCount))
.Add(LambdaProjection.Sum<Incident>(i => incidentAlias.DownstreamCustQtyTotal).As(() => TotalCustomers))
.Add(LambdaProjection.Max<Location>(l => locationAlias.EtrDatetime).As(() => LongestEtr))
.Add(LambdaProjection.CountDistinct<CrewAction>(ca => crewActionAlias.CrewNo).As(() => CrewCount))
.Add(LambdaProjection.GroupProperty(() => incidentAlias.IncidentId))
.Add(LambdaProjection.GroupProperty(() => incidentAlias.DownstreamCustQtyTotal))
.Add(LambdaProjection.GroupProperty(() => crewActionAlias.CrewNo))
)
// Aliases
.CreateAlias(() => incidentAlias.Locations, () => locationAlias)
.CreateAlias(() => incidentAlias.IncidentDevices, () => incidentDeviceAlias)
.CreateAlias(() => incidentAlias.District, () => districtAlias)
.CreateAlias(() => districtAlias.Zone, () => zoneAlias)
.CreateAlias(() => locationAlias.CrewAction, () => crewActionAlias)
// Criterias
.Add(() => locationAlias.PrimaryLocFlg == "T")
.Add(() => locationAlias.DistNo == districtNumber)
.Add(() => zoneAlias.ZoneId != 1008)
.Add(() => zoneAlias.ZoneId != 1010)
.Add(SqlExpression.In(() => locationAlias.FacJobStatusCd, new[] { "A", "D", "F", "G", "P", "U", "W" }))
.Add(SqlExpression.In(() => incidentDeviceAlias.CallTypeCd, new [] { "ELEC", "PLAN" }))
.Add(() => incidentDeviceAlias.ClueCd != "248")
.Add(() => incidentDeviceAlias.ClueCd != "258")
.Add(() => incidentDeviceAlias.ClueCd != "975")
.SetResultTransformer(Transformers.AliasToBean<Dto>())
.List<Dto>();
Note that I'm using the Lambda criteria extension. Alternatively, I suppose I could create an additional Dto to select all columns with no aggregate functions then use Linq to do the count/sum/max/count distinct.
I just tried it with HQL and it does not work (would be the same with the Criteria API). What does work, however, is the following:
select
(select count(*) from Table1 t1),
(select sum(*) from Table2 t2)
from DummyTable dt
where rownum <= 1
DummyTable is not doing anything other than being there so NHibernate doesn't cry about it, and rownum <= 1 is there to ensure NHibernate doesn't try to return a list of objects. ;-)

Resources