Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Memory Analyzer » OQL: Need help with query involving object array and sub-select
OQL: Need help with query involving object array and sub-select [message #1199096] Wed, 20 November 2013 17:27 Go to next message
Geoff Alexander is currently offline Geoff Alexander
Messages: 4
Registered: November 2013
Junior Member
I have a class, XMLElement, that maintains a parent / child relationship using two data members:

ArrayList<XMLElement> children
XMLElement parent

I'm trying to find cases where the parent / child relationship is broken; that is, cases where an XMLElement object contains a child XMLElement whose parent is not the containing XMLElement. I tried the following query:

SELECT c, c.parent, p FROM OBJECTS ( SELECT OBJECTS p.children.array.getReferenceArray() FROM INSTANCEOF com.ibm.ArtifactTechnology.common.XMLElement p  ) c WHERE (c.parent != p)

However, this didn't work as the sub-select alias p isn't known to the outer select. Can someone suggest a query that would return objects having a broken parent / child relationship?

Thanks,
Geoff Alexander
Re: OQL: Need help with query involving object array and sub-select [message #1209164 is a reply to message #1199096] Mon, 25 November 2013 11:16 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew Johnson
Messages: 119
Registered: July 2009
Senior Member
This seems a bit tricky. Something like this might work for you:
SELECT t FROM OBJECTS ( SELECT OBJECTS s.childrenThreads.@referenceArray FROM java.lang.ThreadGroup s  ) t
 WHERE (t.@objectAddress NOT IN t.threadGroup.childrenThreads.@referenceArray.toArray())


It seems that NOT IN and IN operate on
List
Object[]
int[] (where IObject as left operand is convertible to int via the objectId)
IResultTable

but not long[], so hence the toArray() conversion which relies on OQL converting the
long[] to a List of Long, then to an array of Objects containing the Longs.

Perhaps IN and NOT IN should also operate on long[] where IObject is convertible to long via objectAddress.

I'd like OQL to be able to accomplish more, so any ideas will be useful.
See http://www.eclipse.org/forums/index.php/mv/msg/440195/985704/#msg_985704 for some discussion of OQL improvements.

Andrew Johnson
Re: OQL: Need help with query involving object array and sub-select [message #1209632 is a reply to message #1209164] Mon, 25 November 2013 16:17 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff Alexander
Messages: 4
Registered: November 2013
Junior Member
Andrew, thanks for getting back to me.

However, I don't think a query similar to yours will work. Consider the case where an XMLElement c is the child of both an XMLElement p1 and an XMLElement p2 and c.parent is p1. The p2<->c parent/child relationship is broken, so the p2,c pair should be included in the query results. However, a query similar to yours would not include the p2,c pair as c is a child of its parent p1.
Re: OQL: Need help with query involving object array and sub-select [message #1211773 is a reply to message #1209632] Tue, 26 November 2013 16:15 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew Johnson
Messages: 119
Registered: July 2009
Senior Member
In the first example you are right that the sub-select alias p is not visible in the outer select. That is to be expected as the sub-select is evaluated first to generate the from clause. Each entry is then evaluated as 'c', passed to the where clause, then if successful in the select clause. It does mean we could try the sub-select in the where clause.

SELECT g FROM java.lang.ThreadGroup g WHERE ((
   SELECT t FROM OBJECTS ${g}.childrenThreads.@referenceArray t WHERE ((t != 0) and (${snapshot}.getObject(${snapshot}.mapAddressToId(t)).threadGroup != g)
)) != null)


Note the use of '${g}' so the 'g' isn't taken as a class name.

This query doesn't show the bad children though.
Re: OQL: Need help with query involving object array and sub-select [message #1219721 is a reply to message #1199096] Thu, 05 December 2013 15:00 Go to previous messageGo to next message
Geoff Alexander is currently offline Geoff Alexander
Messages: 4
Registered: November 2013
Junior Member
Thanks for the suggested query. I was able to use it to produce a similar query for my needs:

SELECT OBJECTS p FROM INSTANCEOF com.ibm.ArtifactTechnology.common.XMLElement p WHERE ((SELECT c FROM OBJECTS ${p}.children.array.@referenceArray c WHERE ((c != 0) AND (${snapshot}.getObject(${snapshot}.mapAddressToId(c)).parent != p))) != NULL)

However as you point out, this query only shows bad parents. Since in some cases the query results in hundreds of bad parents with each parent having multiple children (in some case hundreds of children), it's quite tedious to find the bad children.

One way to return bad parent / child pairs would be to perform a query on a parent p / child c join in a query such as

SELECT p, c, c.parent FROM INSTANCEOF com.ibm.ArtifactTechnology.common.XMLElement p, OBJECTS ${p}.children.array.@referenceArray c WHERE ((c != 0) AND (${snapshot}.getObject(${snapshot}.mapAddressToId(c)).parent != p))

Adding a join capability to MAT's OQL would not only be useful in this case, but should rather be of wide-spread, general use. OQL in some related tools already offer join, so I should think that it's technically feasible to add it to MAT's OQL. Please let me know what you think and where / how I should open a formal feature request against MAT?

In the meantime, is there a way to export the parent objects along with their descendants from my first query so that I can perform post-processing to find the bad children? My attempts at exporting so far have only exported the parent objects without any descendants.
Re: OQL: Need help with query involving object array and sub-select [message #1220103 is a reply to message #1219721] Mon, 09 December 2013 17:33 Go to previous message
Andrew Johnson is currently offline Andrew Johnson
Messages: 119
Registered: July 2009
Senior Member
Quote:
Adding a join capability to MAT's OQL would not only be useful in this case, but should rather be of wide-spread, general use. OQL in some related tools already offer join, so I should think that it's technically feasible to add it to MAT's OQL. Please let me know what you think and where / how I should open a formal feature request against MAT?


There is a Report Bug on the MAT home page which can be used to open an enhancement request on Bugzilla. It sound interesting, though I don't know how many users want to do complex OQL queries. Please bear in mind that the committers are generally working on other things for their day jobs so don't have a lot of time for enhancements.

If you want to try working on it yourself then follow the http://wiki.eclipse.org/index.php?title=MemoryAnalyzer/Contributor_Reference#Build_OQL_Parser_using_JavaCC. OQLParser.jj is the grammar. I suppose you would need multiple FROM clauses in Query.java

It would be a bigger change than adding array access which was about the most complex thing I changed.
Some other ideas I have are array/sublist access using [start:end]
SELECT arr FROM int[] arr WHERE 3 in arr[1:10]

conversion of Java IArray to a List using one of the following arr[] or arr[: ] or arr[0:-1] (where -1 marks the end of the array).

Allowing more types of select item could be useful such as
SELECT 1,(2+3) FROM OBJECTS 0

which just selects one item, ignores it and does the column calculations.

Allowing list() to build lists and + to operate on them might allow:
SELECT OBJECTS list(s) + s.children[] FROM com.example.MyClass s

or possibly sub-selects as select items
SELECT OBJECTS list(s) + (SELECT t FROM ${s}.children[] t WHERE t.parent != s) FROM com.example.MyClass s

Previous Topic:Newbie: MAT / C++
Next Topic:java.io.EOFException with Memory Analyzer 1.3.0
Goto Forum:
  


Current Time: Wed Oct 01 04:04:12 GMT 2014

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

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