You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "citrusreticulata (via GitHub)" <gi...@apache.org> on 2023/05/17 09:12:49 UTC

[GitHub] [iotdb] citrusreticulata opened a new pull request, #9874: Support using logical view in query aligned by time.

citrusreticulata opened a new pull request, #9874:
URL: https://github.com/apache/iotdb/pull/9874

   Support using logical view in query aligned by time. 
   
   The commits do NOT support using logical view in query aligned by device till now.
   


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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] citrusreticulata commented on a diff in pull request #9874: Support using logical view in query aligned by time.

Posted by "citrusreticulata (via GitHub)" <gi...@apache.org>.
citrusreticulata commented on code in PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#discussion_r1201731185


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/visitor/ReplaceLogicalViewVisitor.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.mpp.plan.expression.visitor;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
+import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.GetSourcePathsVisitor;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.TransformToExpressionVisitor;
+import org.apache.iotdb.db.mpp.plan.expression.Expression;
+import org.apache.iotdb.db.mpp.plan.expression.binary.BinaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
+import org.apache.iotdb.db.mpp.plan.expression.ternary.TernaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.unary.UnaryExpression;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * step 1. check whether this expression contains logical view, that means check TimeSeriesOperand
+ * which has the LogicalViewSchema.
+ *
+ * <p>step 2. replace that TimeSeriesOperand with expression recorded in LogicalViewSchema (view
+ * expression).
+ *
+ * <p>step 3. record paths that appeared in view expression. They should be fetched later.
+ */
+public class ReplaceLogicalViewVisitor extends ExpressionVisitor<Expression, List<PartialPath>> {
+
+  private TransformToExpressionVisitor transformToExpressionVisitor = null;
+
+  private GetSourcePathsVisitor getSourcePathsVisitor = null;
+
+  private boolean hadProcessedAggregationFunction = false;

Review Comment:
   fixed.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/visitor/ReplaceLogicalViewVisitor.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.mpp.plan.expression.visitor;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
+import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.GetSourcePathsVisitor;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.TransformToExpressionVisitor;
+import org.apache.iotdb.db.mpp.plan.expression.Expression;
+import org.apache.iotdb.db.mpp.plan.expression.binary.BinaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
+import org.apache.iotdb.db.mpp.plan.expression.ternary.TernaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.unary.UnaryExpression;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * step 1. check whether this expression contains logical view, that means check TimeSeriesOperand
+ * which has the LogicalViewSchema.
+ *
+ * <p>step 2. replace that TimeSeriesOperand with expression recorded in LogicalViewSchema (view
+ * expression).
+ *
+ * <p>step 3. record paths that appeared in view expression. They should be fetched later.
+ */
+public class ReplaceLogicalViewVisitor extends ExpressionVisitor<Expression, List<PartialPath>> {
+
+  private TransformToExpressionVisitor transformToExpressionVisitor = null;
+
+  private GetSourcePathsVisitor getSourcePathsVisitor = null;
+
+  private boolean hadProcessedAggregationFunction = false;
+
+  /** The paths that are new added, which should be re-fetched. */
+  private List<PartialPath> newAddedPathList = null;

Review Comment:
   fixed.



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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] citrusreticulata commented on a diff in pull request #9874: Support using logical view in query aligned by time.

Posted by "citrusreticulata (via GitHub)" <gi...@apache.org>.
citrusreticulata commented on code in PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#discussion_r1201731590


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java:
##########
@@ -666,4 +666,27 @@ public Map<String, List<SortItem>> getDeviceToSortItems() {
   public void setDeviceToSortItems(Map<String, List<SortItem>> deviceToSortItems) {
     this.deviceToSortItems = deviceToSortItems;
   }
+
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // Logical View Analysis
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  private boolean hasViewsInQuery = false;
+
+  public void setHasViewsInQuery(boolean hasViewsInQuery) {
+    this.hasViewsInQuery = hasViewsInQuery;
+  }
+
+  public boolean hasViewsInQuery() {
+    return this.hasViewsInQuery;
+  }
+
+  private List<Pair<Expression, String>> outputExpressions = null;

Review Comment:
   fixed.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -437,6 +443,69 @@ private void analyzeLastSource(
     analysis.setSourceExpressions(sourceExpressions);
   }
 
+  private ISchemaTree findAllViewsInTreeThenReFetchAndMerge(ISchemaTree originSchemaTree) {
+    PathPatternTree patternTree = new PathPatternTree();
+    GetSourcePathsVisitor getSourcePathsVisitor = new GetSourcePathsVisitor();
+    boolean needToReFetch = false;
+    try {
+      Pair<List<MeasurementPath>, Integer> tempPair =
+          originSchemaTree.searchMeasurementPaths(new PartialPath("root.**"));
+      for (MeasurementPath measurementPath : tempPair.left) {
+        if (measurementPath.getMeasurementSchema().isLogicalView()) {
+          LogicalViewSchema logicalViewSchema =
+              (LogicalViewSchema) measurementPath.getMeasurementSchema();
+          ViewExpression viewExpression = logicalViewSchema.getExpression();
+          List<PartialPath> pathsNeedToReFetch =
+              getSourcePathsVisitor.process(viewExpression, null);
+          for (PartialPath path : pathsNeedToReFetch) {
+            patternTree.appendFullPath(path);
+            needToReFetch = true;
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    if (needToReFetch) {
+      ISchemaTree viewSchemaTree = this.schemaFetcher.fetchSchema(patternTree, null);
+      originSchemaTree.mergeSchemaTree(viewSchemaTree);
+    }
+    return originSchemaTree;

Review Comment:
   fixed.



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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #9874: Support using logical view in query aligned by time.

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on code in PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#discussion_r1201411611


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java:
##########
@@ -666,4 +666,27 @@ public Map<String, List<SortItem>> getDeviceToSortItems() {
   public void setDeviceToSortItems(Map<String, List<SortItem>> deviceToSortItems) {
     this.deviceToSortItems = deviceToSortItems;
   }
+
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // Logical View Analysis
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  private boolean hasViewsInQuery = false;
+
+  public void setHasViewsInQuery(boolean hasViewsInQuery) {
+    this.hasViewsInQuery = hasViewsInQuery;
+  }
+
+  public boolean hasViewsInQuery() {
+    return this.hasViewsInQuery;
+  }
+
+  private List<Pair<Expression, String>> outputExpressions = null;

Review Comment:
   move the attribute to the upper place of this class to stay with other attributes.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -437,6 +443,69 @@ private void analyzeLastSource(
     analysis.setSourceExpressions(sourceExpressions);
   }
 
+  private ISchemaTree findAllViewsInTreeThenReFetchAndMerge(ISchemaTree originSchemaTree) {
+    PathPatternTree patternTree = new PathPatternTree();
+    GetSourcePathsVisitor getSourcePathsVisitor = new GetSourcePathsVisitor();
+    boolean needToReFetch = false;
+    try {
+      Pair<List<MeasurementPath>, Integer> tempPair =
+          originSchemaTree.searchMeasurementPaths(new PartialPath("root.**"));
+      for (MeasurementPath measurementPath : tempPair.left) {
+        if (measurementPath.getMeasurementSchema().isLogicalView()) {
+          LogicalViewSchema logicalViewSchema =
+              (LogicalViewSchema) measurementPath.getMeasurementSchema();
+          ViewExpression viewExpression = logicalViewSchema.getExpression();
+          List<PartialPath> pathsNeedToReFetch =
+              getSourcePathsVisitor.process(viewExpression, null);
+          for (PartialPath path : pathsNeedToReFetch) {
+            patternTree.appendFullPath(path);
+            needToReFetch = true;
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    if (needToReFetch) {
+      ISchemaTree viewSchemaTree = this.schemaFetcher.fetchSchema(patternTree, null);
+      originSchemaTree.mergeSchemaTree(viewSchemaTree);
+    }
+    return originSchemaTree;

Review Comment:
   It is time-consuming to construct measurementPath. We can implement this check via a new method SchemaTree.hasLogicalView which can be get from the schema tree construction process.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -3033,30 +3157,84 @@ public Analysis visitCreateLogicalView(
     // TODO: CRTODO: add more analyzing
     context.setQueryType(QueryType.WRITE);
 
+    boolean hasViewInSource = false;
+    boolean sourceInSelectNotExist = false;
+    if (createLogicalViewStatement.getQueryStatement() != null) {
+      Analysis queryAnalysis =
+          this.visitQuery(createLogicalViewStatement.getQueryStatement(), context);
+      // get all expression from resultColumns
+      List<Pair<Expression, String>> outputExpressions = queryAnalysis.getOutputExpressions();
+      if (queryAnalysis.isFailed()) {
+        analysis.setFinishQueryAfterAnalyze(true);
+        analysis.setFailMessage(queryAnalysis.getFailMessage());
+        return analysis;
+      }
+      if (outputExpressions == null) {
+        analysis.setFinishQueryAfterAnalyze(true);
+        analysis.setFailMessage(
+            "The result columns in select is empty. "
+                + "Please check the query you used to create view");
+        return analysis;
+      }
+      List<Expression> expressionList = new ArrayList<>();
+      for (Pair<Expression, String> thisPair : outputExpressions) {
+        expressionList.add(thisPair.left);
+      }
+      createLogicalViewStatement.setSourceExpressions(expressionList);
+      hasViewInSource = queryAnalysis.hasViewsInQuery();
+    }
+    analysis.setStatement(createLogicalViewStatement);
+    // make sure the number of targets and source are matched
+
     // check target paths; check source expressions.
     Pair<Boolean, Exception> checkResult = createLogicalViewStatement.checkAll();
     if (checkResult.left == false) {
       throw new RuntimeException(checkResult.right);
     }
+    if (createLogicalViewStatement.getSourceExpressionList().size()
+        != createLogicalViewStatement.getTargetPathList().size()) {
+      analysis.setFinishQueryAfterAnalyze(true);
+      analysis.setFailMessage("The number of target and source paths are miss matched!");
+      return analysis;
+    }
 
-    Analysis queryAnalysis = null;
-    if (createLogicalViewStatement.getQueryStatement() != null) {
-      // analysis query statement
-      //      AnalyzeVisitor queryVisitor = new AnalyzeVisitor(this.partitionFetcher,
-      // this.schemaFetcher);
-      //      queryAnalysis =
-      // queryVisitor.visitQuery(createLogicalViewStatement.getQueryStatement(), null);
-      this.visitQuery(createLogicalViewStatement.getQueryStatement(), null);
-      // get all expression from resultColumns
-      List<ResultColumn> resultColumns =
-          createLogicalViewStatement.getQueryStatement().getSelectComponent().getResultColumns();
-      List<Expression> expressionList = new ArrayList<>();
-      for (ResultColumn resultCol : resultColumns) {
-        expressionList.add(resultCol.getExpression());
+    // make sure there is no view in source
+    List<Expression> sourceExpressionList = createLogicalViewStatement.getSourceExpressionList();
+    List<PartialPath> pathsNeedCheck = new ArrayList<>();
+    for (Expression expression : sourceExpressionList) {
+      if (expression instanceof TimeSeriesOperand) {
+        pathsNeedCheck.add(((TimeSeriesOperand) expression).getPath());
       }
-      createLogicalViewStatement.setSourceExpressions(expressionList);
     }
-    analysis.setStatement(createLogicalViewStatement);
+    Pair<ISchemaTree, Integer> schemaOfNeedToCheck =
+        fetchSchemaOfPathsAndCount(pathsNeedCheck, context);
+    if (schemaOfNeedToCheck.right != pathsNeedCheck.size()) {

Review Comment:
   This check seems not that efficient. Need improvement.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -476,10 +551,11 @@ private Map<Integer, List<Pair<Expression, String>>> analyzeSelect(
           } else {
             Expression expressionWithoutAlias =
                 ExpressionAnalyzer.removeAliasFromExpression(expression);
-            String alias =
-                !Objects.equals(expressionWithoutAlias, expression)
-                    ? expression.getExpressionString()
-                    : null;
+            //            String alias =
+            //                !Objects.equals(expressionWithoutAlias, expression)
+            //                    ? expression.getStringWithLogicalView()
+            //                    : null;
+            String alias = expression.getStringWithLogicalView();

Review Comment:
   remove the comments



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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #9874: Support using logical view in query aligned by time.

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on code in PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#discussion_r1198492007


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/visitor/ReplaceLogicalViewVisitor.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.mpp.plan.expression.visitor;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
+import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.GetSourcePathsVisitor;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.TransformToExpressionVisitor;
+import org.apache.iotdb.db.mpp.plan.expression.Expression;
+import org.apache.iotdb.db.mpp.plan.expression.binary.BinaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
+import org.apache.iotdb.db.mpp.plan.expression.ternary.TernaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.unary.UnaryExpression;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * step 1. check whether this expression contains logical view, that means check TimeSeriesOperand
+ * which has the LogicalViewSchema.
+ *
+ * <p>step 2. replace that TimeSeriesOperand with expression recorded in LogicalViewSchema (view
+ * expression).
+ *
+ * <p>step 3. record paths that appeared in view expression. They should be fetched later.
+ */
+public class ReplaceLogicalViewVisitor extends ExpressionVisitor<Expression, List<PartialPath>> {
+
+  private TransformToExpressionVisitor transformToExpressionVisitor = null;
+
+  private GetSourcePathsVisitor getSourcePathsVisitor = null;
+
+  private boolean hadProcessedAggregationFunction = false;

Review Comment:
   rename to ```hasProcessedAggregationFunction``



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/visitor/ReplaceLogicalViewVisitor.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.mpp.plan.expression.visitor;
+
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
+import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.GetSourcePathsVisitor;
+import org.apache.iotdb.db.metadata.view.viewExpression.visitor.TransformToExpressionVisitor;
+import org.apache.iotdb.db.mpp.plan.expression.Expression;
+import org.apache.iotdb.db.mpp.plan.expression.binary.BinaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
+import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
+import org.apache.iotdb.db.mpp.plan.expression.ternary.TernaryExpression;
+import org.apache.iotdb.db.mpp.plan.expression.unary.UnaryExpression;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * step 1. check whether this expression contains logical view, that means check TimeSeriesOperand
+ * which has the LogicalViewSchema.
+ *
+ * <p>step 2. replace that TimeSeriesOperand with expression recorded in LogicalViewSchema (view
+ * expression).
+ *
+ * <p>step 3. record paths that appeared in view expression. They should be fetched later.
+ */
+public class ReplaceLogicalViewVisitor extends ExpressionVisitor<Expression, List<PartialPath>> {
+
+  private TransformToExpressionVisitor transformToExpressionVisitor = null;
+
+  private GetSourcePathsVisitor getSourcePathsVisitor = null;
+
+  private boolean hadProcessedAggregationFunction = false;
+
+  /** The paths that are new added, which should be re-fetched. */
+  private List<PartialPath> newAddedPathList = null;

Review Comment:
   rename to ```sourceTimeSeriesPathOfLogicalViewList``



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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk commented on pull request #9874: Support using logical view in query aligned by time.

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk commented on PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#issuecomment-1553927888

   Please add some 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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] citrusreticulata commented on a diff in pull request #9874: Support using logical view in query aligned by time.

Posted by "citrusreticulata (via GitHub)" <gi...@apache.org>.
citrusreticulata commented on code in PR #9874:
URL: https://github.com/apache/iotdb/pull/9874#discussion_r1201732802


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -437,6 +443,69 @@ private void analyzeLastSource(
     analysis.setSourceExpressions(sourceExpressions);
   }
 
+  private ISchemaTree findAllViewsInTreeThenReFetchAndMerge(ISchemaTree originSchemaTree) {
+    PathPatternTree patternTree = new PathPatternTree();
+    GetSourcePathsVisitor getSourcePathsVisitor = new GetSourcePathsVisitor();
+    boolean needToReFetch = false;
+    try {
+      Pair<List<MeasurementPath>, Integer> tempPair =
+          originSchemaTree.searchMeasurementPaths(new PartialPath("root.**"));
+      for (MeasurementPath measurementPath : tempPair.left) {
+        if (measurementPath.getMeasurementSchema().isLogicalView()) {
+          LogicalViewSchema logicalViewSchema =
+              (LogicalViewSchema) measurementPath.getMeasurementSchema();
+          ViewExpression viewExpression = logicalViewSchema.getExpression();
+          List<PartialPath> pathsNeedToReFetch =
+              getSourcePathsVisitor.process(viewExpression, null);
+          for (PartialPath path : pathsNeedToReFetch) {
+            patternTree.appendFullPath(path);
+            needToReFetch = true;
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    if (needToReFetch) {
+      ISchemaTree viewSchemaTree = this.schemaFetcher.fetchSchema(patternTree, null);
+      originSchemaTree.mergeSchemaTree(viewSchemaTree);
+    }
+    return originSchemaTree;

Review Comment:
   Added a judgment, skip this step if it does not contain a view



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java:
##########
@@ -476,10 +551,11 @@ private Map<Integer, List<Pair<Expression, String>>> analyzeSelect(
           } else {
             Expression expressionWithoutAlias =
                 ExpressionAnalyzer.removeAliasFromExpression(expression);
-            String alias =
-                !Objects.equals(expressionWithoutAlias, expression)
-                    ? expression.getExpressionString()
-                    : null;
+            //            String alias =
+            //                !Objects.equals(expressionWithoutAlias, expression)
+            //                    ? expression.getStringWithLogicalView()
+            //                    : null;
+            String alias = expression.getStringWithLogicalView();

Review Comment:
   fixed



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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MarcosZyk merged pull request #9874: Support using logical view in query aligned by time.

Posted by "MarcosZyk (via GitHub)" <gi...@apache.org>.
MarcosZyk merged PR #9874:
URL: https://github.com/apache/iotdb/pull/9874


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

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org