Permalink
Browse files

group over array values working :)

  • Loading branch information...
1 parent 854ddab commit 4562b6be64efaafbe2966336dd00acbce01fa62a @paulasmuth committed Jun 26, 2012
Showing with 17 additions and 5 deletions.
  1. +2 −1 src/FilterStack.scala
  2. +12 −2 src/GroupQuery.scala
  3. +1 −1 src/Message.scala
  4. +2 −1 src/SumQuery.scala
@@ -71,7 +71,8 @@ class AndFilterStack(next: FilterStack = null) extends FilterStack{
return true
} catch {
- case e: NumberFormatException => return false
+ case e: java.lang.ClassCastException => return false
+ case e: java.lang.IllegalStateException => return false
}
View
@@ -10,8 +10,18 @@ class GroupQuery() extends Query {
def data(msg: Message) =
- if (matches(msg) && msg.exists(group_key.get))
- groups(msg.getAsString(group_key)) += 1
+ if (matches(msg) && msg.exists(group_key.get)) {
+ val elem = msg.getAsGsonPrimitive(group_key.get)
+
+ if (elem.isJsonPrimitive)
+ groups(msg.getAsString(group_key)) += 1
+
+ else if (msg.getAsGsonPrimitive(group_key.get).isJsonArray) {
+ val iter = msg.getAsGsonPrimitive(group_key.get).getAsJsonArray.iterator
+ while (iter.hasNext)
+ groups(iter.next.getAsString) += 1
+ }
+ }
def eval(token: FQL_TOKEN) =
View
@@ -50,7 +50,7 @@ class Message(raw: Array[Byte]){
getAsGsonPrimitive(key.get).getAsBoolean()
- private def getAsGsonPrimitive(keys: List[String]) = {
+ def getAsGsonPrimitive(keys: List[String]) = {
var parent = ((root /: keys.init)((t, k) =>
if (t == null) null else t.getAsJsonObject(k)))
View
@@ -12,7 +12,8 @@ class SumQuery() extends Query {
if (matches(msg) && msg.exists(sum_key.get))
sum += msg.getAsDouble(sum_key)
} catch {
- case e: java.lang.NumberFormatException => ()
+ case e: java.lang.ClassCastException => ()
+ case e: java.lang.IllegalStateException => ()
}

0 comments on commit 4562b6b

Please sign in to comment.