OQL: Need help with query involving object array and sub-select [message #1199096] |
Wed, 20 November 2013 12:27  |
Eclipse User |
|
|
|
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 #1219721 is a reply to message #1199096] |
Thu, 05 December 2013 10:00   |
Eclipse User |
|
|
|
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 12:33  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.26942 seconds