Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 552879 - OQL enhancements for sub-selects, maps, context providers, DISTINCT
Summary: OQL enhancements for sub-selects, maps, context providers, DISTINCT
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: Core (show other bugs)
Version: 1.9   Edit
Hardware: PC All
: P3 enhancement with 1 vote (vote)
Target Milestone: 1.10.0   Edit
Assignee: Andrew Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 241154
  Show dependency tree
 
Reported: 2019-11-09 16:10 EST by Andrew Johnson CLA
Modified: 2020-02-23 09:05 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Johnson CLA 2019-11-09 16:10:30 EST
I have various enhancements for OQL:

selects returning tables (rather than object lists) can be processed as lists.

SELECT s AS HashMap, eval((SELECT t, t.getKey(), t.getValue()
                        FROM OBJECTS ( s[0:-1] ) t
                        WHERE (toString(t.getKey()) = "META-INF")))[0][2] AS "Value for META-INF"
                        FROM java.util.HashMap s
                        WHERE
                        ((SELECT t FROM OBJECTS ( s[0:-1] ) t
                        WHERE (toString(t.getKey()) = "META-INF")) != null)
                        
This selects HashMaps, then processes the HashMap as a collection so a list of entries, finds the hash maps
containing the key META-INF, then does the select showing the hash map and the corresponding entry
for the key extracted using another select, with the result converted using eval() then the row and column
extracted using array operations.

The tables now have meta data context providers for tables with columns holding objects so that multiple
choices for each column (and the whole row with the underlying object) is available from context menus.

DISTINCT processing now operates on values as well as objects.
Comment 1 Andrew Johnson CLA 2019-11-09 16:37:33 EST
Also, better progressing monitoring, key/values extraction for maps, making these enhancements also
work for UNION queries, simplification of complex OQL UNION copy query, query context menu with no objects
should still allow copy selection.
Comment 2 Eclipse Genie CLA 2019-11-09 16:38:39 EST
New Gerrit change created: https://git.eclipse.org/r/152384
Comment 4 Eclipse Genie CLA 2019-11-10 17:23:07 EST
New Gerrit change created: https://git.eclipse.org/r/152396
Comment 6 Eclipse Genie CLA 2019-11-10 17:49:36 EST
New Gerrit change created: https://git.eclipse.org/r/152397
Comment 8 Kevin Grigorenko CLA 2019-11-11 11:26:29 EST
Does the example take into account that a HashMap is a tree data structure? Each entry may have a field that points to another entry, and on, recursively.

Reformatting for my own clarity:

SELECT s AS HashMap,
       eval(
         (
           SELECT t, t.getKey(), t.getValue() FROM OBJECTS ( s[0:-1] ) t
           WHERE (toString(t.getKey()) = "META-INF"))
         )[0][2] AS "Value for META-INF"
FROM java.util.HashMap s
WHERE (
        (
          SELECT t FROM OBJECTS ( s[0:-1] ) t
          WHERE (toString(t.getKey()) = "META-INF")
        ) != null
      )
Comment 9 Andrew Johnson CLA 2019-11-11 12:20:26 EST
The HashMap extraction is handled by the collections extraction framework, so OQL is relying on that. If the collections queries work, then OQL should too.

One problem is that HashSets also appear in the collections framework as maps so OQL array access of a HashSet returns key/value pairs, not the values.

My first go had sub-selects returning select items as lists.

SELECT t FROM OBJECTS ( SELECT s, s.size, s.table FROM java.util.HashMap s  ) t 

t
-------------------------------------------------------------------------------------------
[java.util.HashMap [id=0x22e573c8], 1, java.util.HashMap$Entry[] [id=0x22e60be8;length=16]]
[java.util.HashMap [id=0x22e574c8], 8, java.util.HashMap$Entry[] [id=0x22e60c40;length=16]]
-------------------------------------------------------------------------------------------

Reading about SQL and OQL shows that they allow select items from the inner select to be referred to by name in the outer select.
I think that is best done by converting each row of the inner select items to a map, and adjusting the attribute parsing to also recognise maps as well
as IObject fields and Java bean get methods. It would require a grammar change to have string constant attributes (for complex select items), but using get("my.select.item") is an alternative.

