Search in sources :

Example 1 with RowAssembler

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);
}
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 2 with RowAssembler

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);
}
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)

Example 3 with RowAssembler

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

Example 4 with RowAssembler

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

Example 5 with RowAssembler

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

Aggregations

RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)34 Test (org.junit.jupiter.api.Test)16 Row (org.apache.ignite.internal.schema.row.Row)13 Column (org.apache.ignite.internal.schema.Column)10 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)6 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)5 TestSimpleObject (org.apache.ignite.internal.schema.testobjects.TestSimpleObject)4 BigInteger (java.math.BigInteger)3 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NotNull (org.jetbrains.annotations.NotNull)3 Columns (org.apache.ignite.internal.schema.Columns)2 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 ManagementFactory (java.lang.management.ManagementFactory)1 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 BigDecimal (java.math.BigDecimal)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1