Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Memory Analyzer » Does Eclipse OQL support map access?
Does Eclipse OQL support map access? [message #1795700] Thu, 27 September 2018 05:22 Go to next message
Jeffery Yuan is currently offline Jeffery YuanFriend
Messages: 27
Registered: July 2009
Junior Member
We would like to get specific key from a map in OQL select, is it possible? or does MAT has plan to support this in future?

- I want to find all id values in AddUpdateCommand. _fields is a field which is a LinkedHashMap.

SELECT updateCmd.solrDoc._fields.get("id") FROM org.apache.solr.update.AddUpdateCommand updateCmd

- From http://help.eclipse.org/2018-09/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Freference%2Fpropertyaccessors.html&cp=66_4_2_3, Eclipse OQL support array access but no mention about map.

Thanks
Re: Does Eclipse OQL support map access? [message #1795809 is a reply to message #1795700] Sat, 29 September 2018 10:20 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew JohnsonFriend
Messages: 205
Registered: July 2009
Senior Member
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.

The
FROM INSTANCEOF java.util.HashMap s
finds all the objects of type "java.util.HashMap" or of a type of a subclass of HashMap, and puts it into variable s.

The
s[0-1]
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
OBJECTS s[0:-1]
flattens that list into individual objects.
The
FROM OBJECTS ( SELECT ... ) t
then takes those individual objects and passes them one by one into another select as variable t.
The
WHERE toString(t.key).contains("e")
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.

The
toString(t.key), toString(t.value)
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.
Re: Does Eclipse OQL support map access? [message #1797005 is a reply to message #1795809] Wed, 24 October 2018 00:24 Go to previous message
Jeffery Yuan is currently offline Jeffery YuanFriend
Messages: 27
Registered: July 2009
Junior Member
Thanks, Andrew JohnsonFriend
I was able to access map using OQL, also MAT Calcite is pretty useful :)
Previous Topic:MAT dependency
Next Topic:Meaning of Overview->Details->Size
Goto Forum:
  


Current Time: Sat Apr 27 08:18:38 GMT 2024

Powered by FUDForum. Page generated in 0.03305 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top