2

我正在尝试编写这样的查询:

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

但是,输出不显示实际对象:

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

删除 Javascript 对象表示法再次正常显示引荐来源网址,但它们不再被划分。有没有办法在 Object 表示法中对其进行格式化?

4

1 回答 1

2

所以我看到你在一年前问过这个问题,所以我不知道你是否还需要答案,但由于我正在寻找类似的东西,我可以回答这个问题。问题是referrers(f) 返回一个枚举,因此当您尝试将其放入哈希图中时,它并不能很好地翻译。我正在做类似类型的分析,我试图找到唯一的 char 数组(计算 char 数组的唯一组合,最多前 50 个字符)。我想出的是:

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

这实质上显示了如何获取枚举(在本例中为 heap.objects('char[]'))并对其进行过滤和映射,以便您可以计算统计信息。希望这可以帮助某人。

于 2015-09-09T19:57:43.860 回答