Eclipse MAT OQL 

OQL for flattening string array

Consider a class whose instances can contain an array of strings which we want to display as output of an OQL. For example, let's say X, Y are two instances of the class and say, X has [Xs1, Xs2] as that array of strings and Y has [Ys1, Ys2, Ys3]. We want to find an OQL which would have output like this:
InstanceName Strings
----------------------------
X                     Xs1, Xs2
Y                     Ys1, Ys2, Ys3

With current artefacts available with Eclipse MAT OQL, it seems to be impossible to show that. But it is possible to formulate a simple query which has output as below:
InstanceName Strings
----------------------------
X                     Xs1
X                     Xs2
Y                     Ys1
Y                     Ys2
Y                     Ys3

A practical example: each instance of sun.font.CompositeFont has a string array name componentNames.
Initial query to make an attempt to display the data:
SELECT cf.fullName.toString() AS CompositeFontName, cf.componentNames[0:-1].toString() AS componentNames FROM INSTANCEOF sun.font.CompositeFont cf 



Refined query which is able to show component names for each composite font, but in multiple arrays is as follows:
SELECT x.cfName AS CompositeFontFullName, x.comps.toString() AS ComponentFontName FROM OBJECTS ( SELECT cf.fullName.toString() AS cfName, cf.componentNames[0:-1] AS comps FROM INSTANCEOF sun.font.CompositeFont cf  ) x 



Comments

Popular posts from this blog