use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testPrecisionRestrictionsForNumbers.
@Test
public void testPrecisionRestrictionsForNumbers() {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("number1", NativeTypes.numberOf(5), false) });
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Tuple badTup = createTuple().set("key", rnd.nextLong());
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(999991L))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("111111"))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", BigInteger.valueOf(-999991L))), "Column's type mismatch");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("number1", new BigInteger("-111111"))), "Column's type mismatch");
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testSameBinaryRepresentation.
/**
* Test.
*/
@ParameterizedTest
@MethodSource("sameDecimals")
public void testSameBinaryRepresentation(Pair<BigInteger, BigInteger> pair) throws Exception {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) });
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
long randomKey = rnd.nextLong();
final Tuple firstTup = createTuple().set("key", randomKey).set("decimalCol", pair.getFirst());
final Tuple secondTup = createTuple().set("key", randomKey).set("decimalCol", pair.getSecond());
final Row firstRow = marshaller.marshal(firstTup);
final Row secondRow = marshaller.marshal(secondTup);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
firstRow.writeTo(stream);
byte[] firstRowInBytes = stream.toByteArray();
stream.reset();
secondRow.writeTo(stream);
byte[] secondRowInBytes = stream.toByteArray();
assertArrayEquals(firstRowInBytes, secondRowInBytes);
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class NumericTypesSerializerTest method testPrecisionRestrictionsForDecimal.
@Test
public void testPrecisionRestrictionsForDecimal() {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(9, 3), false) });
final Tuple badTup = createTuple().set("key", rnd.nextLong());
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("123456789.0123"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("-1234567890123"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("1234567"))), "Failed to set decimal value for column");
assertThrows(TupleMarshallerException.class, () -> marshaller.marshal(badTup.set("decimalCol", new BigDecimal("12345678.9"))), "Failed to set decimal value for column");
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class TupleMarshallerFixlenOnlyBenchmark method init.
/**
* Setup.
*/
@Setup
public void init() {
long seed = System.currentTimeMillis();
rnd = new Random(seed);
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, IntStream.range(0, fieldsCount).boxed().map(i -> new Column("col" + i, NativeTypes.INT64, nullable)).toArray(Column[]::new));
marshaller = new TupleMarshallerImpl(new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION) {
@Override
public SchemaDescriptor schema() {
return schema;
}
@Override
public SchemaDescriptor schema(int ver) {
return schema;
}
@Override
public int lastSchemaVersion() {
return schema.version();
}
});
vals = new Object[schema.valueColumns().length()];
for (int i = 0; i < vals.length; i++) {
vals[i] = rnd.nextLong();
}
}
use of org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method getTuple.
private Tuple getTuple() {
try {
Tuple original = Tuple.create().set("id", 3L).set("name", "Shirt");
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
return TableRow.tuple(new Row(schema, new ByteBufferRow(marshaller.marshal(original).bytes())));
} catch (TupleMarshallerException e) {
return fail();
}
}
Aggregations