Search in sources :

Example 1 with Struct

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

use of com.gemstone.gemfire.cache.query.Struct in project zeppelin by apache.

the class GeodeOqlInterpreterTest method oqlStructResponse.

@Test
public void oqlStructResponse() throws Exception {
    String[] fields = new String[] { "field1", "field2" };
    Struct s1 = new StructImpl(new StructTypeImpl(fields), new String[] { "val11", "val12" });
    Struct s2 = new StructImpl(new StructTypeImpl(fields), new String[] { "val21", "val22" });
    testOql(asIterator(s1, s2), "field1\tfield2\t\nval11\tval12\t\nval21\tval22\t\n", 10);
    testOql(asIterator(s1, s2), "field1\tfield2\t\nval11\tval12\t\n", 1);
}
Also used : StructImpl(com.gemstone.gemfire.cache.query.internal.StructImpl) StructTypeImpl(com.gemstone.gemfire.cache.query.internal.types.StructTypeImpl) Struct(com.gemstone.gemfire.cache.query.Struct) Test(org.junit.Test)

Example 3 with Struct

use of com.gemstone.gemfire.cache.query.Struct in project zeppelin by apache.

the class GeodeOqlInterpreterTest method oqlStructResponseWithReservedCharacters.

@Test
public void oqlStructResponseWithReservedCharacters() throws Exception {
    String[] fields = new String[] { "fi\teld1", "f\nield2" };
    Struct s1 = new StructImpl(new StructTypeImpl(fields), new String[] { "v\nal\t1", "val2" });
    testOql(asIterator(s1), "fi eld1\tf ield2\t\nv al 1\tval2\t\n", 10);
}
Also used : StructImpl(com.gemstone.gemfire.cache.query.internal.StructImpl) StructTypeImpl(com.gemstone.gemfire.cache.query.internal.types.StructTypeImpl) Struct(com.gemstone.gemfire.cache.query.Struct) Test(org.junit.Test)

Aggregations

Struct (com.gemstone.gemfire.cache.query.Struct)3 StructImpl (com.gemstone.gemfire.cache.query.internal.StructImpl)2 StructTypeImpl (com.gemstone.gemfire.cache.query.internal.types.StructTypeImpl)2 Test (org.junit.Test)2 SelectResults (com.gemstone.gemfire.cache.query.SelectResults)1 PdxInstance (com.gemstone.gemfire.pdx.PdxInstance)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1