[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest 
api
URL: https://github.com/apache/incubator-iotdb/pull/777#discussion_r376899481
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/rest/controller/RestController.java
 ##
 @@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.rest.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.auth.authorizer.IAuthorizer;
+import org.apache.iotdb.db.auth.authorizer.LocalFileAuthorizer;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.rest.service.RestService;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * It’s used for mapping http request.
+ */
+
+@Path("/")
+public class RestController {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(RestController.class);
+  private RestService restService = RestService.getInstance();
+
+  /**
+   * http request to login IoTDB
+   */
+
+  @Path("/login")
+  @POST
+  @Consumes(MediaType.TEXT_PLAIN)
+  public void login(@Context HttpServletRequest request)
+  throws AuthException {
+JSONObject jsonObject = restService.getRequestBodyJson(request);
+String username = (String)jsonObject.get("username");
+String password = (String)jsonObject.get("password");
+logger.info("{}: receive http request from username {}", 
IoTDBConstant.GLOBAL_DB_NAME,
+username);
+IAuthorizer authorizer = LocalFileAuthorizer.getInstance();
+boolean status = authorizer.login(username, password);
+if (status) {
+  restService.setUsername(username);
+  logger.info("{}: Login successfully. User : {}", 
IoTDBConstant.GLOBAL_DB_NAME, username);
+} else {
+  throw new AuthException("Wrong login password");
+}
+  }
+
+  /**
+   *
+   * @param request this request will be in json format.
+   * @return json in String
+   */
+  @Path("/query")
 
 Review comment:
   add a UserGuide of rest apis


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest 
api
URL: https://github.com/apache/incubator-iotdb/pull/777#discussion_r376898735
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/rest/model/TimeValues.java
 ##
 @@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.rest.model;
+
+public class TimeValues {
 
 Review comment:
   ```suggestion
   public class TimeValue {
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest 
api
URL: https://github.com/apache/incubator-iotdb/pull/777#discussion_r376898335
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metrics/sink/JsonServletSink.java
 ##
 @@ -1,46 +1,46 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
- * agreements. See the NOTICE file distributed with this work for additional 
information regarding
- * copyright ownership. The ASF licenses this file to you under the Apache 
License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the 
License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software 
distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
- * or implied. See the License for the specific language governing permissions 
and limitations under
- * the License.
- */
-package org.apache.iotdb.db.metrics.sink;
-
-import java.util.concurrent.TimeUnit;
-import org.apache.iotdb.db.metrics.server.JettyUtil;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.json.MetricsModule;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class MetricsServletSink implements Sink {
-
-  public MetricRegistry registry;
-
-  public MetricsServletSink(MetricRegistry registry) {
-this.registry = registry;
-  }
-
-  public ServletContextHandler getHandler() {
-ObjectMapper mapper = new ObjectMapper()
-.registerModule(new MetricsModule(TimeUnit.SECONDS, 
TimeUnit.MILLISECONDS, false));
-return JettyUtil.createMetricsServletHandler(mapper, registry);
-  }
-
-  @Override
-  public void start() {}
-
-  @Override
-  public void stop() {}
-
-  @Override
-  public void report() {}
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
 
 Review comment:
   format this


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #777: [IoTDB-400] Support rest 
api
URL: https://github.com/apache/incubator-iotdb/pull/777#discussion_r376898248
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java
 ##
 @@ -66,7 +67,7 @@ private String inferHostname() {
 } catch (UnknownHostException e) {
   logger.error("The host is unknow", e);
 }
-return ia.getHostName();
+return Objects.requireNonNull(ia).getHostName();
 
 Review comment:
   change ia to a more meaningful name


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583931592
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583982972
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on issue #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on issue #782: [IOTDB-405] cache results in the client and 
makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#issuecomment-583981133
 
 
   My test case is:
   
   SET STORAGE GROUP TO root.turbine;
   create timeseries root.turbine.d1.s0 with datatype=DOUBLE, encoding=GORILLA, 
compression=SNAPPY;
   create timeseries root.turbine.d2.s0 with datatype=DOUBLE, encoding=GORILLA, 
compression=SNAPPY;
   insert into root.turbine.d1(time,s0) values(4,4);
   select * from root;


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #777: [IoTDB-400] Support rest api
URL: https://github.com/apache/incubator-iotdb/pull/777#issuecomment-583958353
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [29 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
 [4.7% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #777: [IoTDB-400] Support rest api
URL: https://github.com/apache/incubator-iotdb/pull/777#issuecomment-583976304
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [29 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
 [4.6% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376880761
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -805,34 +503,100 @@ private static void importCmd(String specialCmd, String 
cmd, IoTDBConnection con
 } catch (SQLException e) {
   println(String.format("Failed to import from %s because %s",
   cmd.split(" ")[1], e.getMessage()));
-  handleException(e);
 } catch (TException e) {
   println("Cannot connect to server");
-  handleException(e);
 }
   }
 
   private static void executeQuery(IoTDBConnection connection, String cmd) {
 long startTime = System.currentTimeMillis();
-try (Statement statement = connection.createStatement();) {
+try (Statement statement = connection.createStatement()) {
   ZoneId zoneId = ZoneId.of(connection.getTimeZone());
   statement.setFetchSize(fetchSize);
   boolean hasResultSet = statement.execute(cmd.trim());
   if (hasResultSet) {
-ResultSet resultSet = statement.getResultSet();
-output(resultSet, printToConsole, zoneId);
-if (resultSet != null) {
-  resultSet.close();
+try (ResultSet resultSet = statement.getResultSet()) {
+  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+  int columnLength = resultSetMetaData.getColumnCount();
+  List maxSizeList = new ArrayList<>(columnLength);
+  List> lists = cacheResult(resultSet, maxSizeList, 
columnLength,
+  resultSetMetaData, zoneId);
+  output(lists, maxSizeList);
 }
   }
 } catch (Exception e) {
   println("Msg: " + e.getMessage());
-  handleException(e);
 }
 long costTime = System.currentTimeMillis() - startTime;
 println(String.format("It costs %.3fs", costTime / 1000.0));
   }
 
+  private static List> cacheResult(ResultSet resultSet, 
List maxSizeList,
+  int columnLength, ResultSetMetaData resultSetMetaData, ZoneId zoneId)
+  throws SQLException {
+boolean printTimestamp = !((IoTDBQueryResultSet) 
resultSet).isIgnoreTimeStamp();
+List> lists = new ArrayList<>(columnLength);
+for(int i = 1; i <= columnLength; i++) {
+  List list = new ArrayList<>(30);
 
 Review comment:
   change this 30 to a field of this class


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376881310
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -805,34 +503,100 @@ private static void importCmd(String specialCmd, String 
cmd, IoTDBConnection con
 } catch (SQLException e) {
   println(String.format("Failed to import from %s because %s",
   cmd.split(" ")[1], e.getMessage()));
-  handleException(e);
 } catch (TException e) {
   println("Cannot connect to server");
-  handleException(e);
 }
   }
 
   private static void executeQuery(IoTDBConnection connection, String cmd) {
 long startTime = System.currentTimeMillis();
-try (Statement statement = connection.createStatement();) {
+try (Statement statement = connection.createStatement()) {
   ZoneId zoneId = ZoneId.of(connection.getTimeZone());
   statement.setFetchSize(fetchSize);
   boolean hasResultSet = statement.execute(cmd.trim());
   if (hasResultSet) {
-ResultSet resultSet = statement.getResultSet();
-output(resultSet, printToConsole, zoneId);
-if (resultSet != null) {
-  resultSet.close();
+try (ResultSet resultSet = statement.getResultSet()) {
+  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+  int columnLength = resultSetMetaData.getColumnCount();
+  List maxSizeList = new ArrayList<>(columnLength);
+  List> lists = cacheResult(resultSet, maxSizeList, 
columnLength,
+  resultSetMetaData, zoneId);
+  output(lists, maxSizeList);
 }
   }
 } catch (Exception e) {
   println("Msg: " + e.getMessage());
-  handleException(e);
 }
 long costTime = System.currentTimeMillis() - startTime;
 println(String.format("It costs %.3fs", costTime / 1000.0));
   }
 
+  private static List> cacheResult(ResultSet resultSet, 
List maxSizeList,
 
 Review comment:
   add some javadoc


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376880400
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -82,89 +82,29 @@
   static final String TIMESTAMP_STR = "Time";
   static final int ISO_DATETIME_LEN = 35;
   private static final String IMPORT_CMD = "import";
-  private static final String NEED_NOT_TO_PRINT_TIMESTAMP = "AGGREGATION";
   private static final String DEFAULT_TIME_FORMAT = "default";
   private static String timeFormat = DEFAULT_TIME_FORMAT;
   static int maxPrintRowCount = 10;
   private static int fetchSize = 1;
 
 Review comment:
   ```suggestion
 private static int fetchSize = 1000;
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376880334
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -82,89 +82,29 @@
   static final String TIMESTAMP_STR = "Time";
   static final int ISO_DATETIME_LEN = 35;
   private static final String IMPORT_CMD = "import";
-  private static final String NEED_NOT_TO_PRINT_TIMESTAMP = "AGGREGATION";
   private static final String DEFAULT_TIME_FORMAT = "default";
   private static String timeFormat = DEFAULT_TIME_FORMAT;
   static int maxPrintRowCount = 10;
 
 Review comment:
   ```suggestion
 static int maxPrintRowCount = 1000;
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376881482
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -805,34 +503,100 @@ private static void importCmd(String specialCmd, String 
cmd, IoTDBConnection con
 } catch (SQLException e) {
   println(String.format("Failed to import from %s because %s",
   cmd.split(" ")[1], e.getMessage()));
-  handleException(e);
 } catch (TException e) {
   println("Cannot connect to server");
-  handleException(e);
 }
   }
 
   private static void executeQuery(IoTDBConnection connection, String cmd) {
 long startTime = System.currentTimeMillis();
-try (Statement statement = connection.createStatement();) {
+try (Statement statement = connection.createStatement()) {
   ZoneId zoneId = ZoneId.of(connection.getTimeZone());
   statement.setFetchSize(fetchSize);
   boolean hasResultSet = statement.execute(cmd.trim());
   if (hasResultSet) {
-ResultSet resultSet = statement.getResultSet();
-output(resultSet, printToConsole, zoneId);
-if (resultSet != null) {
-  resultSet.close();
+try (ResultSet resultSet = statement.getResultSet()) {
+  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+  int columnLength = resultSetMetaData.getColumnCount();
+  List maxSizeList = new ArrayList<>(columnLength);
+  List> lists = cacheResult(resultSet, maxSizeList, 
columnLength,
+  resultSetMetaData, zoneId);
+  output(lists, maxSizeList);
 }
   }
 } catch (Exception e) {
   println("Msg: " + e.getMessage());
 
 Review comment:
   There is a null pointer exception, I can not print result in my client. Try 
to fix it...


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #782: [IOTDB-405] cache results in the client and makes the display look nice.

2020-02-09 Thread GitBox
qiaojialin commented on a change in pull request #782: [IOTDB-405] cache 
results in the client and makes the display look nice.
URL: https://github.com/apache/incubator-iotdb/pull/782#discussion_r376881232
 
 

 ##
 File path: client/src/main/java/org/apache/iotdb/client/AbstractClient.java
 ##
 @@ -805,34 +503,100 @@ private static void importCmd(String specialCmd, String 
cmd, IoTDBConnection con
 } catch (SQLException e) {
   println(String.format("Failed to import from %s because %s",
   cmd.split(" ")[1], e.getMessage()));
-  handleException(e);
 } catch (TException e) {
   println("Cannot connect to server");
-  handleException(e);
 }
   }
 
   private static void executeQuery(IoTDBConnection connection, String cmd) {
 long startTime = System.currentTimeMillis();
-try (Statement statement = connection.createStatement();) {
+try (Statement statement = connection.createStatement()) {
   ZoneId zoneId = ZoneId.of(connection.getTimeZone());
   statement.setFetchSize(fetchSize);
   boolean hasResultSet = statement.execute(cmd.trim());
   if (hasResultSet) {
-ResultSet resultSet = statement.getResultSet();
-output(resultSet, printToConsole, zoneId);
-if (resultSet != null) {
-  resultSet.close();
+try (ResultSet resultSet = statement.getResultSet()) {
+  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+  int columnLength = resultSetMetaData.getColumnCount();
+  List maxSizeList = new ArrayList<>(columnLength);
+  List> lists = cacheResult(resultSet, maxSizeList, 
columnLength,
+  resultSetMetaData, zoneId);
+  output(lists, maxSizeList);
 }
   }
 } catch (Exception e) {
   println("Msg: " + e.getMessage());
-  handleException(e);
 }
 long costTime = System.currentTimeMillis() - startTime;
 println(String.format("It costs %.3fs", costTime / 1000.0));
   }
 
+  private static List> cacheResult(ResultSet resultSet, 
List maxSizeList,
+  int columnLength, ResultSetMetaData resultSetMetaData, ZoneId zoneId)
+  throws SQLException {
+boolean printTimestamp = !((IoTDBQueryResultSet) 
resultSet).isIgnoreTimeStamp();
+List> lists = new ArrayList<>(columnLength);
+for(int i = 1; i <= columnLength; i++) {
+  List list = new ArrayList<>(30);
+  list.add(resultSetMetaData.getColumnLabel(i));
+  lists.add(list);
+  maxSizeList.add(resultSetMetaData.getColumnLabel(i).length());
+}
+int j = 0;
+while (resultSet.next()) {
+  if(j > maxPrintRowCount) {
+break;
+  }
+  for(int i = 1; i <= columnLength; i++) {
+String tmp;
+if(printTimestamp && i == 1) {
+  tmp = formatDatetime(resultSet.getLong(TIMESTAMP_STR), zoneId);
+} else {
+  tmp = resultSet.getString(i);
+}
+lists.get(i-1).add(tmp);
+if(maxSizeList.get(i-1) < tmp.length()) {
 
 Review comment:
   format


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #777: [IoTDB-400] Support rest api
URL: https://github.com/apache/incubator-iotdb/pull/777#issuecomment-583958353
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [29 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
 [4.7% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #777: [IoTDB-400] Support rest api

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #777: [IoTDB-400] Support rest api
URL: https://github.com/apache/incubator-iotdb/pull/777#issuecomment-583285745
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
 [29 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=777=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
 [4.7% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=777=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583926295
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583931592
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583926295
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583867895
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583867895
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-583806007
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb=713=false=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb=713=new_duplicated_lines_density=list)
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jack870131 commented on a change in pull request #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
jack870131 commented on a change in pull request #713: [IOTDB-418] New series 
reader
URL: https://github.com/apache/incubator-iotdb/pull/713#discussion_r376798228
 
 

 ##
 File path: docs/Documentation-CHN/SystemDesign/5-DataQuery/3-RawDataQuery.md
 ##
 @@ -0,0 +1,301 @@
+
+
+# 原始数据查询
+
+## 设计原理
+
+原始数据查询根据是否包含值过滤条件,可以分为两类。不包含值过滤条件时,根据结果集结构又可分为两类。
+
+* 不包含值过滤条件(无过滤条件 or 仅包含时间过滤条件)
+   * 结果集按时间戳对齐(默认原始数据查询)
+   * 结果集不按时间戳对齐(disable align)
+* 包含值过滤条件
+   * 结果集按时间戳对齐
+
+以上三种查询在代码中对应三种不同的 DataSet,封装了这三种查询的执行逻辑。
+
+## 不包含值过滤条件 + 结果集按时间戳对齐
+
+### org.apache.iotdb.db.query.dataset.RawQueryDataSetWithoutValueFilter
+
+`RawQueryDataSetWithoutValueFilter`实现了没有值过滤条件,且需要按照时间戳对齐的查询逻辑。虽然最后的查询结果需要每个时间序列按照时间戳对齐,但是每个时间序列的查询是可以做并行化的。这里借助消费者-生产者队列的思想,将每个时间序列获取数据的操作与最后对所有时间序列进行对齐的操作解耦。每个时间序列对应一个生产者线程,且有其对应的`BlockingQueue`,生产者任务负责读取相应的时间序列的数据放进`BlockingQueue`中;消费者线程只有一个,负责从每个时间序列的`BlockingQueue`中取出数据,进行时间戳对齐之后,将结果组装成`TSQueryDataSet`形式返回。
+
+在具体实现的时候,考虑到机器的资源限制,并非为每个查询的每一个时间序列创建一个线程,而是采用线程池技术,将每一个时间序列的生产者任务当作一个`Runnable`的task提交到线程池中执行。
+
+下面就先介绍生产者的代码,它被封装在是`RawQueryDataSetWithoutValueFilter`的一个内部类`ReadTask`中,实现了`Runnable`接口。
+
+### 
org.apache.iotdb.db.query.dataset.RawQueryDataSetWithoutValueFilter.ReadTask
+
+`ReadTask`中有两个字段
+
+* private final ManagedSeriesReader reader;
+* private BlockingQueue blockingQueue;
+
+`ManagedSeriesReader`接口继承了`IBatchReader`接口,主要用来读取单个时间序列的数据,并且新增了以下四个方法
+
+```
+boolean isManagedByQueryManager();
+
+void setManagedByQueryManager(boolean managedByQueryManager);
+
+boolean hasRemaining();
+
+void setHasRemaining(boolean hasRemaining);
+```
+
+前两个方法用以表征该时间序列对应的生产者任务有没有被查询管理器所管理,即生产者任务有没有因为阻塞队列满了,而自行退出(后文会解释为什么不阻塞等待,而是直接退出);后两个方法用以表征该时间序列对应的reader里还有没有数据。
+
+`blockingQueue`就是该生产者任务的阻塞队列,实际上该阻塞队列只会在消费者取数据时单边阻塞,生产者放数据时,如果发现队列满了,便会直接退出,不会阻塞。
+
+下面看一下`ReadTask`的`run()`方法,执行流程的解释以注释的形式展现在代码中
+
+ run()
+
+```
+public void run() {
+  try {
+// 这里加锁的原因是为了保证对于blockingQueue满不满的判断是正确同步的
+synchronized (reader) {
+  // 
由于每次提交生产者任务时(不论是生产者自己递归的提交自己,还是消费者发现生产者任务自行退出而提交的),都会检查队列是不是满的,如果队列满了,是不会提交生产者任务的
+  // 所以生产者任务一旦被提交,blockingQueue里一定是有空余位置的,我们不需要检查队列是否满
+  // 如果时间序列对应的reader还有数据,进入循环体
+  while (reader.hasNextBatch()) {
+BatchData batchData = reader.nextBatch();
+// 由于拿到的BatchData有可能为空,所以需要一直迭代到第一个不为空的BatchData
+if (batchData.isEmpty()) {
+  continue;
+}
+// 将不为空的batchData放进阻塞队列中,此时的阻塞队列一定是不满的,所以不会阻塞
+blockingQueue.put(batchData);
+// 如果阻塞队列仍然没有满,生产者任务再次向线程池里递归地提交自己,进行下一个batchData的获取
+if (blockingQueue.remainingCapacity() > 0) {
+  pool.submit(this);
+}
+// 如果阻塞队列满了,生产者任务退出,并将对应reader的managedByQueryManager置为false
+else {
+  reader.setManagedByQueryManager(false);
+}
+return;
+  }
+  // 代码执行到这边,代表之前的while循环条件不满足,即该时间序列对应的reader里没有数据了
+  // 我们往阻塞队列里放入一个SignalBatchData,用以告知消费者,这个时间序列已经没有数据了,不需要再从该时间序列对应的队列里取数据了
+  blockingQueue.put(SignalBatchData.getInstance());
+  // 将reader的hasRemaining字段置为false
+  // 通知消费者不需要再为这个时间序列提交生产者任务
+  reader.setHasRemaining(false);
+  // 将reader的managedByQueryManager字段置为false
+  reader.setManagedByQueryManager(false);
+}
+  } catch (InterruptedException e) {
+LOGGER.error("Interrupted while putting into the blocking queue: ", e);
+Thread.currentThread().interrupt();
+  } catch (IOException e) {
+LOGGER.error("Something gets wrong while reading from the series reader: 
", e);
+  } catch (Exception e) {
+LOGGER.error("Something gets wrong: ", e);
+  }
+}
+```
+
+接下来介绍消费者的代码,消费者的主要逻辑是从每个时间序列的队列里拿出值,做时间戳对齐,然后拼凑结果集。时间戳的对齐主要通过一个时间戳的最小堆来实现,如果该时间序列的时间戳等于堆顶的时间戳,则取出该值,反之,将该时间戳下该时间序列的值置为`null`。
+
+先介绍消费者任务的一些重要字段
+
+* TreeSet timeHeap
+
+  时间戳的最小堆,用以实现时间戳对齐操作
+
+* BlockingQueue[] blockingQueueArray;
+
+  阻塞队列的数组,用以存储每个时间序列对应的阻塞队列
+
+* boolean[] noMoreDataInQueueArray
+
+  用以表征某个时间序列的阻塞队列里还有没有值,如果为false,则消费者不会再去调用`take()`方法,以防消费者线程被阻塞。
+  
+* BatchData[] cachedBatchDataArray
+
+  缓存从阻塞队列里取出的一个BatchData,因为阻塞队列里`take()`出的`BatchData`并不能一次性消费完,所以需要做缓存
+  
+在消费者`RawQueryDataSetWithoutValueFilter`的构造函数里首先调用了`init()`方法
+
+ int()
+
+```
+private void init() throws InterruptedException {
+   timeHeap = new TreeSet<>();
+   // 为每个时间序列构建生产者任务
+   for (int i = 0; i < seriesReaderList.size(); i++) {
+ ManagedSeriesReader reader = seriesReaderList.get(i);
+ reader.setHasRemaining(true);
+ reader.setManagedByQueryManager(true);
+ pool.submit(new ReadTask(reader, blockingQueueArray[i]));
+   }
+   // 初始化最小堆,填充每个时间序列对应的缓存
+   for (int i = 0; i < seriesReaderList.size(); i++) {
+ // 调用fillCache(int)方法填充缓存
+ fillCache(i);
+ // 尝试将每个时间序列的当前最小时间戳放进堆中
+ if (cachedBatchDataArray[i] != null && 
cachedBatchDataArray[i].hasCurrent()) {
+   long time = cachedBatchDataArray[i].currentTime();
+   timeHeap.add(time);
+ }
+   }
+}
+```
+
+  fillCache(int)
+

[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #713: [IOTDB-418] New series reader

2020-02-09 Thread GitBox
wshao08 commented on a change in pull request #713: [IOTDB-418] New series 
reader
URL: https://github.com/apache/incubator-iotdb/pull/713#discussion_r376309678
 
 

 ##
 File path: docs/Documentation-CHN/SystemDesign/5-DataQuery/3-RawDataQuery.md
 ##
 @@ -0,0 +1,301 @@
+
+
+# 原始数据查询
+
+## 设计原理
+
+原始数据查询根据是否包含值过滤条件,可以分为两类。不包含值过滤条件时,根据结果集结构又可分为两类。
+
+* 不包含值过滤条件(无过滤条件 or 仅包含时间过滤条件)
+   * 结果集按时间戳对齐(默认原始数据查询)
+   * 结果集不按时间戳对齐(disable align)
+* 包含值过滤条件
+   * 结果集按时间戳对齐
+
+以上三种查询在代码中对应三种不同的 DataSet,封装了这三种查询的执行逻辑。
+
+## 不包含值过滤条件 + 结果集按时间戳对齐
+
+### org.apache.iotdb.db.query.dataset.RawQueryDataSetWithoutValueFilter
+
+`RawQueryDataSetWithoutValueFilter`实现了没有值过滤条件,且需要按照时间戳对齐的查询逻辑。虽然最后的查询结果需要每个时间序列按照时间戳对齐,但是每个时间序列的查询是可以做并行化的。这里借助消费者-生产者队列的思想,将每个时间序列获取数据的操作与最后对所有时间序列进行对齐的操作解耦。每个时间序列对应一个生产者线程,且有其对应的`BlockingQueue`,生产者任务负责读取相应的时间序列的数据放进`BlockingQueue`中;消费者线程只有一个,负责从每个时间序列的`BlockingQueue`中取出数据,进行时间戳对齐之后,将结果组装成`TSQueryDataSet`形式返回。
+
+在具体实现的时候,考虑到机器的资源限制,并非为每个查询的每一个时间序列创建一个线程,而是采用线程池技术,将每一个时间序列的生产者任务当作一个`Runnable`的task提交到线程池中执行。
+
+下面就先介绍生产者的代码,它被封装在是`RawQueryDataSetWithoutValueFilter`的一个内部类`ReadTask`中,实现了`Runnable`接口。
+
+### 
org.apache.iotdb.db.query.dataset.RawQueryDataSetWithoutValueFilter.ReadTask
+
+`ReadTask`中有两个字段
+
+* private final ManagedSeriesReader reader;
+* private BlockingQueue blockingQueue;
+
+`ManagedSeriesReader`接口继承了`IBatchReader`接口,主要用来读取单个时间序列的数据,并且新增了以下四个方法
+
+```
+boolean isManagedByQueryManager();
+
+void setManagedByQueryManager(boolean managedByQueryManager);
+
+boolean hasRemaining();
+
+void setHasRemaining(boolean hasRemaining);
+```
+
+前两个方法用以表征该时间序列对应的生产者任务有没有被查询管理器所管理,即生产者任务有没有因为阻塞队列满了,而自行退出(后文会解释为什么不阻塞等待,而是直接退出);后两个方法用以表征该时间序列对应的reader里还有没有数据。
+
+`blockingQueue`就是该生产者任务的阻塞队列,实际上该阻塞队列只会在消费者取数据时单边阻塞,生产者放数据时,如果发现队列满了,便会直接退出,不会阻塞。
+
+下面看一下`ReadTask`的`run()`方法,执行流程的解释以注释的形式展现在代码中
+
+ run()
+
+```
+public void run() {
+  try {
+// 这里加锁的原因是为了保证对于blockingQueue满不满的判断是正确同步的
+synchronized (reader) {
+  // 
由于每次提交生产者任务时(不论是生产者自己递归的提交自己,还是消费者发现生产者任务自行退出而提交的),都会检查队列是不是满的,如果队列满了,是不会提交生产者任务的
+  // 所以生产者任务一旦被提交,blockingQueue里一定是有空余位置的,我们不需要检查队列是否满
+  // 如果时间序列对应的reader还有数据,进入循环体
+  while (reader.hasNextBatch()) {
+BatchData batchData = reader.nextBatch();
+// 由于拿到的BatchData有可能为空,所以需要一直迭代到第一个不为空的BatchData
+if (batchData.isEmpty()) {
+  continue;
+}
+// 将不为空的batchData放进阻塞队列中,此时的阻塞队列一定是不满的,所以不会阻塞
+blockingQueue.put(batchData);
+// 如果阻塞队列仍然没有满,生产者任务再次向线程池里递归地提交自己,进行下一个batchData的获取
+if (blockingQueue.remainingCapacity() > 0) {
+  pool.submit(this);
+}
+// 如果阻塞队列满了,生产者任务退出,并将对应reader的managedByQueryManager置为false
+else {
+  reader.setManagedByQueryManager(false);
+}
+return;
+  }
+  // 代码执行到这边,代表之前的while循环条件不满足,即该时间序列对应的reader里没有数据了
+  // 我们往阻塞队列里放入一个SignalBatchData,用以告知消费者,这个时间序列已经没有数据了,不需要再从该时间序列对应的队列里取数据了
+  blockingQueue.put(SignalBatchData.getInstance());
+  // 将reader的hasRemaining字段置为false
+  // 通知消费者不需要再为这个时间序列提交生产者任务
+  reader.setHasRemaining(false);
+  // 将reader的managedByQueryManager字段置为false
+  reader.setManagedByQueryManager(false);
+}
+  } catch (InterruptedException e) {
+LOGGER.error("Interrupted while putting into the blocking queue: ", e);
+Thread.currentThread().interrupt();
+  } catch (IOException e) {
+LOGGER.error("Something gets wrong while reading from the series reader: 
", e);
+  } catch (Exception e) {
+LOGGER.error("Something gets wrong: ", e);
+  }
+}
+```
+
+接下来介绍消费者的代码,消费者的主要逻辑是从每个时间序列的队列里拿出值,做时间戳对齐,然后拼凑结果集。时间戳的对齐主要通过一个时间戳的最小堆来实现,如果该时间序列的时间戳等于堆顶的时间戳,则取出该值,反之,将该时间戳下该时间序列的值置为`null`。
+
+先介绍消费者任务的一些重要字段
+
+* TreeSet timeHeap
+
+  时间戳的最小堆,用以实现时间戳对齐操作
+
+* BlockingQueue[] blockingQueueArray;
+
+  阻塞队列的数组,用以存储每个时间序列对应的阻塞队列
+
+* boolean[] noMoreDataInQueueArray
+
+  用以表征某个时间序列的阻塞队列里还有没有值,如果为false,则消费者不会再去调用`take()`方法,以防消费者线程被阻塞。
+  
+* BatchData[] cachedBatchDataArray
+
+  缓存从阻塞队列里取出的一个BatchData,因为阻塞队列里`take()`出的`BatchData`并不能一次性消费完,所以需要做缓存
+  
+在消费者`RawQueryDataSetWithoutValueFilter`的构造函数里首先调用了`init()`方法
+
+ int()
+
+```
+private void init() throws InterruptedException {
+   timeHeap = new TreeSet<>();
+   // 为每个时间序列构建生产者任务
+   for (int i = 0; i < seriesReaderList.size(); i++) {
+ ManagedSeriesReader reader = seriesReaderList.get(i);
+ reader.setHasRemaining(true);
+ reader.setManagedByQueryManager(true);
+ pool.submit(new ReadTask(reader, blockingQueueArray[i]));
+   }
+   // 初始化最小堆,填充每个时间序列对应的缓存
+   for (int i = 0; i < seriesReaderList.size(); i++) {
+ // 调用fillCache(int)方法填充缓存
+ fillCache(i);
+ // 尝试将每个时间序列的当前最小时间戳放进堆中
+ if (cachedBatchDataArray[i] != null && 
cachedBatchDataArray[i].hasCurrent()) {
+   long time = cachedBatchDataArray[i].currentTime();
+   timeHeap.add(time);
+ }
+   }
+}
+```
+
+  fillCache(int)
+