Skip to content

Commit

Permalink
fix array listing in Tableau
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Sep 15, 2023
1 parent 0473cfe commit e6ff22e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 53 deletions.
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.2-SNAPSHOT'
version '0.3.3-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.tiledb;

import static io.tiledb.util.Util.replaceArrayNamesWithUUIDs;
import static java.sql.DatabaseMetaData.columnNoNulls;
import static java.sql.DatabaseMetaData.columnNullable;

Expand Down Expand Up @@ -36,8 +35,7 @@ public TileDBCloudColumnsResultSet(String completeURI, ArrayApi arrayApi) {
this.completeURI = completeURI;
this.nullable = columnNoNulls;

String URIWithUUID = replaceArrayNamesWithUUIDs(completeURI);
String[] split = URIWithUUID.split("/");
String[] split = completeURI.split("/");
String arrayUUIDClean = split[split.length - 1];
String arrayNamespaceClean = split[split.length - 2];

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public String getDatabaseProductName() throws SQLException {

@Override
public String getDatabaseProductVersion() throws SQLException {
return Util.TILEDB_CLOUD_VERSION_MAJOR
+ "."
+ Util.TILEDB_CLOUD_VERSION_REVISION
+ "."
+ Util.TILEDB_CLOUD_VERSION_MINOR;
return Util.VERSION_MAJOR + "." + Util.VERSION_REVISION + "." + Util.VERSION_MINOR;
}

@Override
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/tiledb/TileDBCloudResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private void buildColumnsToPosition() {

@Override
public boolean next() throws SQLException {
if (valueVectors == null) return false;
if (valueVectors.get(currentBatch).getValueCount() - 1 > currentRow) {
currentRow++;
globalRowCount++;
Expand Down Expand Up @@ -109,7 +110,12 @@ public float getFloat(int i) throws SQLException {

@Override
public double getDouble(int i) throws SQLException {
return (double) valueVectors.get(i - 1 + (currentBatch * fieldsPerBatch)).getObject(currentRow);
try {
return (double)
valueVectors.get(i - 1 + (currentBatch * fieldsPerBatch)).getObject(currentRow);
} catch (java.lang.ClassCastException e) {
return getFloat(i);
}
}

@Override
Expand Down Expand Up @@ -398,7 +404,7 @@ public int getFetchSize() throws SQLException {

@Override
public int getType() throws SQLException {
return 0;
return ResultSet.TYPE_FORWARD_ONLY;
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/tiledb/TileDBCloudStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.tiledb.cloud.rest_api.model.ResultFormat;
import io.tiledb.cloud.rest_api.model.SQLParameters;
import io.tiledb.java.api.Pair;
import io.tiledb.util.Util;
import java.sql.*;
import java.util.ArrayList;
import org.apache.arrow.vector.ValueVector;
Expand Down Expand Up @@ -39,7 +38,7 @@ public class TileDBCloudStatement implements Statement {
public ResultSet executeQuery(String s) throws SQLException {
// create SQL parameters
SQLParameters sqlParameters = new SQLParameters();
sqlParameters.setQuery(Util.replaceArrayNamesWithUUIDs(s));
sqlParameters.setQuery(s);
// get results in arrow format
sqlParameters.setResultFormat(ResultFormat.ARROW);

Expand Down
52 changes: 19 additions & 33 deletions src/main/java/io/tiledb/TileDBCloudTablesResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,35 @@
import java.util.logging.Logger;

public class TileDBCloudTablesResultSet implements ResultSet {
private List<ArrayInfo> arraysOwned;
private List<ArrayInfo> arraysShared;
private List<ArrayInfo> arraysPublic;
private List<ArrayInfo> arrays;
private List<ArrayInfo> arraysOwned = new ArrayList<ArrayInfo>();
private List<ArrayInfo> arraysShared = new ArrayList<ArrayInfo>();
private List<ArrayInfo> arraysPublic = new ArrayList<ArrayInfo>();
private int arrayIndex;
private ArrayInfo currentArray;
private int numberOfArrays;

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

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

if (arraysOwnedData == null) this.arraysOwned = new ArrayList<ArrayInfo>();
else {
this.arraysOwned = arraysOwnedData.getArrays();
}
if (arraysOwnedData != null) this.arraysOwned = arraysOwnedData.getArrays();

if (arraysSharedData == null) this.arraysShared = new ArrayList<ArrayInfo>();
else {
this.arraysShared = arraysSharedData.getArrays();
}
if (arraysSharedData != null) this.arraysShared = arraysSharedData.getArrays();

if (arraysPublicData == null) this.arraysPublic = new ArrayList<ArrayInfo>();
else {
this.arraysPublic = arraysPublicData.getArrays();
}
if (arraysPublicData != null) this.arraysPublic = arraysPublicData.getArrays();

this.arrayIndex = -1;

this.numberOfArrays =
this.arraysOwned.size() + this.arraysShared.size() + this.arraysPublic.size();
}

public TileDBCloudTablesResultSet() {}
public TileDBCloudTablesResultSet() {
this.numberOfArrays = 0;
}

@Override
public boolean next() throws SQLException {
Expand Down Expand Up @@ -83,12 +78,7 @@ public boolean wasNull() throws SQLException {

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

@Override
Expand Down Expand Up @@ -186,14 +176,9 @@ public String getString(String columnLabel) throws SQLException {

switch (columnLabel) {
case "TABLE_NAME":
return "tiledb://"
+ currentArray.getNamespace()
+ "/"
+ currentArray.getName()
+ " ~ "
+ currentArray.getTiledbUri();
return "tiledb://" + currentArray.getNamespace() + "/" + currentArray.getName();
case "REMARKS":
return ownership;
return ownership + " TileDB URI: " + currentArray.getTiledbUri();
case "TABLE_TYPE":
return "TABLE";
case "TABLE_SCHEM":
Expand Down Expand Up @@ -296,7 +281,8 @@ public String getCursorName() throws SQLException {

@Override
public ResultSetMetaData getMetaData() throws SQLException {
return new TileDBCloudTablesResultSetMetadata(this.arrays);
return new TileDBCloudTablesResultSetMetadata(
this.arraysOwned, this.arraysShared, this.arraysPublic, this.numberOfArrays);
}

@Override
Expand Down Expand Up @@ -409,7 +395,7 @@ public int getFetchSize() throws SQLException {

@Override
public int getType() throws SQLException {
return 0;
return ResultSet.TYPE_FORWARD_ONLY;
}

@Override
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/io/tiledb/TileDBCloudTablesResultSetMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@
public class TileDBCloudTablesResultSetMetadata implements ResultSetMetaData {
private Logger logger = Logger.getLogger(TileDBCloudTablesResultSetMetadata.class.getName());

private List<ArrayInfo> arrays;
private List<ArrayInfo> arraysOwned;
private List<ArrayInfo> arraysShared;
private List<ArrayInfo> arraysPublic;
private int numberOfArrays;

public TileDBCloudTablesResultSetMetadata(List<ArrayInfo> arrays) {
this.arrays = arrays;
public TileDBCloudTablesResultSetMetadata(
List<ArrayInfo> arraysOwned,
List<ArrayInfo> arraysShared,
List<ArrayInfo> arraysPublic,
int numberOfArrays) {
this.arraysOwned = arraysOwned;
this.arraysShared = arraysShared;
this.arraysPublic = arraysPublic;
this.numberOfArrays = numberOfArrays;
}

@Override
public int getColumnCount() throws SQLException {
if (arrays == null) return 0;
return arrays.size();
if (this.numberOfArrays == 0) return 0;
return 5; // refers to the number of column Labels from TileDBCloudTablesResultSet which are 5
}

@Override
Expand Down Expand Up @@ -65,7 +75,19 @@ public String getColumnLabel(int column) throws SQLException {

@Override
public String getColumnName(int column) throws SQLException {
return arrays.get(column - 1).getName();
if (column < arraysOwned.size()) {
return arraysOwned.get(column - 1).getName();
}

if (column - arraysOwned.size() < arraysShared.size()) {
return arraysShared.get(column - arraysOwned.size() - 1).getName();
}

if (column - arraysOwned.size() - arraysShared.size() < arraysPublic.size()) {
return arraysPublic.get(column - arraysOwned.size() - arraysShared.size() - 1).getName();
}

return "";
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/tiledb/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Util {
public static int VERSION_MINOR = 1;
public static final int VERSION_REVISION = 3;
public static int VERSION_MAJOR = 0;
public static int VERSION_MAJOR = 3;

public static int TILEDB_CLOUD_VERSION_MINOR = 0;
public static int TILEDB_CLOUD_VERSION_REVISION = 2;
Expand Down

0 comments on commit e6ff22e

Please sign in to comment.