use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method remove.
@Test
public void remove() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
tbl.upsert(null, Tuple.create().set("id", 1L).set("val", 11L));
final Tuple keyTuple = Tuple.create().set("id", 1L);
// Delete not existed keyTuple.
assertFalse(tbl.delete(null, Tuple.create().set("id", 2L)));
// Delete existed keyTuple.
assertTrue(tbl.delete(null, keyTuple));
assertNull(tbl.get(null, keyTuple));
// Delete already deleted keyTuple.
assertFalse(tbl.delete(null, keyTuple));
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method validateSchema.
@Test
public void validateSchema() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, true), new Column("str".toUpperCase(), NativeTypes.stringOf(3), true), new Column("blob".toUpperCase(), NativeTypes.blobOf(3), true) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple keyTuple0 = new TestTupleBuilder().set("id", 0).set("id1", 0);
final Tuple keyTuple1 = new TestTupleBuilder().set("id1", 0);
final Tuple tuple0 = new TestTupleBuilder().set("id", 1L).set("str", "qweqweqwe").set("val", 11L);
final Tuple tuple1 = new TestTupleBuilder().set("id", 1L).set("blob", new byte[] { 0, 1, 2, 3 }).set("val", 22L);
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.get(null, keyTuple0));
assertThrowsWithCause(SchemaMismatchException.class, () -> tbl.get(null, keyTuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple1));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple0));
assertThrowsWithCause(InvalidTypeException.class, () -> tbl.replace(null, tuple1));
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method assertEqualsValues.
/**
* Check value columns equality.
*
* @param schema Schema.
* @param expected Expected tuple.
* @param actual Actual tuple.
*/
void assertEqualsValues(SchemaDescriptor schema, Tuple expected, Tuple actual) {
for (int i = 0; i < schema.valueColumns().length(); i++) {
final Column col = schema.valueColumns().column(i);
final Object val1 = expected.value(col.name());
final Object val2 = actual.value(col.name());
if (val1 instanceof byte[] && val2 instanceof byte[]) {
Assertions.assertArrayEquals((byte[]) val1, (byte[]) val2, "Equality check failed: colIdx=" + col.schemaIndex());
} else {
Assertions.assertEquals(val1, val2, "Equality check failed: colIdx=" + col.schemaIndex());
}
}
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class AbstractSerializerTest method schemaSerializeTest.
/**
* (de)Serialize schema test.
*/
@Test
public void schemaSerializeTest() {
AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false), new Column("B", NativeTypes.INT16, false), new Column("C", NativeTypes.INT32, false), new Column("D", NativeTypes.INT64, false), new Column("E", NativeTypes.UUID, false), new Column("F", NativeTypes.FLOAT, false), new Column("G", NativeTypes.DOUBLE, false), new Column("H", NativeTypes.DATE, false) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false), new Column("B1", NativeTypes.numberOf(255), false), new Column("C1", NativeTypes.decimalOf(128, 64), false), new Column("D1", NativeTypes.bitmaskOf(256), false), new Column("E1", NativeTypes.datetime(8), false), new Column("F1", NativeTypes.time(8), false), new Column("G1", NativeTypes.timestamp(8), true) });
byte[] serialize = assembler.serialize(desc);
SchemaDescriptor deserialize = assembler.deserialize(serialize);
assertEquals(desc.version(), deserialize.version());
assertArrayEquals(desc.keyColumns().columns(), deserialize.keyColumns().columns());
assertArrayEquals(desc.valueColumns().columns(), deserialize.valueColumns().columns());
assertArrayEquals(desc.colocationColumns(), deserialize.colocationColumns());
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class NumericTypesSerializerTest method testDecimalMaxScale.
@Test
public void testDecimalMaxScale() throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(Integer.MAX_VALUE, Integer.MAX_VALUE), false) });
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", BigDecimal.valueOf(123, Integer.MAX_VALUE));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), BigDecimal.valueOf(123, Integer.MAX_VALUE));
}
Aggregations