Let's clarify column order and nullable columns handling.

Our current API (Table, KvView) does not rely on column order in
user-provided tuples.
Therefore, two tuples with the same set of columns and equal values for
every column may be considered equal.

Tuple a = Tuple.create().set("name", "x").set("id", 1);
table.upsert(a);

Tuple key = Tuple.create().set("id", 1);
Tuple b = table.get(key); // id column goes first

// a was turned into b by Ignite, therefore they are equal.
assertTrue(a.equals(b));


It gets more complicated with nullable columns: should we consider a tuple
without column X and a tuple with column X set to null as equal?





On Fri, Sep 10, 2021 at 3:49 PM Igor Sapego <isap...@apache.org> wrote:

> Sounds very reasonable to me.
>
> +1
>
> Though the default comparator should be implemented very carefully
> as we had issues with comparison of binary objects in 2.x
>
> Best Regards,
> Igor
>
>
> On Thu, Sep 9, 2021 at 4:04 PM Pavel Tupitsyn <ptupit...@apache.org>
> wrote:
>
> > Igniters,
> >
> > Tuple in Ignite 3.x is a replacement for BinaryObject in Ignite 2.x.
> > Let's discuss equality and sorting.
> >
> > - We have multiple Tuple implementations, and our API allows custom,
> > user-defined Tuples as well (which can be useful for performance when
> > bridging Ignite with another system or importing the data from
> somewhere).
> > - We don't have equals()/hashCode() overrides, so it is not possible to
> > compare tuples or put them into a Map.
> >
> > Proposal:
> > - Add public TupleComparator implements Comparator<Tuple>, based on the
> > tuple contents (column names and values)
> > - Implement common TupleComparator#hashCode(Tuple t) method that combines
> > hash codes of column names and values
> > - Implement equals(), hashCode(), and Comparable on all built-in tuples,
> > delegate the logic to TupleComparator
> > - Make Tuple extend Compable
> >
> > This way we cover all sorting/comparing/mapping scenarios for built-in
> > tuples and provide reusable code for third-party implementations.
> >
> > Thoughts?
> >
>

Reply via email to