Closed kptfh closed 5 years ago
Ordered maps on the server are converted to a TreeMap on the java client. TreeMap requires that the key type implement Comparable. Standard types like Integer,Double,String implement Comparable. Since byte[] does not implement Comparable, I suggest wrapping byte[] in a class that does implement Comparable.
byte array "byte[]". Aerospike allows to have bytes keys.
Yes, but you asked the client to retrieve an ordered map with a byte[] key. The standard ordered map in java is TreeMap and it doesn't allow byte[] keys. Are you suggesting the client should wrap the byte[] key in a ByteBuffer (which does implement Comparable) when asked to retrieve an ordered map?
To use ByteBuffer wrapper for byte[] keys will be a good solution. It fits me well.
On Thu, Mar 7, 2019, 03:57 Brian Nichols notifications@github.com wrote:
Yes, but you asked the client to retrieve an ordered map with a byte[] key. The standard ordered map in java is TreeMap and it doesn't allow byte[] keys. Are you suggesting the client should wrap the byte[] key in a ByteBuffer (which does implement Comparable) when asked to retrieve an ordered map?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aerospike/aerospike-client-java/issues/132#issuecomment-470352018, or mute the thread https://github.com/notifications/unsubscribe-auth/APEUSo-KZlfvfvamKsCOdYedDxji1-AYks5vUHIFgaJpZM4bhp3o .
Ok, this will be included in the next client release.
Fixed in Java client 4.4.0:
While creating storage backend for Janusgraph I need to store data in ordered map. Keys and values of this map are byte arrays. MapOperation works well. But when I try to read whole bin value as a map I got:
Exception in thread "Thread-10" com.aerospike.client.AerospikeException$Serialize: Error -10,1,BB9020011AC4202 127.0.0.1 3000: java.lang.ClassCastException: class [B cannot be cast to class java.lang.Comparable ([B and java.lang.Comparable are in module java.base of loader 'bootstrap') at com.aerospike.client.util.Unpacker.unpackMap(Unpacker.java:141) at com.aerospike.client.util.Unpacker.unpackObjectMap(Unpacker.java:439) at com.aerospike.client.command.Buffer.bytesToParticle(Buffer.java:78) at com.aerospike.client.command.MultiCommand.parseRecord(MultiCommand.java:203) at com.aerospike.client.command.ScanCommand.parseRow(ScanCommand.java:59) at com.aerospike.client.command.MultiCommand.parseGroup(MultiCommand.java:143) at com.aerospike.client.command.MultiCommand.parseResult(MultiCommand.java:99) at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:100) at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:53) at com.aerospike.client.command.MultiCommand.execute(MultiCommand.java:78) at com.aerospike.client.command.Executor$ExecutorThread.run(Executor.java:139) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.ClassCastException: class [B cannot be cast to class java.lang.Comparable ([B and java.lang.Comparable are in module java.base of loader 'bootstrap') at java.base/java.util.TreeMap.compare(TreeMap.java:1291) at java.base/java.util.TreeMap.put(TreeMap.java:536) at com.aerospike.client.util.Unpacker.unpackMap(Unpacker.java:160) at com.aerospike.client.util.Unpacker.unpackMap(Unpacker.java:138)