Skip to content
Merged
Changes from 1 commit
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 @@ -29,10 +29,7 @@
import jsinterop.annotations.JsType;
import jsinterop.base.Js;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* Represents a set of Tables each corresponding to some key. The keys are available locally, but a call must be made to
Expand Down Expand Up @@ -95,19 +92,25 @@ public Promise<JsPartitionedTable> refetch() {
WebBarrageUtils.readSchemaMessage(descriptor.getConstituentDefinitionSchema_asU8()));
ColumnDefinition[] columnDefinitions = tableDefinition.getColumns();
Column[] columns = new Column[0];
Column[] keyColumns = new Column[0];
for (int i = 0; i < columnDefinitions.length; i++) {
ColumnDefinition columnDefinition = columnDefinitions[i];
Column column = columnDefinition.makeJsColumn(columns.length, tableDefinition.getColumnsByName());
columns[columns.length] = column;
if (descriptor.getKeyColumnNamesList().indexOf(columnDefinition.getName()) != -1) {
keyColumnTypes.add(columnDefinition.getType());
keyColumns[keyColumns.length] = column;
}
Column[] keyColumns = new Column[0];
JsArray<String> keyColumnNames = descriptor.getKeyColumnNamesList();
for (int i = 0; i < keyColumnNames.length; i++) {
String name = keyColumnNames.getAt(i);
ColumnDefinition columnDefinition = tableDefinition.getColumnsByName().get(false).get(name);
int index = 0;
while (!columns[index].getName().equals(name)) {
index++;
}
keyColumnTypes.add(columnDefinition.getType());
keyColumns[keyColumns.length] = columns[index];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to loop twice, i think this would do the job too?

Suggested change
ColumnDefinition columnDefinition = tableDefinition.getColumnsByName().get(false).get(name);
int index = 0;
while (!columns[index].getName().equals(name)) {
index++;
}
keyColumnTypes.add(columnDefinition.getType());
keyColumns[keyColumns.length] = columns[index];
ColumnDefinition columnDefinition = tableDefinition.getColumnsByName().get(false).get(name);
keyColumnTypes.add(columnDefinition.getType());
keyColumns[keyColumns.length] = columns[columnDefinition.getIndex()];

}
this.columns = JsObject.freeze(columns);
this.keyColumns = JsObject.freeze(keyColumns);

return w.getExportedObjects()[0].fetch();
}).then(result -> {
keys = (JsTable) result;
Expand Down