javavisualvmoql

How to sort strings in OQL


I have tried:

select sort(obj.displayName, 'lhs < rhs') from my.org.BusinessClass obj

and

select sort(obj.displayName, 'lhs.toString() < rhs.toString()') from my.org.BusinessClass obj

Both give me character array results, but none of them are sorted by String. I think it's sorting by object id.

I have also tried:

select sort(obj.displayName, lhs < rhs) from my.org.BusinessClass obj 
select sort(obj.displayName, lhs.toString() < rhs.toString()) from my.org.BusinessClass obj

But these result in errors because sort second argument is suppose to a string expression.

The examples on the VisualVM documentation are only for numbers: Analyzing a Heap Dump Using Object Query Language (OQL)

The class is structured as follows:

package my.org;
public class BusinessClass {
    private String displayName;
    // rest of class omitted for brevity 
}

Solution

  • This is the workaround I used:

    1. Increase the max number of rows returned by OQL
      1. (see: Increasing the Max Size of OQL Result )
    2. Copy and paste the result of the unsorted query to a text file
    3. Use vim or similar text processor to remove the object id
    4. sort using unix sort