use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class ColumnBindingTest method nullableFieldsBinding.
/**
* Nullable fields binding.
*
* @throws Exception If failed.
*/
@Test
public void nullableFieldsBinding() throws Exception {
Column[] cols = new Column[] { new Column("intCol", INT32, true), new Column("longCol", INT64, true), new Column("stringCol", STRING, true), new Column("bytesCol", BYTES, true) };
final Pair<RowAssembler, Row> mocks = createMocks();
final RowAssembler rowAssembler = mocks.getFirst();
final Row row = mocks.getSecond();
final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
for (int i = 0; i < cols.length; i++) {
ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).write(rowAssembler, obj);
}
final TestSimpleObject restoredObj = new TestSimpleObject();
for (int i = 0; i < cols.length; i++) {
ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).read(row, restoredObj);
}
assertEquals(obj, restoredObj);
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class ColumnBindingTest method createMocks.
/**
* Creates mock pair for {@link Row} and {@link RowAssembler}.
*
* @return Pair of mocks.
*/
private Pair<RowAssembler, Row> createMocks() {
final ArrayList<Object> vals = new ArrayList<>();
final RowAssembler mockedAsm = Mockito.mock(RowAssembler.class);
final Row mockedRow = Mockito.mock(Row.class);
final Answer<Void> asmAnswer = new Answer<>() {
@Override
public Void answer(InvocationOnMock invocation) {
if ("appendNull".equals(invocation.getMethod().getName())) {
vals.add(null);
} else {
vals.add(invocation.getArguments()[0]);
}
return null;
}
};
final Answer<Object> rowAnswer = new Answer<>() {
@Override
public Object answer(InvocationOnMock invocation) {
final int idx = invocation.getArgument(0, Integer.class);
return vals.get(idx);
}
};
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendNull();
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendByte(Mockito.anyByte());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendShort(Mockito.anyShort());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendInt(Mockito.anyInt());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendLong(Mockito.anyLong());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendFloat(Mockito.anyFloat());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendDouble(Mockito.anyDouble());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendUuid(Mockito.any(java.util.UUID.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendBitmask(Mockito.any(BitSet.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendString(Mockito.anyString());
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendBytes(Mockito.any(byte[].class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendNumber(Mockito.any(BigInteger.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendDecimal(Mockito.any(BigDecimal.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendDate(Mockito.any(LocalDate.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendDateTime(Mockito.any(LocalDateTime.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendTime(Mockito.any(LocalTime.class));
Mockito.doAnswer(asmAnswer).when(mockedAsm).appendTimestamp(Mockito.any(Instant.class));
Mockito.doAnswer(rowAnswer).when(mockedRow).byteValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).byteValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).shortValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).shortValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).intValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).intValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).longValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).longValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).floatValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).floatValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).doubleValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).doubleValueBoxed(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).dateValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).timeValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).dateTimeValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).timestampValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).uuidValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).bitmaskValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).stringValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).bytesValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).numberValue(Mockito.anyInt());
Mockito.doAnswer(rowAnswer).when(mockedRow).decimalValue(Mockito.anyInt());
return new Pair<>(mockedAsm, mockedRow);
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class RowAssemblerAdvancedSchemaTest method fixedNullableColumns.
/**
* Validate row layout for schema of fix-len nullable key and fix-len nullable value.
*/
@Test
public void fixedNullableColumns() {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("keyCol", INT8, false) }, new Column[] { new Column("valCol2", INT8, true), new Column("valCol1", INT32, true), new Column("valCol3", INT16, true) });
// Last col null
assertRowBytesEquals(new byte[] { 42, 0, 125, 64, 31, -9, 6, 0, 0, 0, 0, 22, 9, 0, 0, 0, 0, 4, -44, -66, -1 }, new RowAssembler(schema, 0, 0).appendByte((byte) 22).appendByte((byte) -44).appendShort((short) -66).appendNull().toBytes());
// First col null.
assertRowBytesEquals(new byte[] { 42, 0, 125, 64, 31, -9, 6, 0, 0, 0, 0, 22, 12, 0, 0, 0, 0, 1, -55, -1, -66, -1, -1, -1 }, new RowAssembler(schema, 0, 0).appendByte((byte) 22).appendNull().appendShort((short) -55).appendInt(-66).toBytes());
// Middle col null.
assertRowBytesEquals(new byte[] { 42, 0, 125, 64, 31, -9, 6, 0, 0, 0, 0, 22, 11, 0, 0, 0, 0, 2, -44, -66, -1, -1, -1 }, new RowAssembler(schema, 0, 0).appendByte((byte) 22).appendByte((byte) -44).appendNull().appendInt(-66).toBytes());
// All null.
assertRowBytesEquals(new byte[] { 42, 0, 125, 64, 31, -9, 6, 0, 0, 0, 0, 22, 6, 0, 0, 0, 0, 7 }, new RowAssembler(schema, 0, 0).appendByte((byte) 22).appendNull().appendNull().appendNull().toBytes());
// No value.
assertRowBytesEquals(new byte[] { 0, 0, 125, 64, 31, -9, 6, 0, 0, 0, 0, 22 }, new RowAssembler(schema, 0, 0).appendByte((byte) 22).toBytes());
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class RowAssemblerSimpleSchemaTest method fixedKeyFixedNullableValue.
/**
* Validate row layout for schema of fix-len non-null key and fix-len nullable value.
*/
@Test
public void fixedKeyFixedNullableValue() {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("keyIntCol", INT32, false) }, new Column[] { new Column("valIntCol", INT32, true) });
assertRowBytesEquals(new byte[] { 42, 0, -4, -111, -102, -5, 9, 0, 0, 0, 0, 33, 0, 0, 0, 10, 0, 0, 0, 0, 0, -71, -1, -1, -1 }, new RowAssembler(schema, 0, 0).appendInt(33).appendInt(-71).toBytes());
// Null value.
assertRowBytesEquals(new byte[] { 42, 0, -4, -111, -102, -5, 9, 0, 0, 0, 0, 33, 0, 0, 0, 6, 0, 0, 0, 0, 1 }, new RowAssembler(schema, 0, 0).appendInt(33).appendNull().toBytes());
// No value.
assertRowBytesEquals(new byte[] { 0, 0, -4, -111, -102, -5, 9, 0, 0, 0, 0, 33, 0, 0, 0 }, new RowAssembler(schema, 0, 0).appendInt(33).toBytes());
}
use of org.apache.ignite.internal.schema.row.RowAssembler in project ignite-3 by apache.
the class RowAssemblerSimpleSchemaTest method varlenKeyFixedValue.
/**
* Validate row layout for schema of var-len non-null key and fix-len non-null value.
*/
@Test
public void varlenKeyFixedValue() {
SchemaDescriptor schema = new SchemaDescriptor(42, new Column[] { new Column("keyStrCol", STRING, false) }, new Column[] { new Column("valUuidCol", UUID, false) });
assertRowBytesEquals(new byte[] { 42, 0, 64, -119, 105, 64, 8, 0, 0, 0, 0, 107, 101, 121, 21, 0, 0, 0, 0, -117, -61, -31, 85, 61, -32, 57, 68, 111, 67, 56, -3, -99, -37, -58, -73 }, new RowAssembler(schema, 1, 0).appendString("key").appendUuid(uuidVal).toBytes());
// No value.
assertRowBytesEquals(new byte[] { 0, 0, 64, -119, 105, 64, 8, 0, 0, 0, 0, 107, 101, 121 }, new RowAssembler(schema, 1, 0).appendString("key").toBytes());
}
Aggregations