This is an automated email from the ASF dual-hosted git repository.
nehapawar 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 155cb3b Fix PostQuery command to accept queryType. Use Request in
Connection and PreparedStatement to execute sql (#5112)
155cb3b is described below
commit 155cb3b27e2c4c8fb31ebdfe30f79a55c5a417ab
Author: Neha Pawar <[email protected]>
AuthorDate: Sat Mar 7 17:37:32 2020 -0800
Fix PostQuery command to accept queryType. Use Request in Connection and
PreparedStatement to execute sql (#5112)
---
.../java/org/apache/pinot/client/Connection.java | 59 +++++++++++++++-------
.../org/apache/pinot/client/PreparedStatement.java | 28 +++++++---
.../java/org/apache/pinot/client/package-info.java | 4 +-
.../apache/pinot/client/PreparedStatementTest.java | 2 +-
.../tools/admin/command/PostQueryCommand.java | 6 ++-
5 files changed, 67 insertions(+), 32 deletions(-)
diff --git
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java
index 9e47803..b821734 100644
---
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java
+++
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java
@@ -49,29 +49,45 @@ public class Connection {
}
/**
+ * Creates a prepared statement, to escape a PQL query parameters.
+ *
+ * Deprecated as we will soon be removing support for pql endpoint
+ *
+ * @param query The PQL query for which to create a prepared statement.
+ * @return A prepared statement for this connection.
+ */
+ @Deprecated
+ public PreparedStatement prepareStatement(String query) {
+ return new PreparedStatement(this, query);
+ }
+
+ /**
* Creates a prepared statement, to escape query parameters.
*
- * @param statement The statement for which to create a prepared statement.
+ * @param request The request for which to create a prepared statement.
* @return A prepared statement for this connection.
*/
- public PreparedStatement prepareStatement(String statement) {
- return new PreparedStatement(this, statement);
+ public PreparedStatement prepareStatement(Request request) {
+ return new PreparedStatement(this, request);
}
/**
- * Executes a PQL statement.
- * @param statement The statement to execute
+ * Executes a PQL query.
+ *
+ * Deprecated as we will soon be removing support for pql endpoint
+ * @param query The query to execute
* @return The result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
- public ResultSetGroup execute(String statement)
+ @Deprecated
+ public ResultSetGroup execute(String query)
throws PinotClientException {
- return execute(null, new Request("pql", statement));
+ return execute(null, new Request("pql", query));
}
/**
* Executes a Pinot Request.
- * @param request The statement to execute
+ * @param request The request to execute
* @return The result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
@@ -81,21 +97,23 @@ public class Connection {
}
/**
- * Executes a PQL statement.
+ * Executes a PQL query.
*
- * @param statement The statement to execute
+ * Deprecated as we will soon be removing support for pql endpoint
+ * @param query The query to execute
* @return The result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
- public ResultSetGroup execute(String tableName, String statement)
+ @Deprecated
+ public ResultSetGroup execute(String tableName, String query)
throws PinotClientException {
- return execute(tableName, new Request("pql", statement));
+ return execute(tableName, new Request("pql", query));
}
/**
* Executes a Pinot Request.
*
- * @param request The statement to execute
+ * @param request The request to execute
* @return The result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
@@ -114,21 +132,24 @@ public class Connection {
}
/**
- * Executes a PQL statement asynchronously.
+ * Executes a PQL query asynchronously.
+ *
+ * Deprecated as we will soon be removing support for pql endpoint
*
- * @param statement The statement to execute
+ * @param query The query to execute
* @return A future containing the result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
- public Future<ResultSetGroup> executeAsync(String statement)
+ @Deprecated
+ public Future<ResultSetGroup> executeAsync(String query)
throws PinotClientException {
- return executeAsync(new Request("pql", statement));
+ return executeAsync(new Request("pql", query));
}
/**
* Executes a Pinot Request asynchronously.
*
- * @param request The statement to execute
+ * @param request The request to execute
* @return A future containing the result of the query
* @throws PinotClientException If an exception occurs while processing the
query
*/
@@ -140,7 +161,7 @@ public class Connection {
"Could not find broker to query for statement: " +
(request.getQuery() == null ? "null"
: request.getQuery()));
}
- final Future<BrokerResponse> responseFuture =
_transport.executeQueryAsync(brokerHostPort, request.getQuery());
+ final Future<BrokerResponse> responseFuture =
_transport.executeQueryAsync(brokerHostPort, request);
return new ResultSetGroupFuture(responseFuture);
}
diff --git
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/PreparedStatement.java
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/PreparedStatement.java
index fee0d52..8a527f5 100644
---
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/PreparedStatement.java
+++
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/PreparedStatement.java
@@ -28,19 +28,31 @@ public class PreparedStatement {
private final Connection _connection;
private final String _statement;
private final String[] _parameters;
+ private final String _queryFormat;
- PreparedStatement(Connection connection, String statement) {
+ @Deprecated
+ PreparedStatement(Connection connection, String query) {
_connection = connection;
- _statement = statement;
+ _statement = query;
+ _parameters = new String[getQuestionMarkCount(query)];
+ _queryFormat = "pql";
+ }
+ PreparedStatement(Connection connection, Request request) {
+ _connection = connection;
+ _statement = request.getQuery();
+ _parameters = new String[getQuestionMarkCount(request.getQuery())];
+ _queryFormat = request.getQueryFormat();
+ }
+
+ private int getQuestionMarkCount(String query) {
int questionMarkCount = 0;
- int index = statement.indexOf('?');
+ int index = query.indexOf('?');
while (index != -1) {
questionMarkCount++;
- index = statement.indexOf('?', index + 1);
+ index = query.indexOf('?', index + 1);
}
-
- _parameters = new String[questionMarkCount];
+ return questionMarkCount;
}
private String fillStatementWithParameters() {
@@ -57,7 +69,7 @@ public class PreparedStatement {
* @return The query results
*/
public ResultSetGroup execute() {
- return _connection.execute(fillStatementWithParameters());
+ return _connection.execute(new Request(_queryFormat,
fillStatementWithParameters()));
}
/**
@@ -66,7 +78,7 @@ public class PreparedStatement {
* @return The query results
*/
public Future<ResultSetGroup> executeAsync() {
- return _connection.executeAsync(fillStatementWithParameters());
+ return _connection.executeAsync(new Request(_queryFormat,
fillStatementWithParameters()));
}
/**
diff --git
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/package-info.java
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/package-info.java
index a1cb2f2..85ead99 100644
---
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/package-info.java
+++
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/package-info.java
@@ -32,8 +32,8 @@
* ("some-server:1234", "some-other-server:1234", ...);}</pre>
*
* Queries can be sent directly to the Pinot cluster using the
- * {@link org.apache.pinot.client.Connection#execute(java.lang.String)} and
- * {@link org.apache.pinot.client.Connection#executeAsync(java.lang.String)}
methods of
+ * {@link
org.apache.pinot.client.Connection#execute(org.apache.pinot.client.Request)} and
+ * {@link
org.apache.pinot.client.Connection#executeAsync(org.apache.pinot.client.Request)}
methods of
* {@link org.apache.pinot.client.Connection}.
*
* <pre>{@code ResultSetGroup resultSetGroup = connection.execute("select *
from foo...");
diff --git
a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/PreparedStatementTest.java
b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/PreparedStatementTest.java
index 6b01c29..89c719f 100644
---
a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/PreparedStatementTest.java
+++
b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/PreparedStatementTest.java
@@ -37,7 +37,7 @@ public class PreparedStatementTest {
public void testPreparedStatementEscaping() {
// Create a prepared statement that has to quote a string appropriately
Connection connection = ConnectionFactory.fromHostList("dummy");
- PreparedStatement preparedStatement = connection.prepareStatement("SELECT
foo FROM bar WHERE baz = ?");
+ PreparedStatement preparedStatement = connection.prepareStatement(new
Request("sql", "SELECT foo FROM bar WHERE baz = ?"));
preparedStatement.setString(0, "'hello'");
preparedStatement.execute();
diff --git
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/PostQueryCommand.java
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/PostQueryCommand.java
index fe51b46..e08aa3e 100644
---
a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/PostQueryCommand.java
+++
b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/PostQueryCommand.java
@@ -99,14 +99,16 @@ public class PostQueryCommand extends
AbstractBaseAdminCommand implements Comman
}
LOGGER.info("Executing command: " + toString());
- String request = null;
+ String request;
+ String urlString = "http://" + _brokerHost + ":" + _brokerPort + "/query";
if (_queryType.toLowerCase().equals(Request.SQL)) {
+ urlString += "/sql";
request = JsonUtils.objectToString(Collections.singletonMap(Request.SQL,
_query));
} else {
request = JsonUtils.objectToString(Collections.singletonMap(Request.PQL,
_query));
}
- return sendPostRequest("http://" + _brokerHost + ":" + _brokerPort +
"/query", request);
+ return sendPostRequest(urlString, request);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]