You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2021/02/22 18:49:25 UTC
[incubator-pinot] branch master updated: Add support for getObject
for datatypes supported by Pinot (#6581)
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new b06a949 Add support for getObject for datatypes supported by Pinot (#6581)
b06a949 is described below
commit b06a94956eb7d69355c469b2cc5f29beca58f604
Author: Kartik Khare <kh...@gmail.com>
AuthorDate: Tue Feb 23 00:19:10 2021 +0530
Add support for getObject for datatypes supported by Pinot (#6581)
---
.../org/apache/pinot/client/PinotResultSet.java | 50 ++++++++++++++++++++++
.../pinot/client/base/AbstractBaseResultSet.java | 20 ++-------
2 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
index cf3ddbc..10a476b 100644
--- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
+++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
@@ -29,6 +29,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.sql.ResultSetMetaData;
+import java.sql.SQLDataException;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
@@ -38,6 +39,7 @@ import java.util.Map;
import org.apache.commons.codec.binary.Hex;
import org.apache.pinot.client.base.AbstractBaseResultSet;
import org.apache.pinot.client.utils.DateTimeUtils;
+import org.apache.pinot.client.utils.DriverUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -297,6 +299,54 @@ public class PinotResultSet extends AbstractBaseResultSet {
return val;
}
+ @Override
+ public Object getObject(int columnIndex)
+ throws SQLException {
+
+ String dataType = _columnDataTypes.getOrDefault(columnIndex, "");
+
+ if (dataType.isEmpty()) {
+ throw new SQLDataException("Data type not supported for " + dataType);
+ }
+
+ switch (dataType) {
+ case "STRING":
+ return getString(columnIndex);
+ case "INT":
+ return getInt(columnIndex);
+ case "LONG":
+ return getLong(columnIndex);
+ case "FLOAT":
+ return getFloat(columnIndex);
+ case "DOUBLE":
+ return getDouble(columnIndex);
+ case "BOOLEAN":
+ return getBoolean(columnIndex);
+ case "BYTES":
+ return getBytes(columnIndex);
+ default:
+ throw new SQLDataException("Data type not supported for " + dataType);
+ }
+ }
+
+ @Override
+ public <T> T getObject(int columnIndex, Class<T> type)
+ throws SQLException {
+ Object value = getObject(columnIndex);
+
+ try {
+ return type.cast(value);
+ } catch (ClassCastException e) {
+ throw new SQLDataException("Data type conversion is not supported from :" + value.getClass() + " to: " + type);
+ }
+ }
+
+ @Override
+ public <T> T getObject(String columnLabel, Class<T> type)
+ throws SQLException {
+ return super.getObject(columnLabel, type);
+ }
+
private boolean checkIsNull(String val) {
if (val == null || val.toLowerCase().contentEquals(NULL_STRING)) {
_wasNull = true;
diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/base/AbstractBaseResultSet.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/base/AbstractBaseResultSet.java
index 4c2034c..1e27eee 100644
--- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/base/AbstractBaseResultSet.java
+++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/base/AbstractBaseResultSet.java
@@ -307,39 +307,27 @@ public abstract class AbstractBaseResultSet implements ResultSet {
}
@Override
- public Object getObject(int columnIndex)
- throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
public Object getObject(String columnLabel)
throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return getObject(findColumn(columnLabel));
}
@Override
public Object getObject(int columnIndex, Map<String, Class<?>> map)
throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return getObject(columnIndex);
}
@Override
public Object getObject(String columnLabel, Map<String, Class<?>> map)
throws SQLException {
- throw new SQLFeatureNotSupportedException();
- }
-
- @Override
- public <T> T getObject(int columnIndex, Class<T> type)
- throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return getObject(findColumn(columnLabel), map);
}
@Override
public <T> T getObject(String columnLabel, Class<T> type)
throws SQLException {
- throw new SQLFeatureNotSupportedException();
+ return getObject(findColumn(columnLabel), type);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org