Skip to content

Commit

Permalink
improve array listing
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Aug 23, 2023
1 parent aab6839 commit 13a085c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Other available properties are:
- ```password(String)```
- ```verifySSL(boolean)```
- ```overwritePrevious(boolean)```
- ```listPublicArrays(boolean)``` lists all public TileDB arrays. Default: ```true```

## Run a simple query
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'project-report'


group 'io.tiledb'
version '0.3.1-SNAPSHOT'
version '0.3.2-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@ public class TileDBCloudColumnsResultSet implements ResultSet {
private Logger logger = Logger.getLogger(TileDBCloudColumnsResultSet.class.getName());

private String arrayName;
private int numColumns;
private ArrayInfo requestedArrayInfo = null;

private String namespace;

private static List<Attribute> attributes; // static for speed
private static List<Dimension> dimensions; // static for speed

private int columnCounter, nullable;
private String currentColumnName, remarks, dataType;

public TileDBCloudColumnsResultSet(String arrayName, String namespace, ArrayApi arrayApi) {
public TileDBCloudColumnsResultSet(String arrayName, ArrayApi arrayApi) {
this.columnCounter = -1;
this.arrayName = arrayName;
this.namespace = namespace;
this.nullable = columnNoNulls;

try {
String[] split = arrayName.split("/");
String arrayNameClean = split[split.length - 1];
ArraySchema result = arrayApi.getArray(namespace, arrayNameClean, "application/json");
String arrayNamespaceClean = split[split.length - 2];
ArraySchema result =
arrayApi.getArray(arrayNamespaceClean, arrayNameClean, "application/json");
attributes = result.getAttributes();
dimensions = result.getDomain().getDimensions();
} catch (ApiException e) {
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/io/tiledb/TileDBCloudConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ public class TileDBCloudConnection implements java.sql.Connection {
private ArrayApi arrayApi;
private TileDBClient tileDBClient;
private String namespace;
private boolean listPublicArrays;

Logger logger = Logger.getLogger(TileDBCloudConnection.class.getName());

/** @param namespace The TileDB namespace */
TileDBCloudConnection(String namespace) {
TileDBCloudConnection(String namespace, boolean listPublicArrays) {
this.tileDBClient = new TileDBClient();
this.arrayApi = new ArrayApi(tileDBClient.getApiClient());
this.namespace = namespace;
this.listPublicArrays = listPublicArrays;
}

/**
* @param namespace The TileDB namespace
* @param login The TileDB login object
*/
TileDBCloudConnection(String namespace, TileDBLogin login) {
TileDBCloudConnection(String namespace, TileDBLogin login, boolean listPublicArrays) {
this.tileDBClient = new TileDBClient(login);
this.arrayApi = new ArrayApi(tileDBClient.getApiClient());
this.namespace = namespace;
this.listPublicArrays = listPublicArrays;
}

@Override
Expand All @@ -54,8 +57,7 @@ public PreparedStatement prepareStatement(String s) throws SQLException {
}

/**
* Replace \"\ with \`\ and remove schema name to make the driver fully compatible with Power BI's
* sql syntax.*
* Making the driver fully compatible with Power BI's sql syntax.*
*
* @param sql The input query
* @return The TIleDB compatible query
Expand Down Expand Up @@ -131,18 +133,19 @@ public DatabaseMetaData getMetaData() throws SQLException {
FileType.REGISTERED_TASK_GRAPH.toString(),
FileType.USER_DEFINED_FUNCTION.toString());

// owned arrays
try {
ArrayBrowserData resultOwned =
arrayApi.arraysBrowserOwnedGet(
null, null, null, namespace, null, null, null, null, null, excludeFileType, null);
tileDBCloudDatabaseMetadata.setArraysOwned(resultOwned);
} catch (Exception e) {
e.printStackTrace();
}

// shared arrays
try {

List<String> sharedTo = Arrays.asList(namespace);

ArrayBrowserData resultShared =
arrayApi.arraysBrowserSharedGet(
null,
Expand All @@ -159,6 +162,20 @@ public DatabaseMetaData getMetaData() throws SQLException {
sharedTo);
tileDBCloudDatabaseMetadata.setArraysShared(resultShared);
} catch (Exception e) {
e.printStackTrace();
}

// public arrays
if (listPublicArrays) {
try {
ArrayBrowserData resultPublic =
arrayApi.arraysBrowserPublicGet(
null, null, null, null, "name", null, null, null, null, excludeFileType, null);
tileDBCloudDatabaseMetadata.setArraysPublic(resultPublic);
System.out.println(resultPublic);
} catch (Exception e) {
e.printStackTrace();
}
}

return tileDBCloudDatabaseMetadata;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class TileDBCloudDatabaseMetadata implements DatabaseMetaData {

private ArrayBrowserData arraysOwned;
private ArrayBrowserData arraysShared;
private ArrayBrowserData arraysPublic;

private String namespace;

private Logger logger = Logger.getLogger(TileDBCloudDatabaseMetadata.class.getName());
Expand Down Expand Up @@ -628,7 +630,7 @@ public ResultSet getTables(
String catalog, String schemaPattern, String tableNamePattern, String[] types)
throws SQLException {
logger.log(Level.INFO, "Requesting arrays from TileDB");
return new TileDBCloudTablesResultSet(this.arraysOwned, this.arraysShared, this.namespace);
return new TileDBCloudTablesResultSet(this.arraysOwned, this.arraysShared, this.arraysPublic);
}

@Override
Expand All @@ -655,7 +657,7 @@ public ResultSet getColumns(
String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
throws SQLException {
logger.log(Level.INFO, "Requesting columns for array: " + tableNamePattern);
return new TileDBCloudColumnsResultSet(tableNamePattern, namespace, arrayApi);
return new TileDBCloudColumnsResultSet(tableNamePattern, arrayApi);
}

@Override
Expand Down Expand Up @@ -959,6 +961,10 @@ public void setArraysShared(ArrayBrowserData result) {
this.arraysShared = result;
}

public void setArraysPublic(ArrayBrowserData resultPublic) {
this.arraysPublic = resultPublic;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/tiledb/TileDBCloudDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public Connection connect(String s, Properties properties) throws SQLException {
if (parts.length == 4) token = parts[3]; // the fourth part should be the token

// call the appropriate connector depending on the properties given
if (properties.isEmpty() && token.equals("")) return new TileDBCloudConnection(namespace);
return new TileDBCloudConnection(namespace, createLoginObject(properties));
boolean listPublicArrays =
Boolean.parseBoolean((String) properties.getOrDefault("listPublicArrays", "true"));
if (properties.isEmpty() && token.equals(""))
return new TileDBCloudConnection(namespace, listPublicArrays);
return new TileDBCloudConnection(namespace, createLoginObject(properties), listPublicArrays);
}

/**
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/io/tiledb/TileDBCloudTablesResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ public class TileDBCloudTablesResultSet implements ResultSet {
private Iterator<ArrayInfo> iterator = null;
private List<ArrayInfo> arraysOwned;
private List<ArrayInfo> arraysShared;
private List<ArrayInfo> arraysPublic;
private List<ArrayInfo> arrays;
private int arrayIndex;
private ArrayInfo currentArray;
private String namespace;

private Logger logger = Logger.getLogger(TileDBCloudTablesResultSet.class.getName());

public TileDBCloudTablesResultSet(
ArrayBrowserData arraysOwnedData, ArrayBrowserData arraysSharedData, String namespace) {
ArrayBrowserData arraysOwnedData,
ArrayBrowserData arraysSharedData,
ArrayBrowserData arraysPublicData) {
this.arrays = new ArrayList<ArrayInfo>();
this.namespace = namespace;

if (arraysOwnedData == null) this.arraysOwned = new ArrayList<ArrayInfo>();
else {
Expand All @@ -38,8 +39,14 @@ public TileDBCloudTablesResultSet(
this.arraysShared = arraysSharedData.getArrays();
}

this.arrays.addAll(arraysOwned);
this.arrays.addAll(arraysShared);
if (arraysPublicData == null) this.arraysPublic = new ArrayList<ArrayInfo>();
else {
this.arraysPublic = arraysPublicData.getArrays();
}

this.arrays.addAll(this.arraysOwned);
this.arrays.addAll(this.arraysShared);
this.arrays.addAll(this.arraysPublic);

this.iterator = this.arrays.iterator();

Expand Down Expand Up @@ -72,7 +79,7 @@ public boolean wasNull() throws SQLException {

@Override
public String getString(int columnIndex) throws SQLException {
return currentArray.getTiledbUri();
return "tiledb://" + currentArray.getNamespace() + "/" + currentArray.getName();
}

@Override
Expand Down Expand Up @@ -169,15 +176,15 @@ public String getString(String columnLabel) throws SQLException {

switch (columnLabel) {
case "TABLE_NAME":
return currentArray.getTiledbUri();
return "tiledb://" + currentArray.getNamespace() + "/" + currentArray.getName();
case "REMARKS":
return ownership;
case "TABLE_TYPE":
return "TABLE";
case "TABLE_SCHEM":
return Util.SCHEMA_NAME;
case "TABLE_CATALOG":
return this.namespace;
return currentArray.getNamespace();
}
return "";
}
Expand Down

0 comments on commit 13a085c

Please sign in to comment.