DolphinDB: How to deduplicate array vectors while preserving the order of their elements?

18 Views Asked by At

I want to deduplicate the column “b“ in the figure below, but the distinct function cannot be used with the group by or context by clause, nor can it preserve the order of the elements. Besides ungrouping the table and deduplicating with the isDuplicated function, are there any other methods?

enter image description here

1

There are 1 best solutions below

0
Shena On BEST ANSWER

You can use the loop function, as shown in the following script:

t = table(`a`b as sym, array(INT[]).append!([1 2 1, 2 3 2]) as val)
// Not preserving the order
select sym, loop(distinct,val) as`val from t 

// Preserving the order
select sym, loop(x -> x[ifirstHit{==,x,}:E(distinct x).sort()], val) as `val from t