Hi,
I am not able to figureout why following like function gives error:
“dir1/dir2/dir3/dir5” like “dir1/*/*/dir5”
Any suggestions will be helpful.
Hi,
I am not able to figureout why following like function gives error:
“dir1/dir2/dir3/dir5” like “dir1/*/*/dir5”
Any suggestions will be helpful.
q only supports simple wildcarding?
it is simply not supported
kdb+'s regexp support it minimal and to the point
you could do this with
q)all"dir1/dir2/dir3/dir5" like/:(“dir1/*”;“*/dir5”)
1b
Cheers,
? Attila
? Attila
Better late than never…only getting round to reading google groups now.
If you have consistency in your directory structure use “?” instead of “*”.
“dir1/dir2/dir3/dir5” like “dir1/???/???/dir5”
1b
May or may not help.
Thanks,
Sean
Hi Sean,
we don’t have fix directory name length that is why i was looking for *. I end up writing a function that will compare path vs pattern.
I am pasting the code i wrote as well as the test cases. may be if someone can improve the code. I am new to kdb.
CompareKeyWithPath:{[openClosed;pattern;xdb;delim]
$[(count pattern)=1;pattern:(enlist pattern);]
$[(count xdb)=1;xdb:(enlist xdb);]
;patternCnt:count pattern
;xdbCnt:count xdb
;i:0;j:0
;while[i<patternCnt
;$[“*”=(pattern i);while[(j<xdbCnt) and (delim <> xdb j);j+:1] ;$[(pattern i)<>xdb j;:0;j+:1]]
;i+:1
]
;$[j<xdbCnt;$[openClosed=“C”;:0;$[delim<>xdb j;:0;]];]
;:1
}
/ Closed positive scenarios
;(CompareKeyWithPath[“C”;“dir1”;“dir1”;“/”]=1
;CompareKeyWithPath[“C”;“dir1/dir2”;“dir1/dir2”;“/”]=1
;CompareKeyWithPath[“C”;“dir1/dir2/dir3/dir4/dir5”;“dir1/dir2/dir3/dir4/dir5”;“/”]=1
;CompareKeyWithPath[“C”;“*/*/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“C”;“dir1/*/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“C”;“dir1/*/dir3/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“C”;“dir1/*/*/*”;“dir1/dir2/dir3/dir5”;“/”]=1
/ Special case
;CompareKeyWithPath[“C”;“*”;“dir1/dir2/dir3/dir5”;“/”]=0
;CompareKeyWithPath[“C”;“*”;“dir1”;“/”]=1
;CompareKeyWithPath[“C”;“*”;“dir2”;“/”]=1
;CompareKeyWithPath[“C”;“*”;“dir2/dir1”;“/”]=0
;CompareKeyWithPath[“C”;“*/*/*”;“dir2/dir1”;“/”]=0
;CompareKeyWithPath[“C”;“*/*/*”;“dir2/dir1/dir3”;“/”]=1
;CompareKeyWithPath[“C”;“*/*/*”;“dir2d/ddir1/didr3”;“/”]=1
/ Closed negative scenarios
;CompareKeyWithPath[“C”;“dir1”;“dir11”;“/”]=0
;CompareKeyWithPath[“C”;“dir1”;“dir2”;“/”]=0
;CompareKeyWithPath[“C”;“dir1”;“dir1/dir2/dir3/dir4”;“/”]=0
;CompareKeyWithPath[“C”;“dir1”;“dir1/dir2”;“/”] =0
;CompareKeyWithPath[“C”;“dir1/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=0
/ This should never happen “/” should never be in the end of path or key
;CompareKeyWithPath[“C”;“dir1/*/*/*”;“dir1/dir2/dir3/dir5/”;“/”]=0
/ Open Positive scenarios
;CompareKeyWithPath[“O”;“dir1”;“dir1”;“/”]=1
;CompareKeyWithPath[“O”;“dir1”;“dir1/dir2/dir3/dir4”;“/”]=1
;CompareKeyWithPath[“O”;“dir1/dir2”;“dir1/dir2/dir3/dir4”;“/”]=1
;CompareKeyWithPath[“O”;“dir1”;“dir1/dir2”;“/”] =1
;CompareKeyWithPath[“O”;“dir1/dir2”;“dir1/dir2”;“/”]=1
;CompareKeyWithPath[“O”;“dir1/dir2/dir3/dir4/dir5”;“dir1/dir2/dir3/dir4/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“*/*/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“*/*/*/dir5”;“dirdsd1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“*/*/*/dir5”;“dir1/dir2/dir3/dir6”;“/”]=0
;CompareKeyWithPath[“O”;“dir1/*/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“dir1/*/dir3/dir5”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“dir1/*/*/*”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“dir1/*/*/*”;“dir1/dir2/dir3/dir5/dir6”;“/”]=1
/ Open Negative scenarios
;CompareKeyWithPath[“O”;“dir1”;“dir11”;“/”]=0
;CompareKeyWithPath[“O”;“dir1”;“dir2”;“/”]=0
;CompareKeyWithPath[“O”;“dir1/dir2”;“dir1/dir22/dir3/dir4”;“/”]=0
;CompareKeyWithPath[“O”;“dir1/*/dir5”;“dir1/dir2/dir3/dir5”;“/”]=0
;CompareKeyWithPath[“O”;“GENEVA\PFPC”;“GENEVA\PFPC\W201\TRANSACTIONS”;“\”]=1
/ Special case
;CompareKeyWithPath[“O”;“*”;“dir1”;“/”]=1
;CompareKeyWithPath[“O”;“*”;“dir2”;“/”]=1
;CompareKeyWithPath[“O”;“*”;“dir1/dir2/dir3/dir5”;“/”]=1
;CompareKeyWithPath[“O”;“*”;“dir2/dir1”;“/”]=1
)