2

I am trying to write a query such as this:

select {r: referrers(f), count:count(referrers(f))}
from com.a.b.myClass f

However, the output doesn't show the actual objects:

{
count = 3.0,
r = [object Object]
}

Removing the Javascript Object notation once again shows referrers normally, but they are no longer compartmentalized. Is there a way to format it inside the Object notation?

mvd
  • 2,596
  • 2
  • 33
  • 47

1 Answers1

2

So I see that you asked this question a year ago, so I don't know if you still need the answer, but since I was searching around for something similar, I can answer this. The problem is that referrers(f) returns an enumeration and so it doesn't really translate well when you try to put it into your hashmap. I was doing a similar type of analysis where I was trying to find unique char arrays (count the unique combinations of char arrays up to the first 50 characters). What I came up with was this:

var counts = {}; 
filter(
  map(
    unique(
      map(
        filter(heap.objects('char[]'), "it.length > 50"), // filter out strings less than 50 chars in length
        function(charArray) {  // chop the string at 50 chars and then count the unique combos
          var subs = charArray.toString().substr(0,50); 
          if (! counts[subs]) {
            counts[subs] = 1;
          } else {
            counts[subs] = counts[subs] + 1;
          }
          return subs;
        }
      ) // map
    ) // unique
  , function(subs) { // map the strings into an array that has the string and the counts of that string 
      return { string: subs, count: counts[subs] };
  }) // map
  , "it.count > 5000"); // filter out strings that have counts < 5000

This essentially shows how to take an enumeration (heap.objects('char[]') in this case) and filter it and map it so that you can compute statistics on it. Hope this helps someone.

Jeffrey Poore
  • 195
  • 1
  • 14