Complex Relevance Examples

This page has not been liked. Updated 7/30/14, 6:35 PM by brolly33Tags:

 

This page is for relevance that solved a specific query issue that was especially challenging or tricky.

Also look for relevance examples here:  http://bigfix.me/

 

Maximum Version Bitwize

There was a bug in the Maximum and Minimum inspectors on AIX clients that prevented us from querying the maximum of versions correctly. The natural relevance would have been:

maximum of versions of filesets matching "lpp_name = 'perfagent.tools'" of object repository

To workaround this we used a bitwise comparison of the versions instead. We made the assumption that none of the individual version numbers were larger than 16 bit (65535.65535.65535.65535) Ordinarily we could just convert each integer into bits and concatenate them together, and convert the bits back into a really large, single integer, then take the maximum. Note that we front pad our bit strings with leading 0000 and then trim back to the expected bit length from the right.

(it as version) of (item 0 of it &"." & item 1 of it&"." &item 2 of it&"." &item 3 of it) of (bit set (first 16 of it) as integer as string, bit set (first 16 of following text of position 16 of it) as integer as string, bit set (first 16 of following text of position 32 of it) as integer as string, bit set (first 16 of following text of position 48 of it) as integer as string) of last 64 of ("0000000000000000000000000000000000000000000000000000000000000000" & it as bits as string) of maximum of ((bit set (it) as integer) of concatenation of lasts 16 of ("0000000000000000" & it as string ) of (it as integer as bits) of substrings separated by "." of (it as string)) of (versions of filesets matching "lpp_name = 'perfagent.tools'" of object repository)

The above works 1/2 way but truncates the most significant 32 bits of the 64 bit string. Since bit sets in relevance are limited to 32 bits, we had to break the 64 bit version into 2 32 bit portions to get the maximum of the first 32 bits and then the maximum of the last 32 bits for the entries that match the maximum of the first 32 bits. Using a set allows us to keep the set intact while calculating the maximums.

(it as version) of (item 0 of it &"." & item 1 of it&"." &item 2 of it&"." &item 3 of it) of (bit set (first 16 of it) as integer as string, bit set (first 16 of following text of position 16 of it) as integer as string, bit set (first 16 of following text of position 32 of it) as integer as string, bit set (first 16 of following text of position 48 of it) as integer as string) of items 0 of (elements of it, (last 32 of ("00000000000000000000000000000000" & it as bits as string)) of maximum of elements of set of (bit sets (lasts 32 of elements of it) as integer)) whose (item 0 of it ends with item 1 of it) of set of items 2 of (item 0 of it, item 1 of it, elements of item 0 of it) whose (item 2 of it starts with item 1 of it) of (it, (last 32 of ("00000000000000000000000000000000" & it as bits as string)) of maximum of elements of set of (bit sets (firsts 32 of elements of it) as integer)) of set of (concatenation of lasts 16 of ("0000000000000000" & it as integer as bits as string) of substrings separated by "." of (it as string)) of (versions of filesets matching "lpp_name = 'perfagent.tools'" of object repository)

Note that you can run the above on a Windows box by substituting (versions of files of windows folder) instead of (versions of filesets matching "lpp_name = 'perfagent.tools'" of object repository)

 

Base64 encode and decode a string

q: concatenation of firsts 1 of following texts of positions (((if item 0 of it != 0 then item 0 of it else 63);(if item 1 of it != 0 then item 1 of it else 63);(if item 2 of it != 0 then item 2 of it else 63);(if item 3 of it != 0 then item 3 of it else 63)) of (bit set (first 6 of following text of position 0 of it) as integer,bit set (first 6 of following text of position 6 of it) as integer,bit set (first 6 of following text of position 12 of it) as integer,bit set (first 6 of following text of position 18 of it) as integer) of firsts 24 of following texts of positions whose (it mod 24 = 0) of concatenation of (last 8 of ("00000000" & (hexadecimal integer ( it as hexadecimal) as bits) as string)) of firsts 1 of following texts of positions of (it & "%00%00") of "My string to base64 encode") of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+="

A: TXkgc3RyaW5nIHRvIGJhc2U2NCBlbmNvZGU=

