ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yakov Zhdanov <yzhda...@apache.org>
Subject Re: SQL query question
Date Fri, 29 May 2015 12:30:49 GMT
Ognen,

UUID is not a requirement for id fields at all. Ignite does not have such
limitations. You can use any field name, any type, etc

When I run your original code I have:

Exception in thread "main"
org.apache.ignite.cache.CachePartialUpdateException: Failed to update keys
(retry update if possible).: [1026536079]
at
org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1729)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.cacheException(IgniteCacheProxy.java:1511)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.putIfAbsent(IgniteCacheProxy.java:905)
at
org.apache.ignite.scalar.pimps.ScalarCachePimp.putx$(ScalarCachePimp.scala:220)
at
org.apache.ignite.scalar.pimps.ScalarCachePimp.$plus$eq(ScalarCachePimp.scala:268)
at
org.apache.ignite.scalar.ScalarCacheAffinityExample$.main(ScalarCacheAffinityExample.scala:43)
at
org.apache.ignite.scalar.ScalarCacheAffinityExample.main(ScalarCacheAffinityExample.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: class
org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException:
Failed to update keys (retry update if possible).: [1026536079]
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.addFailedKeys(GridNearAtomicUpdateFuture.java:931)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.onResult(GridNearAtomicUpdateFuture.java:364)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture$2.apply(GridNearAtomicUpdateFuture.java:822)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture$2.apply(GridNearAtomicUpdateFuture.java:817)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal0(GridDhtAtomicCache.java:1181)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal(GridDhtAtomicCache.java:988)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.mapSingle(GridNearAtomicUpdateFuture.java:816)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.map0(GridNearAtomicUpdateFuture.java:625)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.mapOnTopology(GridNearAtomicUpdateFuture.java:473)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateFuture.map(GridNearAtomicUpdateFuture.java:307)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$14.apply(GridDhtAtomicCache.java:772)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$14.apply(GridDhtAtomicCache.java:770)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.asyncOp(GridDhtAtomicCache.java:580)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsync0(GridDhtAtomicCache.java:770)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.putAsync0(GridDhtAtomicCache.java:317)
at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.putAsync(GridCacheAdapter.java:2268)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.putIfAbsentAsync(GridDhtAtomicCache.java:364)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.putIfAbsent(GridDhtAtomicCache.java:357)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.putIfAbsent(IgniteCacheProxy.java:898)
... 9 more
Suppressed: class org.apache.ignite.IgniteCheckedException: Failed to
update keys on primary node.
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateResponse.addFailedKey(GridNearAtomicUpdateResponse.java:334)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateSingle(GridDhtAtomicCache.java:1798)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal0(GridDhtAtomicCache.java:1108)
... 23 more
Suppressed: class
org.apache.ignite.internal.processors.cache.GridCacheIndexUpdateException:
Failed to update index, incorrect key class [expCls=int,
actualCls=java.lang.Integer]
at
org.apache.ignite.internal.processors.cache.GridCacheMapEntry.updateIndex(GridCacheMapEntry.java:3458)
at
org.apache.ignite.internal.processors.cache.GridCacheMapEntry.innerUpdate(GridCacheMapEntry.java:2040)
at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateSingle(GridDhtAtomicCache.java:1667)
... 24 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to update
index, incorrect key class [expCls=int, actualCls=java.lang.Integer]
at
org.apache.ignite.internal.processors.query.GridQueryProcessor.store(GridQueryProcessor.java:471)
at
org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager.store(GridCacheQueryManager.java:353)
at
org.apache.ignite.internal.processors.cache.GridCacheMapEntry.updateIndex(GridCacheMapEntry.java:3451)
... 26 more

Pay attention:  Suppressed: class
org.apache.ignite.internal.processors.cache.GridCacheIndexUpdateException:
Failed to update index, incorrect key class [expCls=int,
actualCls=java.lang.Integer]

When I replace "Int" with Integer example starts working.

--Yakov

2015-05-28 17:00 GMT+03:00 Ognen Duzlevski <ognen.duzlevski@gmail.com>:

> 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
>   }*/
>

Mime
View raw message