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

caogaofei pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 0a46364664ea014a5dc09806c126a05dc1069a27
Author: Beyyes <[email protected]>
AuthorDate: Wed May 8 11:47:44 2024 +0800

    fix nameHint naming in SymbolAllocator; fix cast impl
---
 .../plan/relational/planner/SymbolAllocator.java   | 80 ++++------------------
 1 file changed, 14 insertions(+), 66 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/SymbolAllocator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/SymbolAllocator.java
index 306ce8d362a..afbdc6e15e3 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/SymbolAllocator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/SymbolAllocator.java
@@ -15,101 +15,49 @@ package 
org.apache.iotdb.db.queryengine.plan.relational.planner;
 
 import org.apache.iotdb.db.queryengine.plan.analyze.TypeProvider;
 import org.apache.iotdb.db.queryengine.plan.relational.analyzer.Field;
-import org.apache.iotdb.db.relational.sql.tree.Expression;
-import org.apache.iotdb.db.relational.sql.tree.FunctionCall;
-import org.apache.iotdb.db.relational.sql.tree.SymbolReference;
 
 import org.apache.tsfile.read.common.type.Type;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Locale.ENGLISH;
 import static java.util.Objects.requireNonNull;
 
 public class SymbolAllocator {
-  private final Map<Symbol, Type> symbols;
+  private final Map<Symbol, Type> symbolMap;
   private int nextId;
 
   public SymbolAllocator() {
-    symbols = new HashMap<>();
+    symbolMap = new HashMap<>();
   }
 
-  public SymbolAllocator(Map<Symbol, Type> initial) {
-    symbols = new HashMap<>(initial);
+  public Symbol newSymbol(String symbolHint, Type type) {
+    return newSymbol(symbolHint, type, null);
   }
 
-  public Symbol newSymbol(Symbol symbolHint) {
-    return newSymbol(symbolHint, null);
-  }
-
-  public Symbol newSymbol(Symbol symbolHint, String suffix) {
-    checkArgument(symbols.containsKey(symbolHint), "symbolHint not in symbols 
map");
-    return newSymbol(symbolHint.getName(), symbols.get(symbolHint), suffix);
-  }
-
-  public Symbol newSymbol(String nameHint, Type type) {
-    return newSymbol(nameHint, type, null);
-  }
-
-  public Symbol newSymbol(String nameHint, Type type, String suffix) {
-    requireNonNull(nameHint, "nameHint is null");
-    requireNonNull(type, "type is null");
-
-    // TODO: workaround for the fact that QualifiedName lowercases parts
-    nameHint = nameHint.toLowerCase(ENGLISH);
-
-    // don't strip the tail if the only _ is the first character
-    //    int index = nameHint.lastIndexOf("_");
-    //    if (index > 0) {
-    //      String tail = nameHint.substring(index + 1);
-    //
-    //      // only strip if tail is numeric or _ is the last character
-    //      if (Ints.tryParse(tail) != null || index == nameHint.length() - 1) 
{
-    //        nameHint = nameHint.substring(0, index);
-    //      }
-    //    }
-
-    String unique = nameHint;
+  public Symbol newSymbol(String symbolHint, Type symbolType, String suffix) {
+    requireNonNull(symbolHint, "symbolHint is null");
+    requireNonNull(symbolType, "type is null");
 
     if (suffix != null) {
-      unique = unique + "$" + suffix;
+      symbolHint = symbolHint + "$" + suffix;
     }
 
-    Symbol symbol = new Symbol(unique);
-    while (symbols.putIfAbsent(symbol, type) != null) {
-      symbol = new Symbol(unique + "_" + nextId());
+    Symbol symbol = new Symbol(symbolHint);
+    while (symbolMap.putIfAbsent(symbol, symbolType) != null) {
+      symbol = new Symbol(symbolHint + "_" + nextId());
     }
 
     return symbol;
   }
 
-  public Symbol newSymbol(Expression expression, Type type) {
-    return newSymbol(expression, type, null);
-  }
-
-  public Symbol newSymbol(Expression expression, Type type, String suffix) {
-    String nameHint = "expr";
-    if (expression instanceof FunctionCall) {
-      FunctionCall functionCall = (FunctionCall) expression;
-      // symbol allocation can happen during planning, before function calls 
are rewritten
-      nameHint = functionCall.getName().toString();
-    } else if (expression instanceof SymbolReference) {
-      SymbolReference symbolReference = (SymbolReference) expression;
-      nameHint = symbolReference.getName();
-    }
-
-    return newSymbol(nameHint, type, suffix);
-  }
-
   public Symbol newSymbol(Field field) {
-    String nameHint = field.getName().orElse("field");
-    return newSymbol(nameHint, field.getType());
+    String symbolHint = field.getName().orElse("field");
+    return newSymbol(symbolHint, field.getType());
   }
 
   public TypeProvider getTypes() {
-    return TypeProvider.viewOf(symbols);
+    return TypeProvider.viewOf(symbolMap);
   }
 
   private int nextId() {

Reply via email to