Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static <T> List<T> readRows(
var tupleReader = new BinaryTupleReader(rowSize, in.readBinaryUnsafe());
var reader = new ClientMarshallerReader(tupleReader, null, TuplePart.KEY_AND_VAL);

res.add((T) marshaller.readObject(reader));
res.add((T) marshaller.readObject(reader, null));
}
} catch (MarshallerException e) {
assert mapper != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ private HashMap<K, V> readGetAllResponse(ClientSchema schema, PayloadInputChanne
var tupleReader = new BinaryTupleReader(schema.columns().length, in.in().readBinaryUnsafe());
var keyReader = new ClientMarshallerReader(tupleReader, schema.keyColumns(), TuplePart.KEY_AND_VAL);
var valReader = new ClientMarshallerReader(tupleReader, schema.valColumns(), TuplePart.KEY_AND_VAL);
res.put((K) keyMarsh.readObject(keyReader), (V) valMarsh.readObject(valReader));
res.put((K) keyMarsh.readObject(keyReader, null), (V) valMarsh.readObject(valReader, null));
}
}

Expand Down Expand Up @@ -810,8 +810,8 @@ protected Function<SqlRow, Entry<K, V>> queryMapper(ResultSetMetadata meta, Clie
Marshaller valMarsh = schema.getMarshaller(valSer.mapper(), TuplePart.VAL, true);

return (row) -> new IgniteBiTuple<>(
(K) keyMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, keyCols))),
(V) valMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, valCols)))
(K) keyMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, keyCols)), null),
(V) valMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, valCols)), null)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ List<R> readRecs(ClientSchema schema, ClientMessageUnpacker in, boolean nullable
ClientColumn[] columns = schema.columns(part);
var tupleReader = new BinaryTupleReader(columns.length, in.readBinaryUnsafe());
var reader = new ClientMarshallerReader(tupleReader, columns, part);
res.add((R) marshaller.readObject(reader));
res.add((R) marshaller.readObject(reader, null));
}
}

Expand All @@ -261,7 +261,7 @@ R readRec(ClientSchema schema, ClientMessageUnpacker in, TuplePart partToRead, T
var tupleReader = new BinaryTupleReader(schema.columns().length, in.readBinaryUnsafe());
ClientMarshallerReader reader = new ClientMarshallerReader(tupleReader, schema.columns(partToRead), dataPart);

return (R) marshaller.readObject(reader);
return (R) marshaller.readObject(reader, null);
}

