Skip to content

Instantly share code, notes, and snippets.

@Yotamho
Created January 18, 2021 08:43
Show Gist options
  • Select an option

  • Save Yotamho/40215082654471218edac4a79cfe8f07 to your computer and use it in GitHub Desktop.

Select an option

Save Yotamho/40215082654471218edac4a79cfe8f07 to your computer and use it in GitHub Desktop.
package com.checkpoint.datatube.filterpoc
import com.googlecode.cqengine.ConcurrentIndexedCollection
import com.googlecode.cqengine.attribute.SimpleAttribute
import com.googlecode.cqengine.query.option.QueryOptions
import com.googlecode.cqengine.query.parser.sql.SQLParser
object CQEngineExample extends App {
def intAttr(name: String): SimpleAttribute[Map[String, Any], Integer] =
new SimpleAttribute[Map[String, Any], Integer](name) {
override def getValue(`object`: Map[String, Any], queryOptions: QueryOptions): Integer =
`object`(name).asInstanceOf[Integer]
}
def strAttr(name: String): SimpleAttribute[Map[String, Any], String] =
new SimpleAttribute[Map[String, Any], String](name) {
override def getValue(`object`: Map[String, Any], queryOptions: QueryOptions): String =
`object`(name).asInstanceOf[String]
}
val coll = new ConcurrentIndexedCollection[Map[String, Any]]()
coll.add(Map("a" -> "a", "b" -> 1))
coll.add(Map("a" -> "b", "b" -> 2))
coll.add(Map("a" -> "c", "b" -> 3))
coll.add(Map("a" -> "d", "b" -> 4))
val parser = new SQLParser(classOf[Map[String, Any]])
parser.registerAttribute(strAttr("a"))
parser.registerAttribute(intAttr("b"))
val res = parser.retrieve("SELECT * FROM blahblah WHERE b > 2")
res.iterator().forEachRemaining(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment