From 381c72eae51ac5c87971d0aaa65dffe943bee497 Mon Sep 17 00:00:00 2001 From: dimitrisstaratzis Date: Fri, 15 Sep 2023 17:06:30 +0300 Subject: [PATCH] fix array listing in Tableau --- build.gradle | 2 +- .../tiledb/TileDBCloudColumnsResultSet.java | 4 +- .../tiledb/TileDBCloudDatabaseMetadata.java | 6 +-- .../java/io/tiledb/TileDBCloudResultSet.java | 10 +++- .../java/io/tiledb/TileDBCloudStatement.java | 3 +- .../io/tiledb/TileDBCloudTablesResultSet.java | 52 +++++++------------ .../TileDBCloudTablesResultSetMetadata.java | 34 +++++++++--- src/main/java/io/tiledb/util/Util.java | 2 +- 8 files changed, 60 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index f0db515..94a76bb 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ apply plugin: 'project-report' group 'io.tiledb' -version '0.3.2-SNAPSHOT' +version '0.3.3-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java b/src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java index 26296fc..5e3d65c 100644 --- a/src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java +++ b/src/main/java/io/tiledb/TileDBCloudColumnsResultSet.java @@ -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; @@ -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]; diff --git a/src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java b/src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java index 3a9ed39..3e7838d 100644 --- a/src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java +++ b/src/main/java/io/tiledb/TileDBCloudDatabaseMetadata.java @@ -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 diff --git a/src/main/java/io/tiledb/TileDBCloudResultSet.java b/src/main/java/io/tiledb/TileDBCloudResultSet.java index b891ccd..a5c2789 100644 --- a/src/main/java/io/tiledb/TileDBCloudResultSet.java +++ b/src/main/java/io/tiledb/TileDBCloudResultSet.java @@ -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++; @@ -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 @@ -398,7 +404,7 @@ public int getFetchSize() throws SQLException { @Override public int getType() throws SQLException { - return 0; + return ResultSet.TYPE_FORWARD_ONLY; } @Override diff --git a/src/main/java/io/tiledb/TileDBCloudStatement.java b/src/main/java/io/tiledb/TileDBCloudStatement.java index d362f13..816df04 100644 --- a/src/main/java/io/tiledb/TileDBCloudStatement.java +++ b/src/main/java/io/tiledb/TileDBCloudStatement.java @@ -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; @@ -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); diff --git a/src/main/java/io/tiledb/TileDBCloudTablesResultSet.java b/src/main/java/io/tiledb/TileDBCloudTablesResultSet.java index afc2192..2b832bc 100644 --- a/src/main/java/io/tiledb/TileDBCloudTablesResultSet.java +++ b/src/main/java/io/tiledb/TileDBCloudTablesResultSet.java @@ -13,12 +13,12 @@ import java.util.logging.Logger; public class TileDBCloudTablesResultSet implements ResultSet { - private List arraysOwned; - private List arraysShared; - private List arraysPublic; - private List arrays; + private List arraysOwned = new ArrayList(); + private List arraysShared = new ArrayList(); + private List arraysPublic = new ArrayList(); private int arrayIndex; private ArrayInfo currentArray; + private int numberOfArrays; private Logger logger = Logger.getLogger(TileDBCloudTablesResultSet.class.getName()); @@ -26,27 +26,22 @@ public TileDBCloudTablesResultSet( ArrayBrowserData arraysOwnedData, ArrayBrowserData arraysSharedData, ArrayBrowserData arraysPublicData) { - this.arrays = new ArrayList(); - if (arraysOwnedData == null) this.arraysOwned = new ArrayList(); - else { - this.arraysOwned = arraysOwnedData.getArrays(); - } + if (arraysOwnedData != null) this.arraysOwned = arraysOwnedData.getArrays(); - if (arraysSharedData == null) this.arraysShared = new ArrayList(); - else { - this.arraysShared = arraysSharedData.getArrays(); - } + if (arraysSharedData != null) this.arraysShared = arraysSharedData.getArrays(); - if (arraysPublicData == null) this.arraysPublic = new ArrayList(); - 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 { @@ -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 @@ -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": @@ -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 @@ -409,7 +395,7 @@ public int getFetchSize() throws SQLException { @Override public int getType() throws SQLException { - return 0; + return ResultSet.TYPE_FORWARD_ONLY; } @Override diff --git a/src/main/java/io/tiledb/TileDBCloudTablesResultSetMetadata.java b/src/main/java/io/tiledb/TileDBCloudTablesResultSetMetadata.java index 14cb9e7..9b8763b 100644 --- a/src/main/java/io/tiledb/TileDBCloudTablesResultSetMetadata.java +++ b/src/main/java/io/tiledb/TileDBCloudTablesResultSetMetadata.java @@ -11,16 +11,26 @@ public class TileDBCloudTablesResultSetMetadata implements ResultSetMetaData { private Logger logger = Logger.getLogger(TileDBCloudTablesResultSetMetadata.class.getName()); - private List arrays; + private List arraysOwned; + private List arraysShared; + private List arraysPublic; + private int numberOfArrays; - public TileDBCloudTablesResultSetMetadata(List arrays) { - this.arrays = arrays; + public TileDBCloudTablesResultSetMetadata( + List arraysOwned, + List arraysShared, + List 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 @@ -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 diff --git a/src/main/java/io/tiledb/util/Util.java b/src/main/java/io/tiledb/util/Util.java index 43a2056..cc91c24 100644 --- a/src/main/java/io/tiledb/util/Util.java +++ b/src/main/java/io/tiledb/util/Util.java @@ -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;