Vladsz83 commented on code in PR #12189: URL: https://github.com/apache/ignite/pull/12189#discussion_r2228189537
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/GroupKey.java: ########## @@ -17,86 +17,98 @@ package org.apache.ignite.internal.processors.query.calcite.exec.exp.agg; -import java.util.Arrays; -import org.apache.ignite.internal.util.typedef.X; +import java.util.Objects; +import org.apache.ignite.binary.BinaryObjectException; +import org.apache.ignite.binary.BinaryRawReader; +import org.apache.ignite.binary.BinaryRawWriter; +import org.apache.ignite.binary.BinaryReader; +import org.apache.ignite.binary.BinaryWriter; +import org.apache.ignite.binary.Binarylizable; +import org.apache.ignite.internal.processors.query.calcite.exec.ArrayRowHandler; +import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler; /** * */ -public class GroupKey { +public class GroupKey<Row> implements Binarylizable { /** */ - public static final GroupKey EMPTY_GRP_KEY = new GroupKey(X.EMPTY_OBJECT_ARRAY); + private Row row; /** */ - private final Object[] fields; + private RowHandler<Row> hnd; /** */ - public GroupKey(Object[] fields) { - this.fields = fields; + public GroupKey(Row row, RowHandler<Row> hnd) { + this.row = row; + this.hnd = hnd; } /** */ - public Object[] fields() { - return fields; + public Row row() { + return row; + } + + /** */ + public RowHandler<Row> rowHandler() { + return hnd; } /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { + BinaryRawWriter rawWriter = writer.rawWriter(); - GroupKey grpKey = (GroupKey)o; + int colCnt = hnd.columnCount(row); - return Arrays.equals(fields, grpKey.fields); + rawWriter.writeInt(colCnt); + + for (int i = 0; i < colCnt; i++) + rawWriter.writeObject(hnd.get(i, row)); } /** {@inheritDoc} */ - @Override public int hashCode() { - return Arrays.hashCode(fields); - } + @Override public void readBinary(BinaryReader reader) throws BinaryObjectException { + BinaryRawReader rawReader = reader.rawReader(); - /** */ - public static Builder builder(int rowLen) { - return new Builder(rowLen); - } + int colCnt = rawReader.readInt(); - /** */ - public static class Builder { - /** */ - private final Object[] fields; + Object[] row0 = new Object[colCnt]; - /** */ - private int idx; + for (int i = 0; i < colCnt; i++) + row0[i] = rawReader.readObject(); - /** */ - private Builder(int rowLen) { - fields = new Object[rowLen]; - } + row = (Row)row0; + hnd = (RowHandler<Row>)ArrayRowHandler.INSTANCE; + } - /** */ - public Builder add(Object val) { - if (idx == fields.length) - throw new IndexOutOfBoundsException(); + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; - fields[idx++] = val; + GroupKey<Row> other = (GroupKey<Row>)o; - return this; - } + int colCnt = hnd.columnCount(row); - /** */ - public GroupKey build() { - assert idx == fields.length; + if (colCnt != other.hnd.columnCount(other.row)) + return false; - return new GroupKey(fields); + for (int i = 0; i < colCnt; i++) { + if (!Objects.equals(hnd.get(i, row), other.hnd.get(i, other.row))) + return false; } - /** */ - public void clear() { - Arrays.fill(fields, null); + return true; + } - idx = 0; - } + /** {@inheritDoc} */ + @Override public int hashCode() { Review Comment: Can be cached? Or row may change? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org