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

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


The following commit(s) were added to refs/heads/master by this push:
     new 496da57  Fix AggregationProjection return expression without cleaning 
(#11204)
496da57 is described below

commit 496da572a265d9516b2df4d002c58398eca4cf01
Author: Kyujin Nam <[email protected]>
AuthorDate: Tue Jul 20 08:30:14 2021 +0900

    Fix AggregationProjection return expression without cleaning (#11204)
---
 .../select/projection/ProjectionsContext.java      |  5 +-
 .../projection/impl/AggregationProjection.java     |  3 +-
 .../projection/impl/AggregationProjectionTest.java | 61 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
index ff2cf84..86c8faa 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Agg
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -68,7 +69,7 @@ public final class ProjectionsContext {
      */
     public Optional<String> findAlias(final String projectionName) {
         for (Projection each : projections) {
-            if (projectionName.equalsIgnoreCase(each.getExpression())) {
+            if 
(projectionName.equalsIgnoreCase(SQLUtil.getExactlyValue(each.getExpression())))
 {
                 return each.getAlias();
             }
         }
@@ -84,7 +85,7 @@ public final class ProjectionsContext {
     public Optional<Integer> findProjectionIndex(final String projectionName) {
         int result = 1;
         for (Projection each : projections) {
-            if (projectionName.equalsIgnoreCase(each.getExpression())) {
+            if 
(projectionName.equalsIgnoreCase(SQLUtil.getExactlyValue(each.getExpression())))
 {
                 return Optional.of(result);
             }
             result++;
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
index cf0d086..7d900ea 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjection.java
@@ -24,7 +24,6 @@ import lombok.Setter;
 import lombok.ToString;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -52,7 +51,7 @@ public class AggregationProjection implements Projection {
     
     @Override
     public final String getExpression() {
-        return SQLUtil.getExactlyValue(type.name() + innerExpression);
+        return type.name() + innerExpression;
     }
     
     @Override
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
new file mode 100644
index 0000000..01d25b1
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/impl/AggregationProjectionTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.shardingsphere.infra.binder.segment.select.projection.impl;
+
+import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
+import org.junit.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class AggregationProjectionTest {
+    private final AggregationType aggregationType = AggregationType.COUNT;
+
+    private final String innerExpression = "( A.\"DIRECTION\" )";
+
+    private final String alias = "AVG_DERIVED_COUNT_0";
+
+    private final AggregationProjection aggregationProjection1 = new 
AggregationProjection(aggregationType, innerExpression, alias);
+
+    private final AggregationProjection aggregationProjection2 = new 
AggregationProjection(aggregationType, innerExpression, null);
+
+    @Test
+    public void assertGetExpression() {
+        assertThat(aggregationProjection1.getExpression(), is(aggregationType 
+ innerExpression));
+    }
+
+    @Test
+    public void assertGetAlias() {
+        Optional<String> actual = aggregationProjection1.getAlias();
+        assertTrue(actual.isPresent());
+        assertThat(actual.get(), is(alias));
+    }
+
+    @Test
+    public void assertGetColumnLabel() {
+        assertThat(aggregationProjection1.getColumnLabel(), is(alias));
+    }
+
+    @Test
+    public void assertGetColumnLabelWithoutAlias() {
+        assertThat(aggregationProjection2.getColumnLabel(), is(aggregationType 
+ innerExpression));
+    }
+}

Reply via email to