use of org.apache.ignite.binary.BinaryField in project ignite by apache.
the class BinaryFieldsAbstractSelfTest method context.
/**
* Get test context.
*
* @param marsh Binary marshaller.
* @param fieldName Field name.
* @return Test context.
* @throws Exception If failed.
*/
private TestContext context(BinaryMarshaller marsh, String fieldName) throws Exception {
TestObject obj = createObject();
BinaryObjectExImpl portObj = toBinary(marsh, obj);
BinaryField field = portObj.type().field(fieldName);
return new TestContext(obj, portObj, field);
}
use of org.apache.ignite.binary.BinaryField in project ignite by apache.
the class QueryBinaryProperty method binaryField.
/**
* Get binary field for the property.
*
* @param obj Target object.
* @return Binary field.
*/
private BinaryField binaryField(BinaryObject obj) {
if (ctx.query().skipFieldLookup())
return null;
BinaryField field0 = field;
if (field0 == null && !fieldTaken) {
BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx) obj).rawType() : obj.type();
if (type != null) {
field0 = type.field(propName);
assert field0 != null;
field = field0;
}
fieldTaken = true;
}
return field0;
}
use of org.apache.ignite.binary.BinaryField in project ignite by apache.
the class BinaryFooterOffsetsAbstractSelfTest method check.
/**
* Main check routine.
*
* @param len Length of the first field.
*
* @throws Exception If failed.
*/
private void check(int len) throws Exception {
TestObject obj = new TestObject(len);
BinaryObjectExImpl portObj = toBinary(marsh, obj);
assertEquals(portObj.size(), portObj.length());
// 1. Test binary object content.
assert portObj.hasField("field1");
assert portObj.hasField("field2");
byte[] field1 = portObj.field("field1");
Integer field2 = portObj.field("field2");
assert field1 != null;
assert field2 != null;
assert Arrays.equals(obj.field1, field1);
assert obj.field2 == field2;
// 2. Test fields API.
BinaryField field1Desc = portObj.type().field("field1");
BinaryField field2Desc = portObj.type().field("field2");
assert field1Desc.exists(portObj);
assert field2Desc.exists(portObj);
assert Arrays.equals(obj.field1, (byte[]) field1Desc.value(portObj));
assert obj.field2 == (Integer) field2Desc.value(portObj);
// 3. Test deserialize.
TestObject objRestored = portObj.deserialize();
assert objRestored != null;
assert Arrays.equals(obj.field1, objRestored.field1);
assert obj.field2 == objRestored.field2;
}
use of org.apache.ignite.binary.BinaryField in project YCSB by brianfrankcooper.
the class IgniteClient method read.
/**
* Read a record from the database. Each field/value pair from the result will
* be stored in a HashMap.
*
* @param table The name of the table
* @param key The record key of the record to read.
* @param fields The list of fields to read, or null for all of them
* @param result A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error
*/
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
BinaryObject po = cache.get(key);
if (po == null) {
return Status.NOT_FOUND;
}
if (binType == null) {
binType = po.type();
}
for (String s : F.isEmpty(fields) ? binType.fieldNames() : fields) {
BinaryField bfld = fieldsCache.get(s);
if (bfld == null) {
bfld = binType.field(s);
fieldsCache.put(s, bfld);
}
String val = bfld.value(po);
if (val != null) {
result.put(s, new StringByteIterator(val));
}
if (debug) {
log.info("table:{" + table + "}, key:{" + key + "}" + ", fields:{" + fields + "}");
log.info("fields in po{" + binType.fieldNames() + "}");
log.info("result {" + result + "}");
}
}
return Status.OK;
} catch (Exception e) {
log.error(String.format("Error reading key: %s", key), e);
return Status.ERROR;
}
}
Aggregations