IgniteSqlInterpreter extends Interpreter { @Override public InterpreterResult interpret(String st, InterpreterContext context) { if (connEx != null) { return new InterpreterResult(Code.ERROR, connEx.getMessage()); } StringBuilder msg = new StringBuilder("%table "); try (Statement stmt = conn.createStatement()) { curStmt = stmt; try (ResultSet res = stmt.executeQuery(st)) { ResultSetMetaData md = res.getMetaData(); for (int i = 1; i <= md.getColumnCount(); i++) { if (i > 1) { msg.append('\t'); } msg.append(md.getColumnName(i)); } msg.append('\n'); while (res.next()) { for (int i = 1; i <= md.getColumnCount(); i++) { msg.append(res.getString(i)); if (i != md.getColumnCount()) { msg.append('\t'); } } msg.append('\n'); } } } catch (Exception e) { return IgniteInterpreterUtils.buildErrorResult(e); } finally { curStmt = null; } return new InterpreterResult(Code.SUCCESS, msg.toString()); } IgniteSqlInterpreter(Properties property); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String st, InterpreterContext context); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override Scheduler getScheduler(); @Override List<String> completion(String buf, int cursor);  }
@Test public void testSql() { InterpreterResult result = intp.interpret("select name, age from person where age > 10", INTP_CONTEXT); assertEquals(Code.SUCCESS, result.code()); assertEquals(Type.TABLE, result.type()); assertEquals("NAME\tAGE\nsun\t100\nmoon\t50\n", result.message()); }
@Test public void testInvalidSql() throws Exception { InterpreterResult result = intp.interpret("select * hrom person", INTP_CONTEXT); assertEquals(Code.ERROR, result.code()); }