Search in sources :

Example 6 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class RecordMarshallerValidationsTest method testReadOnly.

/**
 * Check ability to read into truncated class, but not write it.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testReadOnly(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final FullRecClass rec = new FullRecClass(1, 1, 2);
    RecordMarshaller<FullRecClass> marshallerFull = factory.create(schema, FullRecClass.class);
    BinaryRow row = marshallerFull.marshal(rec);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertEquals(rec.id, restoredRec.id);
    assertEquals(rec.fbyte1, restoredRec.fbyte1);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(restoredRec));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class RecordMarshallerValidationsTest method testColsWithNullable.

/**
 * Check nullable flag is taken into account if there is no field in specified class to marshall from.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithNullable(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    BinaryRow row = marshaller.marshal(rec);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class RecordMarshallerValidationsTest method testColsWithDefaultValue.

/**
 * Check default value is taken into account if there is no field in specified class to marshall from.
 */
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithDefaultValue(MarshallerFactory factory) throws MarshallerException {
    Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false, () -> 0x42) };
    SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
    final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
    RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
    BinaryRow row = marshaller.marshal(rec);
    TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with Row

use of org.apache.ignite.internal.schema.row.Row 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);
}
Also used : TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Example 10 with Row

use of org.apache.ignite.internal.schema.row.Row 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);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BigInteger(java.math.BigInteger) TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Row(org.apache.ignite.internal.schema.row.Row) UUID(org.apache.ignite.internal.schema.NativeTypes.UUID) Pair(org.apache.ignite.internal.util.Pair)

Aggregations

Row (org.apache.ignite.internal.schema.row.Row)83 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)55 Column (org.apache.ignite.internal.schema.Column)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)30 NotNull (org.jetbrains.annotations.NotNull)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 Tuple (org.apache.ignite.table.Tuple)21 Test (org.junit.jupiter.api.Test)18 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)15 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)15 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)15 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)14 ArrayList (java.util.ArrayList)8 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)6 Random (java.util.Random)5 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)5 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)5 IgniteException (org.apache.ignite.lang.IgniteException)5