Search in sources :

Example 1 with SelectResults

use of com.gemstone.gemfire.cache.query.SelectResults 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)

Aggregations

SelectResults (com.gemstone.gemfire.cache.query.SelectResults)1 Struct (com.gemstone.gemfire.cache.query.Struct)1 PdxInstance (com.gemstone.gemfire.pdx.PdxInstance)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1