q)t:([] a:1 2 3;s:`lll`h`j;longNameColumn:("ww";"ko";"ooo"))
q)t
a s longNameColumn
--------------------
1 lll "ww"
2 h "ko"
3 j "ooo"
`syms _.Q.w[]
used| 10407392
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
mphy| 8464715776
symw| 1380256
Tempting to check against spec
isGuid:{
t:{all (8 4 4 4 12~count each "-" vs x;all x in "ABCDEFabcdef0123456789");
$[36=c:count x;t x;38=c;all (x[0 37]~"{}";t x 1+til 36;0b]
}
Instead faster is testing roundtrip
addToBeginning:{x setenv y,":",":" sv {x where not x~\:""}":" vs getenv x}
addToEnd:{x setenv (":" sv {x where not x~\:""}":" vs getenv x),":",y}
remove:{x setenv ":" sv {x where not any x like/:("";y)}[;y]":" vs getenv x}
pushToEnd:{x setenv ":" sv {x iasc x like y}[;y] {x where not x~\:""}":" vs getenv x}
bringForward:{x setenv ":" sv {x idesc x like y}[;y] {x where not x~\:""}":" vs getenv x}
Add where needed:
/tab : the table to operate on
/baseCols : the columns not to unpivot
/pivotCols : the columns which you wish to unpivot
/kCol : the key name for unpivoted data
/vCol : the value name for unpivoted data
unpivot:{[tab;baseCols;pivotCols;kCol;vCol]
base:?[tab;();0b;{x!x}(),baseCols];
newCols:{[k;v;t;p] flip (k;v)!(count[t]#p;t p)}[kCol;vCol;tab] each pivotCols;
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:
When permforming wj
out of box multiple aggregations requires the user to perform positional renaming to tidy up the result.
Instead a helper can be created:
wjr:{[f;w;c;t;q]
if[not 99h~type q[1];
:f[w;c;t;q]];
In Kdb+ you cannot control the use of '/tmp' during a system call. You may need to avoid this if the drive space is small.
For familiarity use the TMPDIR environment variable:
q)setenv[`TMPDIR] "/my/chosen/path"
Function to run system commands:
Use .p.wrap https://code.kx.com/q/ml/embedpy/userguide/#embedpy-objects_1
Example giving each subplot a title:
plt:.p.import[`matplotlib;`:pyplot]
plts:plt[`:subplots;<;pykwargs `ncols`figsize`dpi!(2;24 8;100)]
.p.wrap[plts[1;0]][`:set_title]"Plot1";
.p.wrap[plts[1;1]][`:set_title]"Plot2";
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
systemWithExitCode:{[c] | |
f:first system"mktemp"; //Make a temp file respecting TMPDIR | |
c:c," > ",f," 2>&1;echo $?"; //Add redirect to tmp file and capture of exit code | |
e:"J"$first system c; //Execute the command | |
f:hsym `$f; | |
r:read0 f; //Read the result of the command | |
hdel f; //Delete the tmp file | |
`exitCode`output!(e;r) | |
} |
OlderNewer