R readValRec(R keyRec, ClientSchema schema, ClientMessageUnpacker in) {
Expand All @@ -274,7 +274,7 @@ R readValRec(R keyRec, ClientSchema schema, ClientMessageUnpacker in) {
var tupleReader = new BinaryTupleReader(schema.columns().length, in.readBinaryUnsafe());
ClientMarshallerReader reader = new ClientMarshallerReader(tupleReader, schema.columns(), TuplePart.KEY_AND_VAL);

return (R) valMarshaller.readObject(reader);
return (R) valMarshaller.readObject(reader, null);
}

private static int columnCount(ClientSchema schema, TuplePart part) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,6 @@ protected Function<SqlRow, R> queryMapper(ResultSetMetadata meta, ClientSchema s
String[] cols = columnNames(schema.columns());
Marshaller marsh = schema.getMarshaller(ser.mapper(), TuplePart.KEY_AND_VAL, true);

return (row) -> (R) marsh.readObject(new TupleReader(new SqlRowProjection(row, meta, cols)));
return (row) -> (R) marsh.readObject(new TupleReader(new SqlRowProjection(row, meta, cols)), null);
}
}
1 change: 1 addition & 0 deletions modules/java-records-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ dependencies {
testFixturesImplementation testFixtures(project(':ignite-core'))

testImplementation project(':ignite-api')
testImplementation testFixtures(project(':ignite-core'))
testImplementation testFixtures(project(':java-records-tests'))
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ void componentsWide(Table t) {
void componentsWrongTypesThrowsException(Table t) {
String msgSubstring = "Column's type mismatch";

assertViewThrows(ClassCastException.class, msgSubstring, t, new ComponentsWrongTypes.Record((short) 1, 2));
assertViewThrows(ClassCastException.class, msgSubstring, t, new ComponentsWrongTypes.Class((short) 1, 2));
assertViewThrows(MarshallerException.class, msgSubstring, t, new ComponentsWrongTypes.Record((short) 1, 2));
assertViewThrows(MarshallerException.class, msgSubstring, t, new ComponentsWrongTypes.Class((short) 1, 2));

assertViewThrows(ClassCastException.class, msgSubstring, t,
assertViewThrows(MarshallerException.class, msgSubstring, t,
new ComponentsWrongTypes.RecordK((short) 1),
new ComponentsWrongTypes.RecordV(2)
);
assertViewThrows(ClassCastException.class, msgSubstring, t,
assertViewThrows(MarshallerException.class, msgSubstring, t,
new ComponentsWrongTypes.ClassK((short) 1),
new ComponentsWrongTypes.ClassV(2)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import org.apache.ignite.internal.schema.marshaller.Records.ComponentsWrongTypes;
import org.apache.ignite.internal.schema.marshaller.Records.NoDefaultConstructor;
import org.apache.ignite.internal.schema.marshaller.Records.NotAnnotatedNotMapped;
import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
import org.apache.ignite.lang.MarshallerException;
import org.junit.jupiter.api.Test;

/**
* Ensures that records and classes behave the same way.
*/
class MarshallerTest {
class MarshallerTest extends BaseIgniteAbstractTest {

@Test
void marshalUnmarshalTest() {
Expand Down Expand Up @@ -83,15 +84,15 @@ void componentsWrongTypesThrowsException() {
String msgSubstring = "Column's type mismatch";

// recordView
assertMarshallerThrows(ClassCastException.class, msgSubstring, new ComponentsWrongTypes.Record((short) 1, 2));
assertMarshallerThrows(ClassCastException.class, msgSubstring, new ComponentsWrongTypes.Class((short) 1, 2));
assertMarshallerThrows(MarshallerException.class, msgSubstring, new ComponentsWrongTypes.Record((short) 1, 2));
assertMarshallerThrows(MarshallerException.class, msgSubstring, new ComponentsWrongTypes.Class((short) 1, 2));

// kvView
assertMarshallerThrows(ClassCastException.class, msgSubstring,
assertMarshallerThrows(MarshallerException.class, msgSubstring,
new ComponentsWrongTypes.RecordK((short) 1),
new ComponentsWrongTypes.RecordV(2)
);
assertMarshallerThrows(ClassCastException.class, msgSubstring,
assertMarshallerThrows(MarshallerException.class, msgSubstring,
new ComponentsWrongTypes.ClassK((short) 1),
new ComponentsWrongTypes.ClassV(2)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ static <K, V, E extends Throwable> void assertMarshallerThrows(
IgniteTestUtils.assertThrows(expectedType, () -> assertMarshaller(expectedKey, expectedVal), msgSubstring);
}


static <T> void assertView(Table table, T expected) {
RecordView<T> view = (RecordView<T>) table.recordView(expected.getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ private Records() {}
});

static class ComponentsExact {

record RecordK(@Column("key") Integer id) { }

record RecordV(@Column("val") String val) { }

record Record(@Column("key") Integer id, @Column("val") String val) { }

record ExplicitCanonical(@Column("key") Integer id, @Column("val") String val) {
Expand Down Expand Up @@ -302,8 +305,8 @@ public boolean equals(Object obj) {
return false;
}
var that = (Class) obj;
return Objects.equals(this.val, that.val) &&
Objects.equals(this.id, that.id);
return Objects.equals(this.val, that.val)
&& Objects.equals(this.id, that.id);
}

@Override
Expand All @@ -314,8 +317,11 @@ public int hashCode() {
}

static class ComponentsWrongTypes {

record RecordK(@Column("key") Short id) { }

record RecordV(@Column("val") Integer val) { }

record Record(@Column("key") Short id, @Column("val") Integer val) { }

static final class Class {
Expand All @@ -340,8 +346,8 @@ public boolean equals(Object obj) {
return false;
}
var that = (Class) obj;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.val, that.val);
return Objects.equals(this.id, that.id)
&& Objects.equals(this.val, that.val);
}

@Override
Expand Down Expand Up @@ -408,7 +414,9 @@ public int hashCode() {
}

static class ComponentsEmpty {

record Record() { }

static final class Class {}
}

Expand All @@ -433,8 +441,8 @@ public boolean equals(Object obj) {
return false;
}
var that = (Class) obj;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.value, that.value);
return Objects.equals(this.id, that.id)
&& Objects.equals(this.value, that.value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static Marshaller pojoMarshaller(
* @return Object.
* @throws MarshallerException If failed.
*/
public abstract Object readObject(MarshallerReader reader) throws MarshallerException;
public abstract Object readObject(MarshallerReader reader, Object target) throws MarshallerException;

/**
* Write an object to a row.
Expand Down Expand Up @@ -233,7 +233,7 @@ Object value(Object obj, int fldIdx) {

/** {@inheritDoc} */
@Override
public Object readObject(MarshallerReader reader) {
public Object readObject(MarshallerReader reader, Object target) {
return fieldAccessor.read(reader);
}

Expand Down Expand Up @@ -281,7 +281,8 @@ private static class PojoMarshaller extends Marshaller {

/** {@inheritDoc} */
@Override
public Object readObject(MarshallerReader reader) throws MarshallerException {
public Object readObject(MarshallerReader reader, Object target) throws MarshallerException {
// target is always null, but this exact API is used by migration tools
return creator.createInstance(fieldAccessors, reader);
}

Expand All @@ -307,7 +308,7 @@ private static class NoOpMarshaller extends Marshaller {
}

@Override
public Object readObject(MarshallerReader reader) {
public Object readObject(MarshallerReader reader, Object target) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Row marshal(K key, @Nullable V val) throws MarshallerException {
public K unmarshalKeyOnly(Row row) throws MarshallerException {
assert row.elementCount() == keyPositions.length : "Number of key columns does not match";

Object o = keyMarsh.readObject(new RowReader(row));
Object o = keyMarsh.readObject(new RowReader(row), null);

assert keyClass.isInstance(o);

Expand All @@ -134,7 +134,7 @@ public K unmarshalKeyOnly(Row row) throws MarshallerException {
/** {@inheritDoc} */
@Override
public K unmarshalKey(Row row) throws MarshallerException {
Object o = keyMarsh.readObject(new RowReader(row, keyPositions));
Object o = keyMarsh.readObject(new RowReader(row, keyPositions), null);

assert keyClass.isInstance(o);

Expand All @@ -145,7 +145,7 @@ public K unmarshalKey(Row row) throws MarshallerException {
@Nullable
@Override
public V unmarshalValue(Row row) throws MarshallerException {
Object o = valMarsh.readObject(new RowReader(row, valPositions));
Object o = valMarsh.readObject(new RowReader(row, valPositions), null);

assert o == null || valClass.isInstance(o);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Row marshalKey(R rec) throws MarshallerException {
public R unmarshal(Row row) throws MarshallerException {
Marshaller marsh = row.keyOnly() ? keyMarsh : recMarsh;
RowReader reader = row.keyOnly() ? new RowReader(row, keyPositions) : new RowReader(row);
final Object o = marsh.readObject(reader);
final Object o = marsh.readObject(reader, null);

assert recClass.isInstance(o);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ protected Function<SqlRow, Entry<K, V>> queryMapper(ResultSetMetadata meta, Sche
Marshaller valMarsh = marshallers.getValuesMarshaller(marshallerSchema, valueMapper, false, true);

return (row) -> new IgniteBiTuple<>(
(K) keyMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(keyCols)))),
(V) valMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(valCols))))
(K) keyMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(keyCols))), null),
(V) valMarsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(valCols))), null)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,6 @@ protected Function<SqlRow, R> queryMapper(ResultSetMetadata meta, SchemaDescript
Marshaller marsh = marshallers.getRowMarshaller(marshallerSchema, mapper, false, true);
List<Column> cols = schema.columns();

return (row) -> (R) marsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(cols))));
return (row) -> (R) marsh.readObject(new TupleReader(new SqlRowProjection(row, meta, columnNames(cols))), null);
}
}