You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "haotian.chen" <ha...@blackrock.com> on 2018/06/05 14:22:36 UTC

support for Scala Collection as key?

Thanks a lot for the wonderful development on Ignite. I am wondering if there
is any plan to support Scala Collection (e.g. Vector) as key? 

There is support for common Java Collection, see here:
https://github.com/apache/ignite/blob/d4ae653d8018e88847425111321e653bd558a973/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java#L320

Scala List seems working fine for me (did not thoroughly test it), but not
vector. A simple demo here:

val bin = ignite().binary()
val k1 = Vector(“1”, “2”)
val k2 = Vector(“1”) ++ Vector(“2”)
k1 == k2 // true
binary.toBinary(k1) == binary.toBinary(k2) // false


Thanks!




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: support for Scala Collection as key?

Posted by "haotian.chen" <ha...@blackrock.com>.
Yeah, I believe k1 and k2's internal structure are different, and therefore
causing the problem



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: support for Scala Collection as key?

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

Most likely, Scala Vector can't be used as a key as-is due to it's
implementation [1].
I'm not sure, if k1 and k2 scala objects have same internal structure to
Ignite can serialize them to same binary representation.


[1] https://stackoverflow.com/questions/20612729/how-does-scalas-vector-work

On Tue, Jun 5, 2018 at 6:41 PM, haotian.chen <ha...@blackrock.com>
wrote:

> Got it. I thought IgniteCache converts key to BinaryObject and then
> compares
> them, and therefore gave the example.
>
> However, if I put key k1 with a value into IgniteCache, and retrieve the
> value using k2, I won't be able to find the entry. Do you know what's the
> process behind this process?
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov

Re: support for Scala Collection as key?

Posted by "haotian.chen" <ha...@blackrock.com>.
Got it. I thought IgniteCache converts key to BinaryObject and then compares
them, and therefore gave the example.

However, if I put key k1 with a value into IgniteCache, and retrieve the
value using k2, I won't be able to find the entry. Do you know what's the
process behind this process?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: support for Scala Collection as key?

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

Ignite doesn't rely on BinaryObject hashcode or equals method, it use
internal comparison logic instead.
So, it is ok BinaryObject.equals() return true if compared with same object
only.

As Ignite have no hooks for scala collections, they will be handled as
regular user objects.
Let us know if you observer any issues related to incorrect scala
collection objects handling.


AFAIK, there is no plans to add support for scala collections to binary
protocol.
It doesn't looks like trivial task, but anyway feel free to contribute.

On Tue, Jun 5, 2018 at 5:22 PM, haotian.chen <ha...@blackrock.com>
wrote:

> Thanks a lot for the wonderful development on Ignite. I am wondering if
> there
> is any plan to support Scala Collection (e.g. Vector) as key?
>
> There is support for common Java Collection, see here:
> https://github.com/apache/ignite/blob/d4ae653d8018e88847425111321e65
> 3bd558a973/modules/core/src/main/java/org/apache/ignite/
> internal/binary/BinaryContext.java#L320
>
> Scala List seems working fine for me (did not thoroughly test it), but not
> vector. A simple demo here:
>
> val bin = ignite().binary()
> val k1 = Vector(“1”, “2”)
> val k2 = Vector(“1”) ++ Vector(“2”)
> k1 == k2 // true
> binary.toBinary(k1) == binary.toBinary(k2) // false
>
>
> Thanks!
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov