Skip to content

Instantly share code, notes, and snippets.

@rianoc
Created December 7, 2021 10:02
Show Gist options
  • Save rianoc/8656c70bffcdb81ef2e9b5632d3e1c06 to your computer and use it in GitHub Desktop.
Save rianoc/8656c70bffcdb81ef2e9b5632d3e1c06 to your computer and use it in GitHub Desktop.
Kdb+ find source of 'part' error

https://code.kx.com/q/basics/errors/

part
Something wrong with the partitions in the HDB; or med applied over partitions or segments

Make a broken HDB:

$ mkdir -p badHDB/2001.01.01/tab1
$ mkdir -p badHDB/20011.01.01/tab2
$ mkdir -p badHDB/2002.01.01
$ chmod 000 badHDB/2002.01.01

Confirm it triggers part error:

q badHDB
'part
  [2]  (.Q.L)

  [0]  \l badHDB

Run function to inspect HDB:

q)tmp:first system"mktemp"
q){d:1_string x;{y:string y;(y;"D"$y),{r:system x;show last r;$[1~"J"$last r;(1b;-1_r;"");(0b;();-1_r)]} "ls ",x,"/",y," > ",tmp," 2>&1;echo $? >> ",tmp,";cat ",tmp}[d] each key x} `:badHDB
q)tab:flip `part`date`osError`files`error!flip {d:1_string x;{y:string y;(y;"D"$y),{r:system x;$[0~"J"$last r;(0b;-1_r;"");(1b;();first r)]} "ls ",x,"/",y," > ",tmp," 2>&1;echo $? >> ",tmp,";cat ",tmp}[d] each key x} `:badHDB

https://code.kx.com/q/ref/system/#capture-stderr-output

The resulting table:

part          date       osError files   error
-----------------------------------------------------------------------------------------------------------
"2001.01.01"  2001.01.01 0       ,"tab1" ""
"20011.01.01"            0       ,"tab2" ""
"2002.01.01"  2002.01.01 1       ()      "ls: cannot open directory 'badHDB/2002.01.01': Permission denied"

For a larger HDB filter down to partitions with issues:

select from tab where or[null date;osError]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment