coder616 commented on issue #20338:
URL: 
https://github.com/apache/shardingsphere/issues/20338#issuecomment-1222358174

   I know that ShardingSphere Proxy uses the logical database name, but in 
practice, the logical database name is usually composed of prefix or suffix 
with business significance and the actual database name. So when I use the 
ShardingSphere - JBDC to a database table through the agent as the decryption 
MySQLSchemaMetaDataLoader cannot correct to get the actual metadata, leading to 
a join operation of the query results cannot be normal.
   
   org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult#getValue:
   `public Object getValue(final int columnIndex, final Class<?> type) throws 
SQLException {
           Optional<EncryptContext> encryptContext = 
metaData.findEncryptContext(columnIndex);
           if (!encryptContext.isPresent() || 
!metaData.isQueryWithCipherColumn(encryptContext.get().getTableName(), 
encryptContext.get().getColumnName())) {
               return mergedResult.getValue(columnIndex, type);
           }
           Optional<EncryptAlgorithm> encryptAlgorithm = 
metaData.findEncryptor(encryptContext.get().getTableName(), 
encryptContext.get().getColumnName());
           if (!encryptAlgorithm.isPresent()) {
               return mergedResult.getValue(columnIndex, type);
           }
           Object cipherValue = mergedResult.getValue(columnIndex, 
Object.class);
           return null == cipherValue ? null : 
encryptAlgorithm.get().decrypt(cipherValue, encryptContext.get());
       }`
   
   `/**
        * Find encrypt context.
        * 
        * @param columnIndex column index
        * @return encrypt context
        */
       public Optional<EncryptContext> findEncryptContext(final int 
columnIndex) {
           Optional<ColumnProjection> columnProjection = 
findColumnProjection(columnIndex);
           if (!columnProjection.isPresent()) {
               return Optional.empty();
           }
           TablesContext tablesContext = 
selectStatementContext.getTablesContext();
           String schemaName = tablesContext.getSchemaName().orElseGet(() -> 
DatabaseTypeEngine.getDefaultSchemaName(selectStatementContext.getDatabaseType(),
 database.getName()));
           Map<String, String> expressionTableNames = 
tablesContext.findTableNamesByColumnProjection(
                   Collections.singletonList(columnProjection.get()), 
database.getSchema(schemaName));
           Optional<String> tableName = findTableName(columnProjection.get(), 
expressionTableNames);
           return tableName.map(optional -> 
EncryptContextBuilder.build(database.getName(), schemaName, optional, 
columnProjection.get().getName()));
       }`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to