This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch ty/TableModelGrammar in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/TableModelGrammar by this push: new dd7ee662f4e fix 'select -s1' dd7ee662f4e is described below commit dd7ee662f4ef7f7d992c69b845111d8937e70ec1 Author: Weihao Li <60659567+wei-hao...@users.noreply.github.com> AuthorDate: Wed Jul 24 15:00:40 2024 +0800 fix 'select -s1' --- .../plan/relational/planner/ir/ExpressionRewriter.java | 9 +++++---- .../relational/planner/ir/ExpressionTreeRewriter.java | 18 ++++++++++++++++++ .../relational/sql/ast/ArithmeticUnaryExpression.java | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionRewriter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionRewriter.java index 3de51a1b89b..022d6527dab 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionRewriter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionRewriter.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.queryengine.plan.relational.planner.ir; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ArithmeticBinaryExpression; +import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ArithmeticUnaryExpression; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.BetweenPredicate; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Cast; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CoalesceExpression; @@ -64,10 +65,10 @@ public class ExpressionRewriter<C> { return rewriteExpression(node, context, treeRewriter); } - // public Expression rewriteArithmeticUnary(ArithmeticNegation node, C context, - // ExpressionTreeRewriter<C> treeRewriter) { - // return rewriteExpression(node, context, treeRewriter); - // } + public Expression rewriteArithmeticUnary( + ArithmeticUnaryExpression node, C context, ExpressionTreeRewriter<C> treeRewriter) { + return rewriteExpression(node, context, treeRewriter); + } public Expression rewriteArithmeticBinary( ArithmeticBinaryExpression node, C context, ExpressionTreeRewriter<C> treeRewriter) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionTreeRewriter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionTreeRewriter.java index 525804fd2bd..91c685d6d26 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionTreeRewriter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ir/ExpressionTreeRewriter.java @@ -19,6 +19,7 @@ package org.apache.iotdb.db.queryengine.plan.relational.planner.ir; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ArithmeticBinaryExpression; +import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.ArithmeticUnaryExpression; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.BetweenPredicate; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Cast; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CoalesceExpression; @@ -136,6 +137,23 @@ public final class ExpressionTreeRewriter<C> { // // return node; // } + @Override + protected Expression visitArithmeticUnary(ArithmeticUnaryExpression node, Context<C> context) { + if (!context.isDefaultRewrite()) { + Expression result = + rewriter.rewriteArithmeticUnary(node, context.get(), ExpressionTreeRewriter.this); + if (result != null) { + return result; + } + } + + Expression child = rewrite(node.getValue(), context.get()); + if (child != node.getValue()) { + return new ArithmeticUnaryExpression(node.getLocation().get(), node.getSign(), child); + } + + return node; + } @Override public Expression visitArithmeticBinary(ArithmeticBinaryExpression node, Context<C> context) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ArithmeticUnaryExpression.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ArithmeticUnaryExpression.java index 2879081f23f..0acd9a53b23 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ArithmeticUnaryExpression.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/ArithmeticUnaryExpression.java @@ -42,7 +42,7 @@ public class ArithmeticUnaryExpression extends Expression { private final Expression value; private final Sign sign; - private ArithmeticUnaryExpression(NodeLocation location, Sign sign, Expression value) { + public ArithmeticUnaryExpression(NodeLocation location, Sign sign, Expression value) { super(location); requireNonNull(value, "value is null"); requireNonNull(sign, "sign is null");