You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by kh...@apache.org on 2021/07/01 19:49:31 UTC
[incubator-pinot] 01/01: Make JDBC driver compatible for Timestamp
datatype - Add Timestamp datatype support in driver utils - Add support for
max rows with default as integer.max so that all the results are returned
by default - Include java-client dependency in the jdbc client shaded jar.
This will allow users to copy jdbc jar alone in the drivers.
This is an automated email from the ASF dual-hosted git repository.
kharekartik pushed a commit to branch jdbc_tableau
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit ee2848e8c265ac14f9b6797f3fcfa87ef87ef3c0
Author: KKcorps <kh...@gmail.com>
AuthorDate: Fri Jul 2 00:46:46 2021 +0530
Make JDBC driver compatible for Timestamp datatype
- Add Timestamp datatype support in driver utils
- Add support for max rows with default as integer.max so that all the results are returned by default
- Include java-client dependency in the jdbc client shaded jar. This will allow users to copy jdbc jar alone in the drivers.
---
pinot-clients/pinot-jdbc-client/pom.xml | 34 ++++++++++++++++++++++
.../pinot/client/PinotPreparedStatement.java | 34 ++++++++++++++++++++--
.../org/apache/pinot/client/PinotStatement.java | 29 ++++++++++++++++++
.../org/apache/pinot/client/utils/DriverUtils.java | 7 +++++
.../pinot/client/PinotPreparedStatementTest.java | 18 ++++++++----
5 files changed, 114 insertions(+), 8 deletions(-)
diff --git a/pinot-clients/pinot-jdbc-client/pom.xml b/pinot-clients/pinot-jdbc-client/pom.xml
index 54e26aa..9562491 100644
--- a/pinot-clients/pinot-jdbc-client/pom.xml
+++ b/pinot-clients/pinot-jdbc-client/pom.xml
@@ -63,6 +63,7 @@
<dependency>
<groupId>org.apache.pinot</groupId>
<artifactId>pinot-java-client</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
@@ -106,4 +107,37 @@
<artifactId>jsr305</artifactId>
</dependency>
</dependencies>
+
+ <profiles>
+ <profile>
+ <id>build-shaded-jar</id>
+ <activation>
+ <property>
+ <name>skipShade</name>
+ <value>!true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>3.2.1</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
index 20d6847..648b877 100644
--- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
+++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
@@ -33,6 +33,7 @@ import org.apache.pinot.client.utils.DateTimeUtils;
public class PinotPreparedStatement extends AbstractBasePreparedStatement {
private static final String QUERY_FORMAT = "sql";
+ public static final String LIMIT_STATEMENT = "LIMIT";
private Connection _connection;
private org.apache.pinot.client.Connection _session;
private ResultSetGroup _resultSetGroup;
@@ -40,13 +41,17 @@ public class PinotPreparedStatement extends AbstractBasePreparedStatement {
private String _query;
private boolean _closed;
private ResultSet _resultSet;
+ private Integer _maxRows = Integer.MAX_VALUE;
public PinotPreparedStatement(PinotConnection connection, String query) {
_connection = connection;
_session = connection.getSession();
- _query = query;
_closed = false;
- _preparedStatement = new PreparedStatement(_session, new Request(QUERY_FORMAT, query));
+ _query = query;
+ if(!_query.contains(LIMIT_STATEMENT)) {
+ _query = _query.concat(" " + LIMIT_STATEMENT + " " + _maxRows);
+ }
+ _preparedStatement = new PreparedStatement(_session, new Request(QUERY_FORMAT, _query));
}
@Override
@@ -234,7 +239,6 @@ public class PinotPreparedStatement extends AbstractBasePreparedStatement {
return execute(sql);
}
-
@Override
public ResultSet getResultSet()
throws SQLException {
@@ -258,6 +262,30 @@ public class PinotPreparedStatement extends AbstractBasePreparedStatement {
}
@Override
+ public int getFetchSize()
+ throws SQLException {
+ return _maxRows;
+ }
+
+ @Override
+ public void setFetchSize(int rows)
+ throws SQLException {
+ _maxRows = rows;
+ }
+
+ @Override
+ public int getMaxRows()
+ throws SQLException {
+ return _maxRows;
+ }
+
+ @Override
+ public void setMaxRows(int max)
+ throws SQLException {
+ _maxRows = max;
+ }
+
+ @Override
public boolean isClosed()
throws SQLException {
return _closed;
diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotStatement.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotStatement.java
index 4fbe02d..d3df38e 100644
--- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotStatement.java
+++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotStatement.java
@@ -27,11 +27,13 @@ import org.apache.pinot.client.base.AbstractBaseStatement;
public class PinotStatement extends AbstractBaseStatement {
private static final String QUERY_FORMAT = "sql";
+ public static final String LIMIT_STATEMENT = "LIMIT";
private Connection _connection;
private org.apache.pinot.client.Connection _session;
private ResultSetGroup _resultSetGroup;
private boolean _closed;
private ResultSet _resultSet;
+ private Integer _maxRows = Integer.MAX_VALUE;
public PinotStatement(PinotConnection connection) {
_connection = connection;
@@ -59,6 +61,9 @@ public class PinotStatement extends AbstractBaseStatement {
throws SQLException {
validateState();
try {
+ if(!sql.contains(LIMIT_STATEMENT)) {
+ sql = sql.concat(" " + LIMIT_STATEMENT + " " + _maxRows);
+ }
Request request = new Request(QUERY_FORMAT, sql);
_resultSetGroup = _session.execute(request);
if (_resultSetGroup.getResultSetCount() == 0) {
@@ -117,6 +122,30 @@ public class PinotStatement extends AbstractBaseStatement {
}
@Override
+ public int getFetchSize()
+ throws SQLException {
+ return _maxRows;
+ }
+
+ @Override
+ public void setFetchSize(int rows)
+ throws SQLException {
+ _maxRows = rows;
+ }
+
+ @Override
+ public int getMaxRows()
+ throws SQLException {
+ return _maxRows;
+ }
+
+ @Override
+ public void setMaxRows(int max)
+ throws SQLException {
+ _maxRows = max;
+ }
+
+ @Override
public boolean isClosed()
throws SQLException {
return _closed;
diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
index 3b533b1..944f7ab 100644
--- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
+++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
@@ -19,6 +19,7 @@
package org.apache.pinot.client.utils;
import java.net.URI;
+import java.sql.Timestamp;
import java.sql.Types;
import java.util.Collections;
import java.util.List;
@@ -99,6 +100,9 @@ public class DriverUtils {
case "BYTES":
columnsSQLDataType = Types.BINARY;
break;
+ case "TIMESTAMP":
+ columnsSQLDataType = Types.TIMESTAMP;
+ break;
default:
columnsSQLDataType = Types.NULL;
}
@@ -132,6 +136,9 @@ public class DriverUtils {
case "BYTES":
columnsJavaClassName = byte.class.getTypeName();
break;
+ case "TIMESTAMP":
+ columnsJavaClassName = Timestamp.class.getTypeName();
+ break;
default:
columnsJavaClassName = String.class.getTypeName();
}
diff --git a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
index b32e3fe..ed58239 100644
--- a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
+++ b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
@@ -51,7 +51,9 @@ public class PinotPreparedStatementTest {
preparedStatement.setFloat(6, 1.4f);
preparedStatement.executeQuery();
- Assert.assertEquals(_dummyPinotClientTransport.getLastQuery(),
+ String lastExecutedQuery = _dummyPinotClientTransport.getLastQuery();
+
+ Assert.assertEquals(lastExecutedQuery.substring(0, lastExecutedQuery.indexOf("LIMIT")).stripTrailing(),
"SELECT * FROM dummy WHERE name = 'foo' and age = 20 and score = 98.1 and ts = 123456789 and eligible = 'true' and sub_score = 1.4");
preparedStatement.clearParameters();
@@ -63,7 +65,9 @@ public class PinotPreparedStatementTest {
preparedStatement.setFloat(6, 0);
preparedStatement.executeQuery();
- Assert.assertEquals(_dummyPinotClientTransport.getLastQuery(),
+ lastExecutedQuery = _dummyPinotClientTransport.getLastQuery();
+
+ Assert.assertEquals(lastExecutedQuery.substring(0, lastExecutedQuery.indexOf("LIMIT")).stripTrailing(),
"SELECT * FROM dummy WHERE name = '' and age = 0 and score = 0.0 and ts = 0 and eligible = 'false' and sub_score = 0.0");
}
@@ -81,8 +85,9 @@ public class PinotPreparedStatementTest {
String expectedDate = DateTimeUtils.dateToString(new Date(currentTimestamp));
String expectedTime = DateTimeUtils.timeStampToString(new Timestamp(currentTimestamp));
+ String lastExecutedQuery = _dummyPinotClientTransport.getLastQuery();
- Assert.assertEquals(_dummyPinotClientTransport.getLastQuery(), String
+ Assert.assertEquals(lastExecutedQuery.substring(0, lastExecutedQuery.indexOf("LIMIT")).stripTrailing(), String
.format("SELECT * FROM dummy WHERE date = '%s' and updated_at = '%s' and created_at = '%s'", expectedDate,
expectedTime, expectedTime));
}
@@ -96,13 +101,16 @@ public class PinotPreparedStatementTest {
String value = "1234567891011121314151617181920";
preparedStatement.setBigDecimal(1, new BigDecimal(value));
preparedStatement.executeQuery();
- Assert.assertEquals(_dummyPinotClientTransport.getLastQuery(),
+
+ String lastExecutedQuery = _dummyPinotClientTransport.getLastQuery();
+ Assert.assertEquals(lastExecutedQuery.substring(0, lastExecutedQuery.indexOf("LIMIT")).stripTrailing(),
String.format("SELECT * FROM dummy WHERE value = '%s'", value));
preparedStatement.clearParameters();
preparedStatement.setBytes(1, value.getBytes());
preparedStatement.executeQuery();
- Assert.assertEquals(_dummyPinotClientTransport.getLastQuery(),
+ lastExecutedQuery = _dummyPinotClientTransport.getLastQuery();
+ Assert.assertEquals(lastExecutedQuery.substring(0, lastExecutedQuery.indexOf("LIMIT")).stripTrailing(),
String.format("SELECT * FROM dummy WHERE value = '%s'", Hex.encodeHexString(value.getBytes())));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org