Skip to content

Commit

Permalink
deal with duplicate short-UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Oct 5, 2023
1 parent 7af480a commit dd1ba51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
implementation 'com.google.guava:guava:32.1.2-jre'
implementation group: 'io.tiledb', name: 'tiledb-cloud-java', version: '0.2.0'
}

Expand Down
31 changes: 25 additions & 6 deletions src/main/java/io/tiledb/TileDBCloudTablesResultSet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tiledb;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import io.tiledb.cloud.rest_api.model.ArrayBrowserData;
import io.tiledb.cloud.rest_api.model.ArrayInfo;
import io.tiledb.util.Util;
Expand All @@ -13,7 +15,7 @@
import java.util.logging.Logger;

public class TileDBCloudTablesResultSet implements ResultSet {
public static HashMap<String, String> uris = new HashMap<>();
public static BiMap<String, String> shortUUIDToUri = HashBiMap.create();
private List<ArrayInfo> arraysOwned = new ArrayList<ArrayInfo>();
private List<ArrayInfo> arraysShared = new ArrayList<ArrayInfo>();
private List<ArrayInfo> arraysPublic = new ArrayList<ArrayInfo>();
Expand Down Expand Up @@ -47,24 +49,41 @@ private void populateURIs() {
for (ArrayInfo arrayInfo : arraysOwned) {
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
String value = arrayInfo.getTiledbUri();
uris.put(key, value);
putURI(key, value);
}

// Iterate through arraysShared and add entries to the HashMap
for (ArrayInfo arrayInfo : arraysShared) {
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
String value = arrayInfo.getTiledbUri();
uris.put(key, value);
putURI(key, value);
}

// Iterate through arraysPublic and add entries to the HashMap
for (ArrayInfo arrayInfo : arraysPublic) {
String key = Util.getUUIDStart(arrayInfo.getTiledbUri());
String value = arrayInfo.getTiledbUri();
uris.put(key, value);
putURI(key, value);
}
}

/**
* Puts a short UUID and value to the hashmap. If the key exists it will append "-1" or "-2", etc.
*
* @param key
* @param value
*/
private void putURI(String key, String value) {
int counter = 1;
while (shortUUIDToUri.containsKey(key)) {
key = key + "-" + counter;
counter++;
}
// we might have an array that is both public and shared. In such cases there is
// no need to display the array twice
if (!shortUUIDToUri.inverse().containsKey(value)) shortUUIDToUri.put(key, value);
}

public TileDBCloudTablesResultSet() {
this.numberOfArrays = 0;
}
Expand Down Expand Up @@ -109,7 +128,7 @@ public String getString(int columnIndex) throws SQLException {
+ "/"
+ currentArray.getName()
+ "]["
+ Util.getUUIDStart(currentArray.getTiledbUri())
+ shortUUIDToUri.inverse().get(currentArray.getTiledbUri())
+ "]";
}

Expand Down Expand Up @@ -213,7 +232,7 @@ public String getString(String columnLabel) throws SQLException {
+ "/"
+ currentArray.getName()
+ "]["
+ Util.getUUIDStart(currentArray.getTiledbUri())
+ shortUUIDToUri.inverse().get(currentArray.getTiledbUri())
+ "]";
case "REMARKS":
return ownership + " TileDB URI: " + currentArray.getTiledbUri();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/tiledb/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static String useTileDBUris(String query) {
String key = matcher.group(3);

String replacement =
TileDBCloudTablesResultSet.uris.getOrDefault(key, ""); // Get replacement from the map
TileDBCloudTablesResultSet.shortUUIDToUri.getOrDefault(
key, ""); // Get replacement from the map
if (!replacement.equals(""))
matcher.appendReplacement(
result, replacement); // Replace the match with the corresponding value
Expand Down

0 comments on commit dd1ba51

Please sign in to comment.