Fix ResultSet#findColumn - return actual column's index instead of 0
#2376
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Now
findColumnreturns actual column's index.Closes #2375.
Closes #1378.
Closes #2498.
The reason this method returns 0 is the following: this method obtains an instance of
ClickHouseColumnto return its index. However, its private fieldcolumnIndexalways equals 0 for any write/read path. This field is set in the constructor initially and never updated to reflect the actual column's index - https://github.com/gravity182/clickhouse-java/blob/a3f80b6476c6832a0f8e09c88b65f55e86b4e270/clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseColumn.java#L670.Interestingly, this method worked correctly in jdbc-v1. See the implementation - https://github.com/gravity182/clickhouse-java/blob/3ce1b09161e15bfd13695d7fb7bdd198b4672e00/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseResultSet.java#L219-L225. As you can see, it simply counted from 1 until the required column is found.
Having said that, we can proceed with this solution fixing only the
findColumnmethod or fix this problem on the deeper level, settingClickHouseColumn#columnIndexfield to a correct column's index. There probably might be other methods affected by this problem as well.Checklist
Delete items not relevant to your PR: