|Re: Does Eclipse OQL support map access? [message #1795809 is a reply to message #1795700]
||Sat, 29 September 2018 10:20
| Andrew Johnson
Registered: July 2009
In OQL, array style access to a map gives you the nodes of the map (the object holding the key, value pair). The names of the fields holding the key and value will depend on the map type, and the Java class libraries.|
Something like this might help.
SELECT toString(t.key), toString(t.value) FROM OBJECTS ( SELECT OBJECTS s[0:-1] FROM INSTANCEOF java.util.HashMap s ) t WHERE toString(t.key).contains("e")
For the benefit of others trying to understand this OQL.
finds all the objects of type "java.util.HashMap" or of a type of a subclass of HashMap, and puts it into variable s.
FROM INSTANCEOF java.util.HashMap s
The does an OQL array access on objects held in s, and does an array slice finding elements from element 0 to element total length - 1 inclusive (i.e. the whole array) and returns the slice as a list.
The OQL array access works on primitive arrays, object arrays, Memory Analyzer internal arrays and lists, but does also operate on collections in the snapshot. See bug 287268. Collections are abstracted in the org.eclipse.mat.api plugin. OQL array access works on Lists, Sets, and Maps (operating on the Map nodes).
The flattens that list into individual objects.
then takes those individual objects and passes them one by one into another select as variable t.
FROM OBJECTS ( SELECT ... ) t
chooses the objects where the field key of t is converted to a standard JVM String by the MAT name resolver. This String is not an object in the dump, but an object in the MAT JVM process. Using reflection MAT then call contains() to determine whether the selected object t should be processed.
then generates two columns in the result table by running the MAT name resolver on the IObjects returned from reading the key and value fields of the IObject t.
The table then has those two column values, but underlying each row is IObject t for which right click (mouse button 2) on the row brings up the context menu.
Currently I don't have plans to do much more development of OQL - the code is in the org.eclipse.mat.parser plugin if you would like to dive in.
Another approach would be to use MAT Calcite extension plugin which gives a proper SQL parser, allowing SQL JOINS etc. This also has Quote:
getMapEntries(ref) | unnests Map as (key, value) tuples. It powerful but is a bit different from OQL, so there is some learning to do. Ideally I'd like a list of how to do common queries in both OQL and SQL.
Powered by FUDForum
. Page generated in 0.02314 seconds