You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/09/02 09:51:59 UTC

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1656: Add raw data query Interface in Session

qiaojialin commented on a change in pull request #1656:
URL: https://github.com/apache/incubator-iotdb/pull/1656#discussion_r481785697



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/Planner.java
##########
@@ -64,6 +77,50 @@ public PhysicalPlan parseSQLToPhysicalPlan(String sqlStr, ZoneId zoneId)
     return physicalGenerator.transformToPhysicalPlan(operator);
   }
 
+  /**
+   * convert raw data query to physical plan directly
+   */
+  public PhysicalPlan rawDataQueryReqToPhysicalPlan(TSRawDataQueryReq rawDataQueryReq)
+      throws QueryProcessException, IllegalPathException {
+    List<String> paths = rawDataQueryReq.getPaths();
+    long startTime = rawDataQueryReq.getStartTime();
+    long endTime = rawDataQueryReq.getEndTime();
+
+    //construct query operator and set its global time filter
+    QueryOperator queryOp = new QueryOperator(SQLConstant.TOK_QUERY);
+    FromOperator fromOp = new FromOperator(SQLConstant.TOK_FROM);
+    SelectOperator selectOp = new SelectOperator(SQLConstant.TOK_SELECT);
+
+    //iterate the path list and add it to from operator
+    for (String p : paths) {
+      PartialPath path = new PartialPath(p);
+      fromOp.addPrefixTablePath(path);
+    }
+    selectOp.addSelectPath(new PartialPath(""));
+
+    queryOp.setSelectOperator(selectOp);
+    queryOp.setFromOperator(fromOp);
+
+    //set time filter operator
+    FilterOperator filterOp = new FilterOperator(SQLConstant.KW_AND);
+    PartialPath timePath = new PartialPath(TIME);
+    filterOp.setSinglePath(timePath);
+    Set<PartialPath> pathSet = new HashSet<>();
+    pathSet.add(timePath);
+    filterOp.setIsSingle(true);
+    filterOp.setPathSet(pathSet);
+
+    BasicFunctionOperator left = new BasicFunctionOperator(SQLConstant.GREATERTHANOREQUALTO, timePath, Long.toString(startTime));
+    BasicFunctionOperator right = new BasicFunctionOperator(SQLConstant.LESSTHAN, timePath, Long.toString(endTime));

Review comment:
       ```suggestion
       BasicFunctionOperator right = new BasicFunctionOperator(SQLConstant.LESSTHANOREQUALTO, timePath, Long.toString(endTime));
   ```

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/Planner.java
##########
@@ -64,6 +77,50 @@ public PhysicalPlan parseSQLToPhysicalPlan(String sqlStr, ZoneId zoneId)
     return physicalGenerator.transformToPhysicalPlan(operator);
   }
 
+  /**
+   * convert raw data query to physical plan directly
+   */
+  public PhysicalPlan rawDataQueryReqToPhysicalPlan(TSRawDataQueryReq rawDataQueryReq)
+      throws QueryProcessException, IllegalPathException {
+    List<String> paths = rawDataQueryReq.getPaths();
+    long startTime = rawDataQueryReq.getStartTime();
+    long endTime = rawDataQueryReq.getEndTime();
+
+    //construct query operator and set its global time filter
+    QueryOperator queryOp = new QueryOperator(SQLConstant.TOK_QUERY);
+    FromOperator fromOp = new FromOperator(SQLConstant.TOK_FROM);
+    SelectOperator selectOp = new SelectOperator(SQLConstant.TOK_SELECT);
+
+    //iterate the path list and add it to from operator
+    for (String p : paths) {
+      PartialPath path = new PartialPath(p);
+      fromOp.addPrefixTablePath(path);
+    }
+    selectOp.addSelectPath(new PartialPath(""));
+
+    queryOp.setSelectOperator(selectOp);
+    queryOp.setFromOperator(fromOp);
+
+    //set time filter operator
+    FilterOperator filterOp = new FilterOperator(SQLConstant.KW_AND);
+    PartialPath timePath = new PartialPath(TIME);
+    filterOp.setSinglePath(timePath);
+    Set<PartialPath> pathSet = new HashSet<>();
+    pathSet.add(timePath);
+    filterOp.setIsSingle(true);
+    filterOp.setPathSet(pathSet);
+
+    BasicFunctionOperator left = new BasicFunctionOperator(SQLConstant.GREATERTHANOREQUALTO, timePath, Long.toString(startTime));
+    BasicFunctionOperator right = new BasicFunctionOperator(SQLConstant.LESSTHAN, timePath, Long.toString(endTime));

Review comment:
       ```suggestion
       BasicFunctionOperator right = new BasicFunctionOperator(SQLConstant.LESSTHANOREQUALTO, timePath, Long.toString(endTime));
   ```

##########
File path: session/src/main/java/org/apache/iotdb/session/Session.java
##########
@@ -913,6 +914,38 @@ public SessionDataSet executeQueryStatement(String sql)
         execResp.isIgnoreTimeStamp());
   }
 
+  /**
+   * query eg. select * from paths where time >= startTime and time < endTime
+   * time interval include startTime and exclude endTime
+   * @param paths
+   * @param startTime included
+   * @param endTime excluded
+   * @return
+   * @throws StatementExecutionException
+   * @throws IoTDBConnectionException
+   */
+
+  public SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime)
+          throws StatementExecutionException, IoTDBConnectionException {
+
+    String statement = SessionUtils.rawDataQuery;

Review comment:
       In JDBC or executeQueryStatement in Session, we send a SQL to the server, the SQL is used in a web metric(SqlArgument), which is disabled by default. The SQL is not important.
   
   We could remove the statement field in the rpc. if we need it, we could reconstruct a sql in the server based on other parameters.

##########
File path: thrift/src/main/thrift/rpc.thrift
##########
@@ -238,6 +238,16 @@ struct TSDeleteDataReq {
     4: required i64 endTime
 }
 
+struct TSRawDataQueryReq {
+    1: required i64 sessionId
+    2: required list<string> paths
+    3: optional i32 fetchSize
+    4: required i64 startTime
+    5: required i64 endTime
+    6: required i64 statementId

Review comment:
       The statementId is generated by the server, not the client. So this field is not needed.
   
   You could refer to generateQueryId(boolean isDataQuery) in TSServiceImpl.
   

##########
File path: session/src/main/java/org/apache/iotdb/session/Session.java
##########
@@ -913,6 +914,38 @@ public SessionDataSet executeQueryStatement(String sql)
         execResp.isIgnoreTimeStamp());
   }
 
+  /**
+   * query eg. select * from paths where time >= startTime and time < endTime
+   * time interval include startTime and exclude endTime
+   * @param paths
+   * @param startTime included
+   * @param endTime excluded
+   * @return
+   * @throws StatementExecutionException
+   * @throws IoTDBConnectionException
+   */
+
+  public SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime)
+          throws StatementExecutionException, IoTDBConnectionException {
+
+    String statement = SessionUtils.rawDataQuery;

Review comment:
       In the old version, we send a sql to the server, the sql is used in a web metric(SqlArgument), this is disable by default, not important.
   
   We could remove the statement arg in rpc, it's a redundant information, even we need it, we could construct a sql in server based on other parameters.

##########
File path: session/src/main/java/org/apache/iotdb/session/SessionUtils.java
##########
@@ -28,6 +28,8 @@
 
 public class SessionUtils {
 
+  public static final String rawDataQuery = "raw data query";

Review comment:
       this could be removed




----------------------------------------------------------------
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:
users@infra.apache.org