@Test public void testHandleInputInputCmd() { assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.EXIT_COMMAND, connection), OperationResult.RETURN_OPER); assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.QUIT_COMMAND, connection), OperationResult.RETURN_OPER); assertEquals( AbstractClient.handleInputInputCmd(AbstractClient.SHOW_METADATA_COMMAND, connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=default", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OperationResult.CONTINUE_OPER); testSetTimeFormat(); assertEquals( AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=1", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OperationResult.CONTINUE_OPER); testSetMaxDisplayNumber(); assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMEZONE, connection), OperationResult.CONTINUE_OPER); assertEquals( AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMESTAMP_DISPLAY, connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_FETCH_SIZE, connection), OperationResult.CONTINUE_OPER); assertEquals(AbstractClient .handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIME_ZONE), connection), OperationResult.CONTINUE_OPER); assertEquals( AbstractClient.handleInputInputCmd(String.format("%s=+08:00", AbstractClient.SET_TIME_ZONE), connection), OperationResult.CONTINUE_OPER); assertEquals( AbstractClient .handleInputInputCmd(String.format("%s=", AbstractClient.SET_FETCH_SIZE), connection), OperationResult.CONTINUE_OPER); assertEquals( AbstractClient.handleInputInputCmd(String.format("%s=111", AbstractClient.SET_FETCH_SIZE), connection), OperationResult.CONTINUE_OPER); }
protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) { String specialCmd = cmd.toLowerCase().trim(); if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) { System.out.println(specialCmd + " normally"); return OperationResult.RETURN_OPER; } if (specialCmd.equals(HELP)) { System.out.println(String.format(" <your-sql>\t\t\t execute your sql statment")); System.out .println(String .format(" %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND)); System.out .println(String.format(" %s=xxx\t eg. long, default, ISO8601, yyyy-MM-dd HH:mm:ss.", SET_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s\t show time display type", SHOW_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s=xxx\t\t eg. +08:00, Asia/Shanghai.", SET_TIME_ZONE)); System.out.println(String.format(" %s\t\t show cli time zone", SHOW_TIMEZONE)); System.out.println( String.format(" %s=xxx\t\t set fetch size when querying data from server.", SET_FETCH_SIZE)); System.out.println(String.format(" %s\t\t show fetch size", SHOW_FETCH_SIZE)); System.out.println( String.format(" %s=xxx\t eg. set max lines for cli to ouput, -1 equals to unlimited.", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } if (specialCmd.equals(SHOW_METADATA_COMMAND)) { try { System.out.println(((IoTDBDatabaseMetadata) connection.getMetaData()).getMetadataInJson()); } catch (SQLException e) { System.out.println("Failed to show timeseries because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIMESTAMP_DISPLAY)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println(String.format("Time display format error, please input like %s=ISO8601", SET_TIMESTAMP_DISPLAY)); return OperationResult.CONTINUE_OPER; } try { setTimeFormat(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("time display format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time display type has set to " + cmd.split("=")[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIME_ZONE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println( String.format("Time zone format error, please input like %s=+08:00", SET_TIME_ZONE)); return OperationResult.CONTINUE_OPER; } try { connection.setTimeZone(cmd.split("=")[1].trim()); } catch (Exception e) { System.out.println(String.format("Time zone format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time zone has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_FETCH_SIZE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String .format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE)); return OperationResult.CONTINUE_OPER; } try { setFetchSize(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Fetch size format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Fetch size has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_MAX_DISPLAY_NUM)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String.format("Max display number format error, please input like %s = 10000", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } try { setMaxDisplayNumber(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Max display number format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Max display number has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMEZONE)) { try { System.out.println("Current time zone: " + connection.getTimeZone()); } catch (Exception e) { System.out.println("Cannot get time zone from server side because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) { System.out.println("Current time format: " + timeFormat); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_FETCH_SIZE)) { System.out.println("Current fetch size: " + fetchSize); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(IMPORT_CMD)) { String[] values = specialCmd.split(" "); if (values.length != 2) { System.out.println(String.format( "Please input like: import /User/myfile. " + "Noted that your file path cannot contain any space character)")); return OperationResult.CONTINUE_OPER; } try { System.out.println(cmd.split(" ")[1]); ImportCsv.importCsvFromFile(host, port, username, password, cmd.split(" ")[1], connection.getTimeZone()); } catch (SQLException e) { System.out.println( String .format("Failed to import from %s because %s", cmd.split(" ")[1], e.getMessage())); } catch (TException e) { System.out.println("Cannot connect to server"); } return OperationResult.CONTINUE_OPER; } Statement statement = null; long startTime = System.currentTimeMillis(); try { ZoneId zoneId = ZoneId.of(connection.getTimeZone()); statement = connection.createStatement(); statement.setFetchSize(fetchSize); boolean hasResultSet = statement.execute(cmd.trim()); if (hasResultSet) { ResultSet resultSet = statement.getResultSet(); output(resultSet, printToConsole, cmd.trim(), zoneId); } System.out.println("Execute successfully. Type `help` to get more information."); } catch (Exception e) { System.out.println("Msg: " + e.getMessage()); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { System.out.println("Cannot close statement because: " + e.getMessage()); } } } long costTime = System.currentTimeMillis() - startTime; System.out.println(String.format("It costs %.3fs", costTime / 1000.0)); return OperationResult.NO_OPER; }
AbstractClient { protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) { String specialCmd = cmd.toLowerCase().trim(); if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) { System.out.println(specialCmd + " normally"); return OperationResult.RETURN_OPER; } if (specialCmd.equals(HELP)) { System.out.println(String.format(" <your-sql>\t\t\t execute your sql statment")); System.out .println(String .format(" %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND)); System.out .println(String.format(" %s=xxx\t eg. long, default, ISO8601, yyyy-MM-dd HH:mm:ss.", SET_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s\t show time display type", SHOW_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s=xxx\t\t eg. +08:00, Asia/Shanghai.", SET_TIME_ZONE)); System.out.println(String.format(" %s\t\t show cli time zone", SHOW_TIMEZONE)); System.out.println( String.format(" %s=xxx\t\t set fetch size when querying data from server.", SET_FETCH_SIZE)); System.out.println(String.format(" %s\t\t show fetch size", SHOW_FETCH_SIZE)); System.out.println( String.format(" %s=xxx\t eg. set max lines for cli to ouput, -1 equals to unlimited.", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } if (specialCmd.equals(SHOW_METADATA_COMMAND)) { try { System.out.println(((IoTDBDatabaseMetadata) connection.getMetaData()).getMetadataInJson()); } catch (SQLException e) { System.out.println("Failed to show timeseries because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIMESTAMP_DISPLAY)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println(String.format("Time display format error, please input like %s=ISO8601", SET_TIMESTAMP_DISPLAY)); return OperationResult.CONTINUE_OPER; } try { setTimeFormat(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("time display format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time display type has set to " + cmd.split("=")[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIME_ZONE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println( String.format("Time zone format error, please input like %s=+08:00", SET_TIME_ZONE)); return OperationResult.CONTINUE_OPER; } try { connection.setTimeZone(cmd.split("=")[1].trim()); } catch (Exception e) { System.out.println(String.format("Time zone format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time zone has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_FETCH_SIZE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String .format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE)); return OperationResult.CONTINUE_OPER; } try { setFetchSize(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Fetch size format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Fetch size has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_MAX_DISPLAY_NUM)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String.format("Max display number format error, please input like %s = 10000", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } try { setMaxDisplayNumber(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Max display number format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Max display number has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMEZONE)) { try { System.out.println("Current time zone: " + connection.getTimeZone()); } catch (Exception e) { System.out.println("Cannot get time zone from server side because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) { System.out.println("Current time format: " + timeFormat); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_FETCH_SIZE)) { System.out.println("Current fetch size: " + fetchSize); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(IMPORT_CMD)) { String[] values = specialCmd.split(" "); if (values.length != 2) { System.out.println(String.format( "Please input like: import /User/myfile. " + "Noted that your file path cannot contain any space character)")); return OperationResult.CONTINUE_OPER; } try { System.out.println(cmd.split(" ")[1]); ImportCsv.importCsvFromFile(host, port, username, password, cmd.split(" ")[1], connection.getTimeZone()); } catch (SQLException e) { System.out.println( String .format("Failed to import from %s because %s", cmd.split(" ")[1], e.getMessage())); } catch (TException e) { System.out.println("Cannot connect to server"); } return OperationResult.CONTINUE_OPER; } Statement statement = null; long startTime = System.currentTimeMillis(); try { ZoneId zoneId = ZoneId.of(connection.getTimeZone()); statement = connection.createStatement(); statement.setFetchSize(fetchSize); boolean hasResultSet = statement.execute(cmd.trim()); if (hasResultSet) { ResultSet resultSet = statement.getResultSet(); output(resultSet, printToConsole, cmd.trim(), zoneId); } System.out.println("Execute successfully. Type `help` to get more information."); } catch (Exception e) { System.out.println("Msg: " + e.getMessage()); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { System.out.println("Cannot close statement because: " + e.getMessage()); } } } long costTime = System.currentTimeMillis() - startTime; System.out.println(String.format("It costs %.3fs", costTime / 1000.0)); return OperationResult.NO_OPER; } }
AbstractClient { protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) { String specialCmd = cmd.toLowerCase().trim(); if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) { System.out.println(specialCmd + " normally"); return OperationResult.RETURN_OPER; } if (specialCmd.equals(HELP)) { System.out.println(String.format(" <your-sql>\t\t\t execute your sql statment")); System.out .println(String .format(" %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND)); System.out .println(String.format(" %s=xxx\t eg. long, default, ISO8601, yyyy-MM-dd HH:mm:ss.", SET_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s\t show time display type", SHOW_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s=xxx\t\t eg. +08:00, Asia/Shanghai.", SET_TIME_ZONE)); System.out.println(String.format(" %s\t\t show cli time zone", SHOW_TIMEZONE)); System.out.println( String.format(" %s=xxx\t\t set fetch size when querying data from server.", SET_FETCH_SIZE)); System.out.println(String.format(" %s\t\t show fetch size", SHOW_FETCH_SIZE)); System.out.println( String.format(" %s=xxx\t eg. set max lines for cli to ouput, -1 equals to unlimited.", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } if (specialCmd.equals(SHOW_METADATA_COMMAND)) { try { System.out.println(((IoTDBDatabaseMetadata) connection.getMetaData()).getMetadataInJson()); } catch (SQLException e) { System.out.println("Failed to show timeseries because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIMESTAMP_DISPLAY)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println(String.format("Time display format error, please input like %s=ISO8601", SET_TIMESTAMP_DISPLAY)); return OperationResult.CONTINUE_OPER; } try { setTimeFormat(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("time display format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time display type has set to " + cmd.split("=")[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIME_ZONE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println( String.format("Time zone format error, please input like %s=+08:00", SET_TIME_ZONE)); return OperationResult.CONTINUE_OPER; } try { connection.setTimeZone(cmd.split("=")[1].trim()); } catch (Exception e) { System.out.println(String.format("Time zone format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time zone has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_FETCH_SIZE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String .format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE)); return OperationResult.CONTINUE_OPER; } try { setFetchSize(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Fetch size format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Fetch size has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_MAX_DISPLAY_NUM)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String.format("Max display number format error, please input like %s = 10000", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } try { setMaxDisplayNumber(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Max display number format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Max display number has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMEZONE)) { try { System.out.println("Current time zone: " + connection.getTimeZone()); } catch (Exception e) { System.out.println("Cannot get time zone from server side because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) { System.out.println("Current time format: " + timeFormat); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_FETCH_SIZE)) { System.out.println("Current fetch size: " + fetchSize); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(IMPORT_CMD)) { String[] values = specialCmd.split(" "); if (values.length != 2) { System.out.println(String.format( "Please input like: import /User/myfile. " + "Noted that your file path cannot contain any space character)")); return OperationResult.CONTINUE_OPER; } try { System.out.println(cmd.split(" ")[1]); ImportCsv.importCsvFromFile(host, port, username, password, cmd.split(" ")[1], connection.getTimeZone()); } catch (SQLException e) { System.out.println( String .format("Failed to import from %s because %s", cmd.split(" ")[1], e.getMessage())); } catch (TException e) { System.out.println("Cannot connect to server"); } return OperationResult.CONTINUE_OPER; } Statement statement = null; long startTime = System.currentTimeMillis(); try { ZoneId zoneId = ZoneId.of(connection.getTimeZone()); statement = connection.createStatement(); statement.setFetchSize(fetchSize); boolean hasResultSet = statement.execute(cmd.trim()); if (hasResultSet) { ResultSet resultSet = statement.getResultSet(); output(resultSet, printToConsole, cmd.trim(), zoneId); } System.out.println("Execute successfully. Type `help` to get more information."); } catch (Exception e) { System.out.println("Msg: " + e.getMessage()); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { System.out.println("Cannot close statement because: " + e.getMessage()); } } } long costTime = System.currentTimeMillis() - startTime; System.out.println(String.format("It costs %.3fs", costTime / 1000.0)); return OperationResult.NO_OPER; }  }
AbstractClient { protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) { String specialCmd = cmd.toLowerCase().trim(); if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) { System.out.println(specialCmd + " normally"); return OperationResult.RETURN_OPER; } if (specialCmd.equals(HELP)) { System.out.println(String.format(" <your-sql>\t\t\t execute your sql statment")); System.out .println(String .format(" %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND)); System.out .println(String.format(" %s=xxx\t eg. long, default, ISO8601, yyyy-MM-dd HH:mm:ss.", SET_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s\t show time display type", SHOW_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s=xxx\t\t eg. +08:00, Asia/Shanghai.", SET_TIME_ZONE)); System.out.println(String.format(" %s\t\t show cli time zone", SHOW_TIMEZONE)); System.out.println( String.format(" %s=xxx\t\t set fetch size when querying data from server.", SET_FETCH_SIZE)); System.out.println(String.format(" %s\t\t show fetch size", SHOW_FETCH_SIZE)); System.out.println( String.format(" %s=xxx\t eg. set max lines for cli to ouput, -1 equals to unlimited.", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } if (specialCmd.equals(SHOW_METADATA_COMMAND)) { try { System.out.println(((IoTDBDatabaseMetadata) connection.getMetaData()).getMetadataInJson()); } catch (SQLException e) { System.out.println("Failed to show timeseries because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIMESTAMP_DISPLAY)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println(String.format("Time display format error, please input like %s=ISO8601", SET_TIMESTAMP_DISPLAY)); return OperationResult.CONTINUE_OPER; } try { setTimeFormat(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("time display format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time display type has set to " + cmd.split("=")[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIME_ZONE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println( String.format("Time zone format error, please input like %s=+08:00", SET_TIME_ZONE)); return OperationResult.CONTINUE_OPER; } try { connection.setTimeZone(cmd.split("=")[1].trim()); } catch (Exception e) { System.out.println(String.format("Time zone format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time zone has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_FETCH_SIZE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String .format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE)); return OperationResult.CONTINUE_OPER; } try { setFetchSize(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Fetch size format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Fetch size has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_MAX_DISPLAY_NUM)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String.format("Max display number format error, please input like %s = 10000", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } try { setMaxDisplayNumber(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Max display number format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Max display number has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMEZONE)) { try { System.out.println("Current time zone: " + connection.getTimeZone()); } catch (Exception e) { System.out.println("Cannot get time zone from server side because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) { System.out.println("Current time format: " + timeFormat); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_FETCH_SIZE)) { System.out.println("Current fetch size: " + fetchSize); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(IMPORT_CMD)) { String[] values = specialCmd.split(" "); if (values.length != 2) { System.out.println(String.format( "Please input like: import /User/myfile. " + "Noted that your file path cannot contain any space character)")); return OperationResult.CONTINUE_OPER; } try { System.out.println(cmd.split(" ")[1]); ImportCsv.importCsvFromFile(host, port, username, password, cmd.split(" ")[1], connection.getTimeZone()); } catch (SQLException e) { System.out.println( String .format("Failed to import from %s because %s", cmd.split(" ")[1], e.getMessage())); } catch (TException e) { System.out.println("Cannot connect to server"); } return OperationResult.CONTINUE_OPER; } Statement statement = null; long startTime = System.currentTimeMillis(); try { ZoneId zoneId = ZoneId.of(connection.getTimeZone()); statement = connection.createStatement(); statement.setFetchSize(fetchSize); boolean hasResultSet = statement.execute(cmd.trim()); if (hasResultSet) { ResultSet resultSet = statement.getResultSet(); output(resultSet, printToConsole, cmd.trim(), zoneId); } System.out.println("Execute successfully. Type `help` to get more information."); } catch (Exception e) { System.out.println("Msg: " + e.getMessage()); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { System.out.println("Cannot close statement because: " + e.getMessage()); } } } long costTime = System.currentTimeMillis() - startTime; System.out.println(String.format("It costs %.3fs", costTime / 1000.0)); return OperationResult.NO_OPER; }  static void output(ResultSet res, boolean printToConsole, String statement, ZoneId zoneId); }
AbstractClient { protected static OperationResult handleInputInputCmd(String cmd, IoTDBConnection connection) { String specialCmd = cmd.toLowerCase().trim(); if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) { System.out.println(specialCmd + " normally"); return OperationResult.RETURN_OPER; } if (specialCmd.equals(HELP)) { System.out.println(String.format(" <your-sql>\t\t\t execute your sql statment")); System.out .println(String .format(" %s\t\t show how many timeseries are in iotdb", SHOW_METADATA_COMMAND)); System.out .println(String.format(" %s=xxx\t eg. long, default, ISO8601, yyyy-MM-dd HH:mm:ss.", SET_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s\t show time display type", SHOW_TIMESTAMP_DISPLAY)); System.out.println(String.format(" %s=xxx\t\t eg. +08:00, Asia/Shanghai.", SET_TIME_ZONE)); System.out.println(String.format(" %s\t\t show cli time zone", SHOW_TIMEZONE)); System.out.println( String.format(" %s=xxx\t\t set fetch size when querying data from server.", SET_FETCH_SIZE)); System.out.println(String.format(" %s\t\t show fetch size", SHOW_FETCH_SIZE)); System.out.println( String.format(" %s=xxx\t eg. set max lines for cli to ouput, -1 equals to unlimited.", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } if (specialCmd.equals(SHOW_METADATA_COMMAND)) { try { System.out.println(((IoTDBDatabaseMetadata) connection.getMetaData()).getMetadataInJson()); } catch (SQLException e) { System.out.println("Failed to show timeseries because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIMESTAMP_DISPLAY)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println(String.format("Time display format error, please input like %s=ISO8601", SET_TIMESTAMP_DISPLAY)); return OperationResult.CONTINUE_OPER; } try { setTimeFormat(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("time display format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time display type has set to " + cmd.split("=")[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_TIME_ZONE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out.println( String.format("Time zone format error, please input like %s=+08:00", SET_TIME_ZONE)); return OperationResult.CONTINUE_OPER; } try { connection.setTimeZone(cmd.split("=")[1].trim()); } catch (Exception e) { System.out.println(String.format("Time zone format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Time zone has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_FETCH_SIZE)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String .format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE)); return OperationResult.CONTINUE_OPER; } try { setFetchSize(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Fetch size format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Fetch size has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SET_MAX_DISPLAY_NUM)) { String[] values = specialCmd.split("="); if (values.length != 2) { System.out .println(String.format("Max display number format error, please input like %s = 10000", SET_MAX_DISPLAY_NUM)); return OperationResult.CONTINUE_OPER; } try { setMaxDisplayNumber(cmd.split("=")[1]); } catch (Exception e) { System.out.println(String.format("Max display number format error, %s", e.getMessage())); return OperationResult.CONTINUE_OPER; } System.out.println("Max display number has set to " + values[1].trim()); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMEZONE)) { try { System.out.println("Current time zone: " + connection.getTimeZone()); } catch (Exception e) { System.out.println("Cannot get time zone from server side because: " + e.getMessage()); } return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) { System.out.println("Current time format: " + timeFormat); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(SHOW_FETCH_SIZE)) { System.out.println("Current fetch size: " + fetchSize); return OperationResult.CONTINUE_OPER; } if (specialCmd.startsWith(IMPORT_CMD)) { String[] values = specialCmd.split(" "); if (values.length != 2) { System.out.println(String.format( "Please input like: import /User/myfile. " + "Noted that your file path cannot contain any space character)")); return OperationResult.CONTINUE_OPER; } try { System.out.println(cmd.split(" ")[1]); ImportCsv.importCsvFromFile(host, port, username, password, cmd.split(" ")[1], connection.getTimeZone()); } catch (SQLException e) { System.out.println( String .format("Failed to import from %s because %s", cmd.split(" ")[1], e.getMessage())); } catch (TException e) { System.out.println("Cannot connect to server"); } return OperationResult.CONTINUE_OPER; } Statement statement = null; long startTime = System.currentTimeMillis(); try { ZoneId zoneId = ZoneId.of(connection.getTimeZone()); statement = connection.createStatement(); statement.setFetchSize(fetchSize); boolean hasResultSet = statement.execute(cmd.trim()); if (hasResultSet) { ResultSet resultSet = statement.getResultSet(); output(resultSet, printToConsole, cmd.trim(), zoneId); } System.out.println("Execute successfully. Type `help` to get more information."); } catch (Exception e) { System.out.println("Msg: " + e.getMessage()); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { System.out.println("Cannot close statement because: " + e.getMessage()); } } } long costTime = System.currentTimeMillis() - startTime; System.out.println(String.format("It costs %.3fs", costTime / 1000.0)); return OperationResult.NO_OPER; }  static void output(ResultSet res, boolean printToConsole, String statement, ZoneId zoneId);  }