You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/05/04 11:37:40 UTC

[iotdb] branch master updated: Refactor abstract class Expression (#5793)

This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 23abc02191 Refactor abstract class Expression (#5793)
23abc02191 is described below

commit 23abc0219177de83b5b6e8df607570be37ada621
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed May 4 19:37:35 2022 +0800

    Refactor abstract class Expression (#5793)
    
    Make every method and every field clearer.
---
 .../iotdb/db/query/expression/Expression.java      | 80 ++++++++++++++++------
 1 file changed, 60 insertions(+), 20 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java b/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
index 2a56a4974f..2779a735e9 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/Expression.java
@@ -69,11 +69,9 @@ import java.util.Set;
 /** A skeleton class for expression */
 public abstract class Expression {
 
-  private String expressionStringCache;
-
-  protected Boolean isConstantOperandCache = null;
-
-  protected Integer inputColumnIndex = null;
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // Expression type inferring for execution plan generation
+  /////////////////////////////////////////////////////////////////////////////////////////////////
 
   public boolean isBuiltInAggregationFunctionExpression() {
     return false;
@@ -87,6 +85,10 @@ public abstract class Expression {
     return false;
   }
 
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // Operations for time series paths
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
   public abstract void concat(
       List<PartialPath> prefixPaths,
       List<Expression> resultExpressions,
@@ -107,9 +109,19 @@ public abstract class Expression {
 
   public abstract void collectPaths(Set<PartialPath> pathSet);
 
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // For UDF instances initialization
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
   public abstract void constructUdfExecutors(
       Map<String, UDTFExecutor> expressionName2Executor, ZoneId zoneId);
 
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // For expression evaluation DAG building
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
+  protected Integer inputColumnIndex = null;
+
   public abstract void bindInputLayerColumnIndexWithExpression(UDTFPlan udtfPlan);
 
   public abstract void updateStatisticsForMemoryAssigner(LayerMemoryAssigner memoryAssigner);
@@ -123,14 +135,21 @@ public abstract class Expression {
       LayerMemoryAssigner memoryAssigner)
       throws QueryProcessException, IOException;
 
-  /** Sub-classes should override this method indicating if the expression is a constant operand */
-  protected abstract boolean isConstantOperandInternal();
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // getExpressions: returning DIRECT children expressions
+  /////////////////////////////////////////////////////////////////////////////////////////////////
 
   /**
    * returns the DIRECT children expressions if it has any, otherwise an EMPTY list will be returned
    */
   public abstract List<Expression> getExpressions();
 
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // isConstantOperand
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
+  protected Boolean isConstantOperandCache = null;
+
   /** If this expression and all of its sub-expressions are {@link ConstantOperand}. */
   public final boolean isConstantOperand() {
     if (isConstantOperandCache == null) {
@@ -139,11 +158,20 @@ public abstract class Expression {
     return isConstantOperandCache;
   }
 
-  /**
-   * Sub-classes should override this method to provide valid string representation of this object.
-   * See {@link #getExpressionString()}
-   */
-  protected abstract String getExpressionStringInternal();
+  /** Sub-classes should override this method indicating if the expression is a constant operand */
+  protected abstract boolean isConstantOperandInternal();
+
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // toString
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private String expressionStringCache;
+
+  /** Sub-classes must not override this method. */
+  @Override
+  public final String toString() {
+    return getExpressionString();
+  }
 
   /**
    * Get the representation of the expression in string. The hash code of the returned value will be
@@ -158,6 +186,16 @@ public abstract class Expression {
     return expressionStringCache;
   }
 
+  /**
+   * Sub-classes should override this method to provide valid string representation of this object.
+   * See {@link #getExpressionString()}
+   */
+  protected abstract String getExpressionStringInternal();
+
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // hashCode & equals
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+
   /** Sub-classes must not override this method. */
   @Override
   public final int hashCode() {
@@ -178,11 +216,9 @@ public abstract class Expression {
     return getExpressionString().equals(((Expression) o).getExpressionString());
   }
 
-  /** Sub-classes must not override this method. */
-  @Override
-  public final String toString() {
-    return getExpressionString();
-  }
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // iterator: level-order traversal iterator
+  /////////////////////////////////////////////////////////////////////////////////////////////////
 
   /** returns an iterator to traverse all the successor expressions in a level-order */
   public final Iterator<Expression> iterator() {
@@ -218,7 +254,9 @@ public abstract class Expression {
     }
   }
 
-  public abstract ExpressionType getExpressionType();
+  /////////////////////////////////////////////////////////////////////////////////////////////////
+  // serialize & deserialize
+  /////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static void serialize(Expression expression, ByteBuffer byteBuffer) {
     ReadWriteIOUtils.write(
@@ -232,8 +270,6 @@ public abstract class Expression {
     }
   }
 
-  protected abstract void serialize(ByteBuffer byteBuffer);
-
   public static Expression deserialize(ByteBuffer byteBuffer) {
     short type = ReadWriteIOUtils.readShort(byteBuffer);
 
@@ -325,4 +361,8 @@ public abstract class Expression {
 
     return expression;
   }
+
+  public abstract ExpressionType getExpressionType();
+
+  protected abstract void serialize(ByteBuffer byteBuffer);
 }