Skip to content

Commit dd1ba51

Browse files
deal with duplicate short-UUIDs
1 parent 7af480a commit dd1ba51

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies {
4242
testImplementation 'junit:junit:4.13.2'
4343
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
4444
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
45+
implementation 'com.google.guava:guava:32.1.2-jre'
4546
implementation group: 'io.tiledb', name: 'tiledb-cloud-java', version: '0.2.0'
4647
}
4748

src/main/java/io/tiledb/TileDBCloudTablesResultSet.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.tiledb;
22

3+
import com.google.common.collect.BiMap;
4+
import com.google.common.collect.HashBiMap;
35
import io.tiledb.cloud.rest_api.model.ArrayBrowserData;
46
import io.tiledb.cloud.rest_api.model.ArrayInfo;
57
import io.tiledb.util.Util;
@@ -13,7 +15,7 @@
1315
import java.util.logging.Logger;
1416

1517
public class TileDBCloudTablesResultSet implements ResultSet {
16-
public static HashMap<String, String> uris = new HashMap<>();
18+
public static BiMap<String, String> shortUUIDToUri = HashBiMap.create();
1719
private List<ArrayInfo> arraysOwned = new ArrayList<ArrayInfo>();
1820
private List<ArrayInfo> arraysShared = new ArrayList<ArrayInfo>();
1921
private List<ArrayInfo> arraysPublic = new ArrayList<ArrayInfo>();
@@ -47,24 +49,41 @@ private void populateURIs() {
4749
for (ArrayInfo arrayInfo : arraysOwned) {
4850
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
4951
String value = arrayInfo.getTiledbUri();
50-
uris.put(key, value);
52+
putURI(key, value);
5153
}
5254

5355
// Iterate through arraysShared and add entries to the HashMap
5456
for (ArrayInfo arrayInfo : arraysShared) {
5557
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
5658
String value = arrayInfo.getTiledbUri();
57-
uris.put(key, value);
59+
putURI(key, value);
5860
}
5961

6062
// Iterate through arraysPublic and add entries to the HashMap
6163
for (ArrayInfo arrayInfo : arraysPublic) {
6264
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
6365
String value = arrayInfo.getTiledbUri();
64-
uris.put(key, value);
66+
putURI(key, value);
6567
}
6668
}
6769

70+
/**
71+
* Puts a short UUID and value to the hashmap. If the key exists it will append "-1" or "-2", etc.
72+
*
73+
* @param key
74+
* @param value
75+
*/
76+
private void putURI(String key, String value) {
77+
int counter = 1;
78+
while (shortUUIDToUri.containsKey(key)) {
79+
key = key + "-" + counter;
80+
counter++;
81+
}
82+
// we might have an array that is both public and shared. In such cases there is
83+
// no need to display the array twice
84+
if (!shortUUIDToUri.inverse().containsKey(value)) shortUUIDToUri.put(key, value);
85+
}
86+
6887
public TileDBCloudTablesResultSet() {
6988
this.numberOfArrays = 0;
7089
}
@@ -109,7 +128,7 @@ public String getString(int columnIndex) throws SQLException {
109128
+ "/"
110129
+ currentArray.getName()
111130
+ "]["
112-
+ Util.getUUIDStart(currentArray.getTiledbUri())
131+
+ shortUUIDToUri.inverse().get(currentArray.getTiledbUri())
113132
+ "]";
114133
}
115134

@@ -213,7 +232,7 @@ public String getString(String columnLabel) throws SQLException {
213232
+ "/"
214233
+ currentArray.getName()
215234
+ "]["
216-
+ Util.getUUIDStart(currentArray.getTiledbUri())
235+
+ shortUUIDToUri.inverse().get(currentArray.getTiledbUri())
217236
+ "]";
218237
case "REMARKS":
219238
return ownership + " TileDB URI: " + currentArray.getTiledbUri();

src/main/java/io/tiledb/util/Util.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public static String useTileDBUris(String query) {
4444
String key = matcher.group(3);
4545

4646
String replacement =
47-
TileDBCloudTablesResultSet.uris.getOrDefault(key, ""); // Get replacement from the map
47+
TileDBCloudTablesResultSet.shortUUIDToUri.getOrDefault(
48+
key, ""); // Get replacement from the map
4849
if (!replacement.equals(""))
4950
matcher.appendReplacement(
5051
result, replacement); // Replace the match with the corresponding value

0 commit comments

Comments
 (0)