Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap is much slower that ImmutableMap - that we have measured in our benchmark tests.
ImmutableMap allows to leave last value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it!

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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The colIndex map is no longer immutable after switching from ImmutableMap to HashMap, but it's still exposed as a public field. Consider making this field private or ensuring it remains immutable by wrapping it with Collections.unmodifiableMap() to prevent external modifications.

}

/**
Expand Down