Search in sources :

Example 1 with PdxInstance

use of com.gemstone.gemfire.pdx.PdxInstance in project zeppelin by apache.

the class GeodeOqlInterpreter method executeOql.

private InterpreterResult executeOql(String oql) {
    try {
        if (getExceptionOnConnect() != null) {
            return new InterpreterResult(Code.ERROR, getExceptionOnConnect().getMessage());
        }
        @SuppressWarnings("unchecked") SelectResults<Object> results = (SelectResults<Object>) getQueryService().newQuery(oql).execute();
        StringBuilder msg = new StringBuilder(TABLE_MAGIC_TAG);
        boolean isTableHeaderSet = false;
        Iterator<Object> iterator = results.iterator();
        int rowDisplayCount = 0;
        while (iterator.hasNext() && (rowDisplayCount < getMaxResult())) {
            Object entry = iterator.next();
            rowDisplayCount++;
            if (entry instanceof Number) {
                handleNumberEntry(isTableHeaderSet, entry, msg);
            } else if (entry instanceof Struct) {
                handleStructEntry(isTableHeaderSet, entry, msg);
            } else if (entry instanceof PdxInstance) {
                handlePdxInstanceEntry(isTableHeaderSet, entry, msg);
            } else {
                handleUnsupportedTypeEntry(isTableHeaderSet, entry, msg);
            }
            isTableHeaderSet = true;
            msg.append(NEWLINE);
        }
        return new InterpreterResult(Code.SUCCESS, msg.toString());
    } catch (Exception ex) {
        logger.error("Cannot run " + oql, ex);
        return new InterpreterResult(Code.ERROR, ex.getMessage());
    }
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Struct(com.gemstone.gemfire.cache.query.Struct) SelectResults(com.gemstone.gemfire.cache.query.SelectResults) PdxInstance(com.gemstone.gemfire.pdx.PdxInstance)

Example 2 with PdxInstance

use of com.gemstone.gemfire.pdx.PdxInstance in project zeppelin by apache.

the class GeodeOqlInterpreterTest method oqlPdxInstanceResponse.

@Test
public void oqlPdxInstanceResponse() throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream("koza\tboza\n".getBytes());
    PdxInstance pdx1 = new PdxInstanceImpl(new PdxType(), new DataInputStream(bais), 4);
    PdxInstance pdx2 = new PdxInstanceImpl(new PdxType(), new DataInputStream(bais), 4);
    testOql(asIterator(pdx1, pdx2), "\n\n\n", 10);
    testOql(asIterator(pdx1, pdx2), "\n\n", 1);
}
Also used : PdxInstance(com.gemstone.gemfire.pdx.PdxInstance) PdxInstanceImpl(com.gemstone.gemfire.pdx.internal.PdxInstanceImpl) PdxType(com.gemstone.gemfire.pdx.internal.PdxType) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 3 with PdxInstance

use of com.gemstone.gemfire.pdx.PdxInstance in project YCSB by brianfrankcooper.

the class GeodeClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    Region<String, PdxInstance> r = getRegion(table);
    PdxInstance val = r.get(key);
    if (val != null) {
        if (fields == null) {
            for (String fieldName : val.getFieldNames()) {
                result.put(fieldName, new ByteArrayByteIterator((byte[]) val.getField(fieldName)));
            }
        } else {
            for (String field : fields) {
                result.put(field, new ByteArrayByteIterator((byte[]) val.getField(field)));
            }
        }
        return Status.OK;
    }
    return Status.ERROR;
}
Also used : PdxInstance(com.gemstone.gemfire.pdx.PdxInstance)

Aggregations

PdxInstance (com.gemstone.gemfire.pdx.PdxInstance)3 SelectResults (com.gemstone.gemfire.cache.query.SelectResults)1 Struct (com.gemstone.gemfire.cache.query.Struct)1 PdxInstanceImpl (com.gemstone.gemfire.pdx.internal.PdxInstanceImpl)1 PdxType (com.gemstone.gemfire.pdx.internal.PdxType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 Test (org.junit.Test)1