Created
January 18, 2021 08:43
-
-
Save Yotamho/40215082654471218edac4a79cfe8f07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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