lmhmhl commented on issue #8883:
URL: https://github.com/apache/shardingsphere/issues/8883#issuecomment-758753986
Hi @tristaZero,
Thanks for your sincere advice, I tried again followed by your
instructions. Firstly, I prepare a `ShardingSphereDataSource` with
CALCITE_DB_NAMES which is a single database instance, then configure the yaml
file named `config-calcite.yaml` and add tables rules as follow, this is a
single table without sharding rules. Next, I Inserts a piece of data into the
databaseļ¼then prepare a SQL["SELECT id, cipher_pwd, plain_pwd FROM t_encrypt
WHERE id = ?";] to retrieve the data inserted just now. After that, when I
execute the test, some unexpected error happen again. In `executeQuery()`, a
method of `ShardingSpherePreparedStatement`, `queryResults` is returned by
`executeQuery0()` which execute query by Calcite, and return value is not null
showing that Calcite do query successfully, the weird thing is that when
creating `ShardingSphereResultSet`, it needs to invoke
`statement.getResultSet()` and the return value is null, thus
`resultSets.get(0).getMetaData()` in `ShardingSphereResu
ltSet` method would cast NullPointerException.
The `queryResults` and `mergedResult ` are both not null in executeQuery(),
but `this::getResultSet` returns null, I don't know what went wrong about my
method, can u give me some hints, THX.
```
rules:
- !SHARDING
tables:
t_encrypt:
actualDataNodes: jdbc_0.t_encrypt
```
```
public ResultSet executeQuery() throws SQLException {
ResultSet result;
try {
clearPrevious();
executionContext = createExecutionContext();
List<QueryResult> queryResults = executeQuery0();
MergedResult mergedResult = mergeQuery(queryResults);
result = new
ShardingSphereResultSet(statements.stream().map(this::getResultSet).collect(Collectors.toList()),
mergedResult, this, executionContext);
} finally {
clearBatch();
}
currentResultSet = result;
return result;
}
```
```
public ShardingSphereResultSet(final List<ResultSet> resultSets, final
MergedResult mergeResultSet, final Statement statement, final ExecutionContext
executionContext) throws SQLException {
super(resultSets, statement, executionContext);
this.mergeResultSet = mergeResultSet;
columnLabelAndIndexMap =
createColumnLabelAndIndexMap(resultSets.get(0).getMetaData());
}
```
<img width="1342" alt="Screen Shot 2021-01-12 at 8 38 47 PM"
src="https://user-images.githubusercontent.com/24718258/104338435-77681380-5531-11eb-80bd-db3b558930c1.png">
<img width="886" alt="Screen Shot 2021-01-12 at 8 38 13 PM"
src="https://user-images.githubusercontent.com/24718258/104338469-8222a880-5531-11eb-8141-d6eacf22afd5.png">
<img width="1289" alt="Screen Shot 2021-01-12 at 8 37 28 PM"
src="https://user-images.githubusercontent.com/24718258/104338500-8cdd3d80-5531-11eb-8720-29850a70c1bb.png">
The ExecutionContext is as follows:
<img width="1264" alt="Screen Shot 2021-01-12 at 10 04 30 PM"
src="https://user-images.githubusercontent.com/24718258/104338816-dfb6f500-5531-11eb-8024-18998946067b.png">
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]