From 4fdfe2be16d47f70af3bba38d0a8a3857032033c Mon Sep 17 00:00:00 2001 From: jamie Date: Mon, 12 Apr 2021 20:40:57 +0800 Subject: [PATCH] improve cast expr --- .../java/io/mycat/calcite/SqlImplementor.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hbt/src/main/java/io/mycat/calcite/SqlImplementor.java b/hbt/src/main/java/io/mycat/calcite/SqlImplementor.java index f1c64234f..0512130b6 100644 --- a/hbt/src/main/java/io/mycat/calcite/SqlImplementor.java +++ b/hbt/src/main/java/io/mycat/calcite/SqlImplementor.java @@ -829,11 +829,22 @@ public SqlNode toSql(RexProgram program, RexNode rex) { assert nodeList.size() == 1; return nodeList.get(0); } else { - if (call.getOperands().size() ==1 && call.getOperands().get(0) instanceof RexDynamicParam){ - return nodeList.get(0); - }else { - nodeList.add(dialect.getCastSpec(call.getType())); + if (call.getOperands().size() == 1) { + RexNode rexNode = call.getOperands().get(0); + if(rexNode.getType().getSqlTypeName().getFamily() == call.getType().getSqlTypeName().getFamily()){ + return nodeList.get(0); + } + if (rexNode instanceof RexDynamicParam) { + return nodeList.get(0); + } + if (rexNode instanceof RexInputRef) { + return nodeList.get(0); + } + if (rexNode instanceof RexLocalRef) { + return nodeList.get(0); + } } + nodeList.add(dialect.getCastSpec(call.getType())); } } if (op instanceof SqlBinaryOperator && nodeList.size() > 2) {