Repository: apache/shardingsphere
Issue: Encrypt replace the table name with the column name.

## Bug Report

### Which version of ShardingSphere did you use?

4.0.0-RC2-SNAPSHOT

### Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC 

### Expected behavior

encrypt successfully.

### Actual behavior

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'status.status' in 'field list'

### Reason analyze (If you can)

Logic SQL: `select orderentit0_.order_id as order_id1_1_, orderentit0_.status as status2_1_, orderentit0_.user_id as user_id3_1_ from t_order orderentit0_`

actual SQL: `select orderentit0_.order_id as order_id1_1_, status.status as status2_1_, orderentit0_.user_id as user_id3_1_ from t_order orderentit0_`

Replace the table name with column name when rewrite.

### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

clone example code
use `local-zookeeper-encrypt` as spring.profiles.active
run `/Users/yangyi/Documents/java/sharding-sphere-example-sion/sharding-jdbc-example/orchestration-example/orchestration-spring-boot-example/src/main/java/org/apache/shardingsphere/example/orchestration/spring/boot/SpringBootExample`

### Example codes for reproduce this issue (such as a github link).

https://github.com/apache/incubator-shardingsphere-example


Changed files:
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/SelectEncryptItemTokenGenerator.java
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/core/extractor/impl/common/column/ColumnExtractor.java
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectEncryptItemToken.java

diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/core/extractor/impl/common/column/ColumnExtractor.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/core/extractor/impl/common/column/ColumnExtractor.java
index 55fe9bcbd98..3b660ff2da8 100644
--- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/core/extractor/impl/common/column/ColumnExtractor.java
+++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/core/extractor/impl/common/column/ColumnExtractor.java
@@ -43,7 +43,7 @@ public final class ColumnExtractor implements OptionalSQLSegmentExtractor {
     
     private ColumnSegment getColumnSegment(final ParserRuleContext columnNode) {
         ParserRuleContext nameNode = ExtractorUtils.getFirstChildNode(columnNode, RuleName.NAME);
-        ColumnSegment result = new ColumnSegment(columnNode.getStart().getStartIndex(), columnNode.getStart().getStopIndex(), nameNode.getText());
+        ColumnSegment result = new ColumnSegment(columnNode.getStart().getStartIndex(), columnNode.getStop().getStopIndex(), nameNode.getText());
         Optional<ParserRuleContext> ownerNode = ExtractorUtils.findFirstChildNodeNoneRecursive(columnNode, RuleName.OWNER);
         if (ownerNode.isPresent()) {
             result.setOwner(new TableSegment(ownerNode.get().getStart().getStartIndex(), ownerNode.get().getStop().getStopIndex(), ownerNode.get().getText()));
diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/SelectEncryptItemTokenGenerator.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/SelectEncryptItemTokenGenerator.java
index 2b6b87e3e45..78b86870e6a 100644
--- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/SelectEncryptItemTokenGenerator.java
+++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/SelectEncryptItemTokenGenerator.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement;
 import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ColumnSelectItemSegment;
 import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment;
 import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemsSegment;
+import org.apache.shardingsphere.core.parse.sql.segment.generic.TableSegment;
 import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
 import org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder;
 import org.apache.shardingsphere.core.rewrite.token.pojo.SelectEncryptItemToken;
@@ -79,12 +80,21 @@ public final class SelectEncryptItemTokenGenerator implements CollectionSQLToken
         return each instanceof ColumnSelectItemSegment && logicColumns.contains(((ColumnSelectItemSegment) each).getName());
     }
     
-    private SelectEncryptItemToken createSelectCipherItemToken(final SelectItemSegment each, final String tableName, final EncryptRule encryptRule, final boolean isQueryWithCipherColumn) {
-        String columnName = ((ColumnSelectItemSegment) each).getName();
+    private SelectEncryptItemToken createSelectCipherItemToken(final SelectItemSegment selectItemSegment, 
+                                                               final String tableName, final EncryptRule encryptRule, final boolean isQueryWithCipherColumn) {
+        String columnName = ((ColumnSelectItemSegment) selectItemSegment).getName();
         Optional<String> plainColumn = encryptRule.getPlainColumn(tableName, columnName);
         if (!isQueryWithCipherColumn && plainColumn.isPresent()) {
-            return new SelectEncryptItemToken(each.getStartIndex(), each.getStopIndex(), plainColumn.get());
+            return createSelectEncryptItemToken(selectItemSegment, plainColumn.get());
         }
-        return new SelectEncryptItemToken(each.getStartIndex(), each.getStopIndex(), encryptRule.getCipherColumn(tableName, columnName));
+        return createSelectEncryptItemToken(selectItemSegment, encryptRule.getCipherColumn(tableName, columnName));
+    }
+    
+    private SelectEncryptItemToken createSelectEncryptItemToken(final SelectItemSegment selectItemSegment, final String columnName) {
+        Optional<TableSegment> owner = ((ColumnSelectItemSegment) selectItemSegment).getOwner();
+        if (owner.isPresent()) {
+            return new SelectEncryptItemToken(selectItemSegment.getStartIndex(), selectItemSegment.getStopIndex(), columnName, owner.get().getTableName());
+        }
+        return new SelectEncryptItemToken(selectItemSegment.getStartIndex(), selectItemSegment.getStopIndex(), columnName);
     }
 }
diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectEncryptItemToken.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectEncryptItemToken.java
index 89117ebc6fd..fdeecddc1ca 100644
--- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectEncryptItemToken.java
+++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectEncryptItemToken.java
@@ -29,16 +29,23 @@ public final class SelectEncryptItemToken extends SQLToken implements Substituta
     
     private final int stopIndex;
     
-    private final String selectItemName;
+    private final String columnName;
     
-    public SelectEncryptItemToken(final int startIndex, final int stopIndex, final String selectItemName) {
+    private final String owner;
+    
+    public SelectEncryptItemToken(final int startIndex, final int stopIndex, final String columnName, final String owner) {
         super(startIndex);
         this.stopIndex = stopIndex;
-        this.selectItemName = selectItemName;
+        this.columnName = columnName;
+        this.owner = owner;
+    }
+    
+    public SelectEncryptItemToken(final int startIndex, final int stopIndex, final String columnName) {
+        this(startIndex, stopIndex, columnName, null);
     }
     
     @Override
     public String toString() {
-        return selectItemName;
+        return null == owner ? columnName : String.format("%s.%s", owner, columnName);
     }
 }