0

I have the below table

t:flip (`comps`uid)!(("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1");`user1`user2)

I am trying to populate the valueWhere1 and valueWhere0 columns from the below table

tRes:flip (`comps`uid`valueWhere1`valueWhere0)!(("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1");`user1`user2;(`ub01`csf`ci`in`j106;`ub01`csf`ci`in`j106);(`msil`gsc;`msil`gsc))

I have got the count of each string where the value before each pipe is either 1,0

t:update countWhere1:sum each {"1"=last x}''["|"vs'comps],countWhere0:sum each {"0"=last x}''["|"vs'comps] from t

Trying to pull in the first section of each string and filter based on the 1;0 flag. I have the below but not quite working

`$first each raze {"," vs x} each '{"|"vs x} each ("ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1";"ub01,140,16600,1|msil,140,31,0|gsc,140,40,0|csf,140,9,1|ci,140,18,1|in,140,10,1|j106,100,100,1")

Thanks for looking

Cathal O'Neill
  • 2,522
  • 1
  • 6
  • 17
pmade1
  • 21
  • 4

2 Answers2

1

Here's an approach using "|" separation similar to Matt and then using 0: to parse based on the assumption that your bit between the pipes is predictable and regular:

t,'exec{group`$"valueWhere",/:string(!).("S  B";csv)0:"|"vs x}each comps from t

Note that this may need a bit of tweaking to generalise ... the dictionaries created after the group may not always conform, in which case you may need to

t,'exec{`valueWhere1`valueWhere0#group`$"valueWhere",/:string(!).("S  B";csv)0:"|"vs x}each comps from t
terrylynch
  • 11,844
  • 13
  • 21
0

This will seperate each comps by "|", then the nested function will filter based on the last character of each string in the list. You can either convert directly to boolean "B"$ if it's always 1 or 0.

select {x where "B"$-1#/: x} each "|" vs/: comps from t

or convert to an int with = in the where

select {x where 1 = "I"$-1#/: x} each "|" vs/: comps from t
Matt Moore
  • 2,705
  • 6
  • 13