LeiRui commented on a change in pull request #433: [IOTDB-203]add "group by 
device" function for narrow table display
URL: https://github.com/apache/incubator-iotdb/pull/433#discussion_r334216535
 
 

 ##########
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
 ##########
 @@ -260,75 +269,122 @@ private PhysicalPlan transformQuery(QueryOperator 
queryOperator)
       queryPlan = new QueryPlan();
     }
 
-    List<Path> paths = queryOperator.getSelectedPaths();
-    queryPlan.setPaths(paths);
-    queryPlan.checkPaths(executor);
+    if (!queryOperator.isGroupByDevice()) {
+      List<Path> paths = queryOperator.getSelectedPaths();
+      queryPlan.setPaths(paths);
 
-    if (queryOperator.isGroupByDevice()) {
-      queryPlan.setGroupByDevice(true);
-      // group paths and aggregations by devices
-      List<String> aggregations = 
queryOperator.getSelectOperator().getAggregations();
-      TreeMap<String, List<Path>> pathsGroupByDevice = new TreeMap<>();
-      TreeMap<String, List<String>> aggregationsGroupByDevice = new 
TreeMap<>();
-      TreeMap<String, List<String>> sensorColumnsGroupByDevice = new 
TreeMap<>();
-      for (int i = 0; i < paths.size(); i++) {
-        Path path = paths.get(i);
-        String device = path.getDevice();
-        if (!pathsGroupByDevice.containsKey(device)) {
-          pathsGroupByDevice.put(device, new ArrayList<>());
-          aggregationsGroupByDevice.put(device, new ArrayList<>());
-          sensorColumnsGroupByDevice.put(device, new ArrayList<>());
-        }
-        pathsGroupByDevice.get(device).add(path);
-        if (aggregations != null && !aggregations.isEmpty()) {
-          aggregationsGroupByDevice.get(device).add(aggregations.get(i));
-          sensorColumnsGroupByDevice.get(device)
-              .add(aggregations.get(i) + "(" + paths.get(i).getMeasurement() + 
")");
-        } else {
-          
sensorColumnsGroupByDevice.get(device).add(paths.get(i).getMeasurement());
+    } else {
+      // below is the core realization of GROUP_BY_DEVICE sql
+      List<Path> prefixPaths = 
queryOperator.getFromOperator().getPrefixPaths();
+      List<Path> suffixPaths = 
queryOperator.getSelectOperator().getSuffixPaths();
+      List<String> originAggregations = 
queryOperator.getSelectOperator().getAggregations();
+
+      List<String> measurementColumnList = new ArrayList<>();
+      Map<String, Set<String>> measurementColumnsGroupByDevice = new 
LinkedHashMap<>();
+      Map<String, TSDataType> dataTypeConsistencyChecker = new HashMap<>();
+      Set<Path> allSelectPaths = new HashSet<>();
+
+      for (int i = 0; i < suffixPaths.size(); i++) { // per suffix
+        Path suffixPath = suffixPaths.get(i);
+        Set<String> deviceSetOfGivenSuffix = new HashSet<>();
+        Set<String> measurementSetOfGivenSuffix = new TreeSet<>();
+        for (Path prefixPath : prefixPaths) { // per prefix
+          if (!prefixPath.startWith(SQLConstant.ROOT)) {
+            throw new QueryProcessorException("illegal from clause : " + 
prefixPath.getFullPath());
+          }
 
 Review comment:
   removed two places

----------------------------------------------------------------
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

Reply via email to