Removing generic nulls from a mixed list in kdb

102 Views Asked by At

I have a function that returns a mixed list. This list has generic nulls which I am looking to remove as I am not able to raze and eventually get a table.

q)sample
  ::
  ::
  (+(,`hostName)!,,`hostName1)!+(,`topCpu)!,,0f
  ::
  (+(,`hostName)!,,`hostName2)!+(,`topCpu)!,,0f
  (+(,`hostName)!,,`hostName3)!+(,`topCpu)!,,0f
  (+(,`hostName)!,,`hostName4)!+(,`topCpu)!,,0f
  ::
  ::
  ::

I tried using except keyword but that didn't help either

q)sample except ::
k){x@&~x in y}[(::;::;(+(,`hostName)!,,`hostName1)!+(,`topCpu)!,,0f;::;(+(,`hostName)!,,`hostName2)!+(,`topCpu)!,,0f;(+(,`hostName)!,,`hostName3)!+(,`topCpu)!,,0f;(+(,`hostName)!,,`hostName4)!+(,`topCpu)!,,0f;::;::;::;

Is there any effective way of removing these?

Thanks!

2

There are 2 best solutions below

0
rianoc On
q)(::;1;::;2;::;3) except (::)
1 2 3

You need brackets, otherwise the trailing :: makes a composition out of the statement

3
Maurice Lim On

You need to use brackets to wrap it up with except

q)0N!sample:(::;::;([hostName:enlist`hostName1] topCpu:enlist 0f);::;([hostName:enlist`hostName2] topCpu:enlist 0f))
(::;::;(+(,`hostName)!,,`hostName1)!+(,`topCpu)!,,0f;::;(+(,`hostName)!,,`hostName2)!+(,`topCpu)!,,0f)
::
::
(+(,`hostName)!,,`hostName1)!+(,`topCpu)!,,0f
::
(+(,`hostName)!,,`hostName2)!+(,`topCpu)!,,0f
q)sample except(::)
(+(,`hostName)!,,`hostName1)!+(,`topCpu)!,,0f
(+(,`hostName)!,,`hostName2)!+(,`topCpu)!,,0f