-
Notifications
You must be signed in to change notification settings - Fork 615
fix: allow duplicate column names in query responses #2623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
|
|
||
| import com.clickhouse.data.ClickHouseColumn; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
|
|
@@ -30,15 +30,17 @@ public TableSchema(String tableName, String query, String databaseName, Collecti | |
| this.databaseName = databaseName; | ||
| this.query = query; | ||
| this.columns = ImmutableList.copyOf(columns); | ||
| ImmutableMap.Builder<String, Integer> colIndexMapBuilder = ImmutableMap.builder(); | ||
| Map<String, Integer> colIndexMapBuilder = new HashMap<>(); | ||
| for (int i = 0; i < this.columns.size(); i++) { | ||
| ClickHouseColumn column= this.columns.get(i); | ||
| if (column.hasDefault()) { | ||
| this.hasDefaults = true; | ||
| } | ||
| colIndexMapBuilder.put(this.columns.get(i).getColumnName(), i); | ||
| String columnName = column.getColumnName(); | ||
| // if a column is duplicated, the last one wins | ||
| colIndexMapBuilder.put(columnName, i); | ||
| } | ||
| this.colIndex = colIndexMapBuilder.build(); | ||
| this.colIndex = colIndexMapBuilder; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashMapis much slower thatImmutableMap- that we have measured in our benchmark tests.ImmutableMapallows to leave last value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it!