use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TupleMarshallerVarlenOnlyBenchmark method measureTupleBuildAndMarshallerCost.
/**
* Measure tuple build then marshall.
*
* @param bh Black hole.
*/
@Benchmark
public void measureTupleBuildAndMarshallerCost(Blackhole bh) throws TupleMarshallerException {
final Columns cols = schema.valueColumns();
final Tuple valBld = Tuple.create(cols.length());
for (int i = 0; i < cols.length(); i++) {
valBld.set(cols.column(i).name(), val);
}
Tuple keyTuple = Tuple.create(1).set("key", rnd.nextLong());
final Row row = marshaller.marshal(keyTuple, valBld);
bh.consume(row);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class Example method useCase5.
/**
* Use case 5: using byte[] and binary objects in columns. The table has structure [ [id int, orgId int] // key [originalObject byte[],
* upgradedObject byte[], int department] // value ] Where {@code originalObject} is some value that was originally put to the column,
* {@code upgradedObject} is a version 2 of the object, and department is an extracted field.
*/
@Disabled
@ParameterizedTest
@MethodSource("tableFactory")
public void useCase5(Table t) {
Tuple res = t.recordView().get(null, Tuple.create().set("id", 1).set("orgId", 1));
byte[] objData = res.value("originalObject");
BinaryObject binObj = BinaryObjects.wrap(objData);
// Work with the binary object as in Ignite 2.x
// Additionally, we may have a shortcut similar to primitive methods.
binObj = res.binaryObjectValue("upgradedObject");
// Plain byte[] and BinaryObject fields in a class are straightforward.
class Record {
final int id;
final int orgId;
byte[] originalObject;
Tuple upgradedObject;
int department;
Record(int id, int orgId) {
this.id = id;
this.orgId = orgId;
}
}
RecordView<Record> recordView = t.recordView(Record.class);
// Similarly work with the binary objects.
Record rec = recordView.get(null, new Record(1, 1));
// Now assume that we have some POJO classes to deserialize the binary objects.
class JavaPerson {
String name;
String lastName;
}
class JavaPersonV2 extends JavaPerson {
int department;
}
// We can have a compound record deserializing the whole tuple automatically.
class JavaPersonRecord {
JavaPerson originalObject;
JavaPersonV2 upgradedObject;
int department;
}
RecordView<JavaPersonRecord> personRecordView = t.recordView(JavaPersonRecord.class);
// Or we can have an arbitrary record with custom class selection.
class TruncatedRecord {
JavaPerson upgradedObject;
int department;
}
// Custom serializer.
TypeConverter<JavaPerson, byte[]> serializer = new TypeConverter<>() {
@Override
public byte[] toColumnType(JavaPerson obj) throws Exception {
return BinaryObjects.serialize(obj).bytes();
}
@Override
public JavaPerson toObjectType(byte[] data) throws Exception {
return BinaryObjects.deserialize(BinaryObjects.wrap(data), JavaPerson.class);
}
};
RecordView<TruncatedRecord> truncatedView = t.recordView(Mapper.builder(TruncatedRecord.class).convert("upgradedObject", serializer).map("updradedObject", "updradedObject").build());
// Or we can have a custom conditional type selection.
RecordView<TruncatedRecord> truncatedView2 = t.recordView(Mapper.builder(TruncatedRecord.class).build());
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class InteropOperationsTest method writeRecordBinary.
/**
* Write through record binary view.
*
* @param id Id to write.
* @param nulls If {@code true} - nullable fields will be filled, if {@code false} - otherwise.
*/
private void writeRecordBinary(int id, boolean nulls) {
Tuple t1 = createTuple(id, nulls);
t1.set("id", (long) id);
assertTrue(R_BIN_VIEW.insert(null, t1));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class InteropOperationsTest method writeKeyValueBinary.
/**
* Write through binary view.
*
* @param id Id to write.
* @param nulls If {@code true} - nullable fields will be filled, if {@code false} - otherwise.
*/
private void writeKeyValueBinary(int id, boolean nulls) {
Tuple k = Tuple.create().set("id", (long) id);
Tuple v = createTuple(id, nulls);
KV_BIN_VIEW.put(null, k, v);
}
use of org.apache.ignite.table.Tuple 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