HiveInterpreter extends Interpreter { public String getPropertyKey(String cmd) { int firstLineIndex = cmd.indexOf("\n"); if (-1 == firstLineIndex) { firstLineIndex = cmd.length(); } int configStartIndex = cmd.indexOf("("); int configLastIndex = cmd.indexOf(")"); if (configStartIndex != -1 && configLastIndex != -1 && configLastIndex < firstLineIndex && configLastIndex < firstLineIndex) { return cmd.substring(configStartIndex + 1, configLastIndex); } return null; } HiveInterpreter(Properties property); HashMap<String, Properties> getPropertiesMap(); @Override void open(); @Override void close(); Connection getConnection(String propertyKey); Statement getStatement(String propertyKey, String paragraphId); InterpreterResult executeSql(String propertyKey, String sql,
                                      InterpreterContext interpreterContext); @Override InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter); String getPropertyKey(String cmd); @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 getPropertyKey() { HiveInterpreter hi = new HiveInterpreter(new Properties()); hi.open(); String testCommand = "(default)\nshow tables"; assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); testCommand = "(default) show tables"; assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); hi.close(); }