Search in sources :

Example 76 with SchemaDescriptor

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

the class NumericTypesSerializerTest method testNumber.

/**
 * Test.
 */
@ParameterizedTest
@MethodSource("numbers")
public void testNumber(Pair<BigInteger, BigInteger> pair) throws TupleMarshallerException {
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(19), false), new Column("number2", NativeTypes.numberOf(10), false) });
    TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
    final Tuple tup = createTuple().set("key", rnd.nextLong()).set("number1", pair.getFirst()).set("number2", pair.getSecond());
    final Row row = marshaller.marshal(tup);
    assertEquals(row.numberValue(1), row.numberValue(2));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Tuple(org.apache.ignite.table.Tuple) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 77 with SchemaDescriptor

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

the class ClientTableCommon method writeTuplesNullable.

/**
 * Writes multiple tuples with null flags.
 *
 * @param packer         Packer.
 * @param tuples         Tuples.
 * @param part           Which part of tuple to write.
 * @param schemaRegistry The registry.
 * @param skipHeader     Whether to skip the tuple header.
 * @throws IgniteException on failed serialization.
 */
public static void writeTuplesNullable(ClientMessagePacker packer, Collection<Tuple> tuples, TuplePart part, SchemaRegistry schemaRegistry, boolean skipHeader) {
    if (tuples == null || tuples.isEmpty()) {
        packer.packNil();
        return;
    }
    SchemaDescriptor schema = schemaRegistry.schema();
    packer.packInt(schema.version());
    packer.packInt(tuples.size());
    for (Tuple tuple : tuples) {
        if (tuple == null) {
            packer.packBoolean(false);
            continue;
        }
        assert schema.version() == ((SchemaAware) tuple).schema().version();
        packer.packBoolean(true);
        writeTuple(packer, tuple, schema, skipHeader, part);
    }
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) SchemaAware(org.apache.ignite.internal.schema.SchemaAware) Tuple(org.apache.ignite.table.Tuple)

Example 78 with SchemaDescriptor

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

the class ClientTableCommon method writeTuples.

/**
 * Writes multiple tuples.
 *
 * @param packer         Packer.
 * @param tuples         Tuples.
 * @param part           Which part of tuple to write.
 * @param schemaRegistry The registry.
 * @param skipHeader     Whether to skip the tuple header.
 * @throws IgniteException on failed serialization.
 */
public static void writeTuples(ClientMessagePacker packer, Collection<Tuple> tuples, TuplePart part, SchemaRegistry schemaRegistry, boolean skipHeader) {
    if (tuples == null || tuples.isEmpty()) {
        packer.packNil();
        return;
    }
    SchemaDescriptor schema = schemaRegistry.schema();
    packer.packInt(schema.version());
    packer.packInt(tuples.size());
    for (Tuple tuple : tuples) {
        assert tuple != null;
        assert schema.version() == ((SchemaAware) tuple).schema().version();
        writeTuple(packer, tuple, schema, skipHeader, part);
    }
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) SchemaAware(org.apache.ignite.internal.schema.SchemaAware) Tuple(org.apache.ignite.table.Tuple)

Example 79 with SchemaDescriptor

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

the class ClientTableCommon method readTuples.

/**
 * Reads multiple tuples.
 *
 * @param unpacker Unpacker.
 * @param table    Table.
 * @param keyOnly  Whether only key fields are expected.
 * @return Tuples.
 */
public static ArrayList<Tuple> readTuples(ClientMessageUnpacker unpacker, TableImpl table, boolean keyOnly) {
    SchemaDescriptor schema = readSchema(unpacker, table);
    var rowCnt = unpacker.unpackInt();
    var res = new ArrayList<Tuple>(rowCnt);
    for (int i = 0; i < rowCnt; i++) {
        res.add(readTuple(unpacker, keyOnly, schema));
    }
    return res;
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) ArrayList(java.util.ArrayList)

Example 80 with SchemaDescriptor

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

the class BinaryIndexRowFactory method createRowAssembler.

/**
 * Creates a {@link RowAssembler} that can later be used to serialized the given column mapping.
 */
private RowAssembler createRowAssembler(Object[] rowColumns) {
    SchemaDescriptor schemaDescriptor = descriptor.asSchemaDescriptor();
    int nonNullVarlenKeyCols = 0;
    for (Column column : schemaDescriptor.keyColumns().columns()) {
        Object columnValue = rowColumns[column.columnOrder()];
        if (!column.type().spec().fixedLength() && columnValue != null) {
            nonNullVarlenKeyCols += 1;
        }
    }
    return new RowAssembler(schemaDescriptor, nonNullVarlenKeyCols, 0);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5