It could then work like this:

SELECT t.s, t.get("s.size"), t.tab, t.entries FROM OBJECTS ( SELECT s, s.size, s.table AS tab, s[0:-1] AS entries FROM java.util.HashMap s  ) t

t.s                              | t.get("s.size") |t.tab                                              |t.entries
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
java.util.HashMap [id=0x17c1efa0]|               1 |java.util.HashMap$Entry[] [id=0x17c1f2c0;length=16]|[java.security.ProtectionDomain [id=0x17c18c80]=java.lang.Class [id=0x12a0bf68;name=java.util.HashSet$PRESENT]]
java.util.HashMap [id=0x17c1eed8]|               1 |java.util.HashMap$Entry[] [id=0x17c1f130;length=16]|[java.security.CodeSource [id=0x17c1e6a0]=java.security.ProtectionDomain [id=0x17c18c80]]
java.util.HashMap [id=0x17c1f240]|               1 |java.util.HashMap$Entry[] [id=0x17c1f4c0;length=16]|[java.net.URL [id=0x17c1e760]=sun.misc.URLClassPath$FileLoader [id=0x17c1f630]]
java.util.HashMap [id=0x17c19298]|               3 |java.util.HashMap$Entry[] [id=0x17c194d0;length=16]|[java.net.URL [id=0x17c199a8]=sun.misc.URLClassPath$JarLoader [id=0x17c19830], java.net.URL [id=0x17c19940]=sun.misc.URLClassPath$JarLoader [id=0x17c197e8], java.net.URL [id=0x17c198d8]=sun.misc.URLClassPath$JarLoader [id=0x17c197a0]]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Comment 10 Kevin Grigorenko CLA 2019-11-11 12:28:49 EST
Ok, I wasn't aware that there was collection extract going on. I'm guessing the `s[0:-1]` in your example is performing that extraction. This would be nice to document at https://help.eclipse.org/2019-09/topic/org.eclipse.mat.ui.help/reference/propertyaccessors.html
Comment 11 Eclipse Genie CLA 2019-11-12 08:32:59 EST
New Gerrit change created: https://git.eclipse.org/r/152494
Comment 13 Eclipse Genie CLA 2019-11-13 10:30:50 EST
New Gerrit change created: https://git.eclipse.org/r/152587
Comment 15 Eclipse Genie CLA 2019-11-13 11:33:57 EST
New Gerrit change created: https://git.eclipse.org/r/152591
Comment 17 Eclipse Genie CLA 2019-11-14 17:03:06 EST
New Gerrit change created: https://git.eclipse.org/r/152701
Comment 19 Eclipse Genie CLA 2019-11-15 11:04:32 EST
New Gerrit change created: https://git.eclipse.org/r/152739
Comment 21 Eclipse Genie CLA 2019-11-16 06:56:50 EST
New Gerrit change created: https://git.eclipse.org/r/152775
Comment 23 Eclipse Genie CLA 2019-11-18 11:47:05 EST
New Gerrit change created: https://git.eclipse.org/r/152880
Comment 25 Eclipse Genie CLA 2019-11-20 16:25:25 EST
New Gerrit change created: https://git.eclipse.org/r/153089
Comment 27 Eclipse Genie CLA 2019-11-22 09:24:51 EST
New Gerrit change created: https://git.eclipse.org/r/153193
Comment 29 Eclipse Genie CLA 2019-11-28 06:28:54 EST
New Gerrit change created: https://git.eclipse.org/r/153527
Comment 31 Eclipse Genie CLA 2020-02-09 22:30:14 EST
New Gerrit change created: https://git.eclipse.org/r/157391
Comment 33 Eclipse Genie CLA 2020-02-09 22:30:35 EST
New Gerrit change created: https://git.eclipse.org/r/157393
Comment 35 Eclipse Genie CLA 2020-02-18 10:46:26 EST
New Gerrit change created: https://git.eclipse.org/r/157913
Comment 37 Andrew Johnson CLA 2020-02-23 08:57:42 EST
No comments from https://www.eclipse.org/forums/index.php/t/1101512/ so marking this as done.