apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.97k stars 6.75k forks source link

Wrong resultSet when execute `desc table;` using EncryptRule #2784

Closed tristaZero closed 5 years ago

tristaZero commented 5 years ago

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

4.0.0.RC2

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-Proxy

Expected behavior

When execute desc encryptTable, it will show logic columns of encryptTable

Actual behavior

when execute desc encryptTable, it shows actual columns of encryptTable

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

The coding entrance:

JDBCDatabaseCommunicationEngine.java
 private BackendResponse merge(final SQLRouteResult routeResult) throws SQLException {
        if (response instanceof UpdateResponse) {
            if (!isAllBroadcastTables(routeResult.getOptimizedStatement())) {
                ((UpdateResponse) response).mergeUpdateCount();
            }
            return response;
        }
        mergedResult = MergeEngineFactory.newInstance(databaseType, 
                logicSchema.getShardingRule(), routeResult, logicSchema.getMetaData().getTable(), ((QueryResponse) response).getQueryResults()).merge();
        if (mergedResult instanceof ShowTablesMergedResult) {
            ((ShowTablesMergedResult) mergedResult).resetColumnLabel(logicSchema.getName());
        }
        handleColumnsForQueryHeader(routeResult);
        return response;
    }

You need to replace actual columns of BackendResponse with logic columns here.

Here are some ideas:

  1. Create DescribeTableMergedResult extends MemoryMergedResult to handle QueryResults of DESC encryptTable, but U need to pass ShardingRuel not EncryptRule to DALMergeEngine
  2. Modify BackendResponse in merge() of JDBCDatabaseCommunicationEngine
betterjava commented 5 years ago

@tristaZero actual columns more than logic columns,we should hide some actual columns,is my understanding correct?

tristaZero commented 5 years ago

@betterjava yes, we should hide actual columns, i.e, AssistedQueryColumn and cipherColumn, and show user the virtual column name, i.e, encryptColumn.