Hello all,
Does every object that is being used via sql queries and has indexable
fields, have to have a field named id of type UUID?
The following example doesn't work as presented; however, if I change the
cache to be of type [UUID,Foo] and then enable the val id = UUID.randomUUID
line that is commented out at the bottom of the file, it all works. When I
say it doesn't work in the first case, I am getting the following errors:
[08:51:38] Topology snapshot [ver=1, nodes=1, CPUs=8, heap=1.3GB]
**** Configure/Create Cache ****
**** Creating Data ****
[error] (run-main-0) org.apache.ignite.cache.CachePartialUpdateException:
Failed to update keys (retry update if possible).: [1092460711]
org.apache.ignite.cache.CachePartialUpdateException: Failed to update keys
(retry update if possible).: [1092460711]
at
org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1805)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.cacheException(IgniteCacheProxy.java:1450)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.putIfAbsent(IgniteCacheProxy.java:828)
at
org.apache.ignite.scalar.pimps.ScalarCachePimp.putx$(ScalarCachePimp.scala:224)
at
org.apache.ignite.scalar.pimps.ScalarCachePimp.$plus$eq(ScalarCachePimp.scala:280)
at ScalaCacheQueryExample$.main(test.scala:42)
at ScalaCacheQueryExample.main(test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
======== code starts here ========
import java.util._
import org.apache.ignite.cache.CacheMode._
import org.apache.ignite.cache.affinity.AffinityKey
import org.apache.ignite.configuration.CacheConfiguration
import org.apache.ignite.scalar.scalar
import org.apache.ignite.scalar.scalar._
import org.apache.ignite.configuration._
import org.apache.ignite.cache._
import org.apache.ignite._
import scala.collection.JavaConversions._
import scala.util.Random
object ScalaCacheQueryExample {
def main(args: Array[String]) {
println("**** Start Ignite ****")
// Start Ignite -- can we just connect?
Ignition.setClientMode(false)
val ign = Ignition.start("example-ignite.xml")
println("**** Configure/Create Cache ****")
val fooCacheCfg = new CacheConfiguration[Int, Foo]()
fooCacheCfg.setName("TestCache")
fooCacheCfg.setCacheMode(CacheMode.PARTITIONED)
fooCacheCfg.setIndexedTypes(classOf[Int], classOf[Foo])
val fCache:IgniteCache[Int,Foo] = ign.getOrCreateCache[Int,
Foo](fooCacheCfg)
println("**** Creating Data ****")
val r = new Random()
// fCache.put(123, Foo(id=Math.abs(r.nextInt()), value=1000,
name="bob"))
val f1 = Foo(Math.abs(r.nextInt),1000,"bob")
val f2 = Foo(Math.abs(r.nextInt),2000,"nancy")
fCache += (f1.id -> f1)
fCache += (f2.id -> f2)
println("**** Starting Query ****")
print(fCache.sql("value > 1000").getAll.map(e => e.getValue))
}
}
private case class Foo(
@ScalarCacheQuerySqlField
id: Int,
@ScalarCacheQuerySqlField
value: Int,
@ScalarCacheQuerySqlField
name: String
)
/* COMMENTED OUT */
/* {
@ScalarCacheQuerySqlField
val id = UUID.randomUUID
}*/