q: concatenation of (character (bit set (first 8 of it) as integer); character (bit set (first 8 of following text of first 8 of it) as integer); character (bit set (last 8 of it) as integer)) whose (it != "") of firsts 24 of (it & "000000000000000000000000") of following texts of positions whose (it mod 24 = 0) of concatenation of (last 6 of ("000000" & it as bits as string)) of (if it=63 then nothing else it) of (items 0 of items 1 of ((firsts 1 of following texts of positions of "TXkgc3RyaW5nIHRvIGJhc2U2NCBlbmNvZGU=" , ((it, firsts 1 of following texts of it) of positions of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+=")) whose (item 0 of it = item 1 of item 1 of it)))

A: My string to base64 encode

Made obsolete as of TEM 8.2.498.0:

q: base64 encode "My string to base64 encode"

A: TXkgc3RyaW5nIHRvIGJhc2U2NCBlbmNvZGU=

q: base64 decode "TXkgc3RyaW5nIHRvIGJhc2U2NCBlbmNvZGU="

A: My string to base64 encode

 

Bitwize logical operations

union (OR), intersection (AND), subtraction, XOR

q: (item 0 of it + item 1 of it, item 0 of it * item 1 of it, item 0 of it - item 1 of it, (item 0 of it + item 1 of it)-(item 0 of it * item 1 of it)) of (bit set "0011" , bit set "0101")

A: 111, 1, 10, 110

T: 0.100 ms

I: singular ( bit set, bit set, bit set, bit set )

 

Tuple lookups

Given an arbitrary object (1;2;3;2;2)  and an arbitrary lookup chart, expressed as a tuple: (1,"a";2,"b";3,"c"), replace the integers in the original object with the corresponding letters in the lookup chart. Retain the order of the original object.

q: (items 1 of items 1 of (it,(1,"a";2,"b";3,"c")) whose (item 0 of item 1 of it = item 0 of it)) of ((1;2;3;2;2))

A: a

A: b

A: c

A: b

A: b

Advanced - if the original object does not have a corresponding lookup, retain the original value. (solved by Marjan Radanovic)

q: (if (exists (it,(1,"a";2,"b";3,"c")) whose (item 0 of item 1 of it = item 0 of it)) then (item 1 of item 1 of (it,(1,"a";2,"b";3,"c")) whose (item 0 of item 1 of it = item 0 of it)) else (it as string)) of ((1;2;4;2;6))

A: a

A: b

A: 4

A: b

A: 6

 

Drive Partition Map (Windows)

For use with Diskpart operations. Does not include partitions without drive letters.

q: (first 1 of following text of position 1 of following text of last "=" of string value of property "dependent" of it, first 1 of following text of first "Disk #" of following text of last "=" of string value of property "Antecedent" of it, first 1 of following text of first "Partition #" of following text of last "=" of string value of property "Antecedent" of it) of select objects "Antecedent, dependent from Win32_LogicalDiskToPartition" of WMI

A: C, 0, 0

A: D, 2, 0

A: E, 3, 0

A: T, 1, 0



includes partitions without drive letters, but expensive because of using the Tuple lookup with fallthrough from above.

q:  (concatenation of substrings separated by "%22" of it) of (if(exists (it,(((concatenation of substrings separated by "%22" of it) of following text of first "Win32_DiskPartition." of string value of property "Antecedent" of it, following text of last "LogicalDisk.DeviceID=" of string value of property "dependent" of it) of select objects "Antecedent, dependent from Win32_LogicalDiskToPartition" of WMI)) whose (item 0 of it = item 0 of item 1 of it)) then((item 0 of it & " - " & item 1 of it) of item 1 of (it,(((concatenation of substrings separated by "%22" of it) of following text of first "Win32_DiskPartition." of string value of property "Antecedent" of it, following text of last "LogicalDisk.DeviceID=" of string value of property "dependent" of it) of select objects "Antecedent, dependent from Win32_LogicalDiskToPartition" of WMI)) whose (item 0 of it = item 0 of item 1 of it)) else it as string & " - $:")  of (selects "deviceID from win32_DiskPartition" of wmi as string)

A: DeviceID=Disk #3, Partition #0 - E:

A: DeviceID=Disk #1, Partition #0 - T:

A: DeviceID=Disk #0, Partition #0 - C:

A: DeviceID=Disk #2, Partition #0 - D: