Search in sources :

Example 11 with BinaryField

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);
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField)

Example 12 with BinaryField

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;
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField) BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectEx(org.apache.ignite.internal.binary.BinaryObjectEx)

Example 13 with BinaryField

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;
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField)

Example 14 with BinaryField

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;
    }
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField) BinaryObject(org.apache.ignite.binary.BinaryObject) EntryProcessorException(javax.cache.processor.EntryProcessorException)

Aggregations

BinaryField (org.apache.ignite.binary.BinaryField)14 BinaryObject (org.apache.ignite.binary.BinaryObject)3 BinaryType (org.apache.ignite.binary.BinaryType)3 BinaryObjectEx (org.apache.ignite.internal.binary.BinaryObjectEx)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 AffinityKeyMapper (org.apache.ignite.cache.affinity.AffinityKeyMapper)2 CacheDefaultBinaryAffinityKeyMapper (org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper)2 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)2 GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntryProcessorException (javax.cache.processor.EntryProcessorException)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)1 T1 (org.apache.ignite.internal.util.typedef.T1)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.Test)1