You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ki...@apache.org on 2020/08/04 03:05:50 UTC
[incubator-pinot] branch master updated: New endpoint to get
routing table for sql query (#5791)
This is an automated email from the ASF dual-hosted git repository.
kishoreg 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 d1b4586 New endpoint to get routing table for sql query (#5791)
d1b4586 is described below
commit d1b458644e505f07c919e7eb983feb9dafcd0061
Author: Oğuzhan Mangır <og...@gmail.com>
AuthorDate: Tue Aug 4 06:05:32 2020 +0300
New endpoint to get routing table for sql query (#5791)
* Add new endpoint to get routing table for sql query
* Add integration test for routing table sql endpoint
---
.../broker/api/resources/PinotBrokerDebug.java | 25 ++++++++++++++++++----
.../tests/HybridClusterIntegrationTest.java | 15 ++++++++++++-
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/pinot-broker/src/main/java/org/apache/pinot/broker/api/resources/PinotBrokerDebug.java b/pinot-broker/src/main/java/org/apache/pinot/broker/api/resources/PinotBrokerDebug.java
index 1743dee..cb6f71a 100644
--- a/pinot-broker/src/main/java/org/apache/pinot/broker/api/resources/PinotBrokerDebug.java
+++ b/pinot-broker/src/main/java/org/apache/pinot/broker/api/resources/PinotBrokerDebug.java
@@ -42,13 +42,15 @@ import org.apache.pinot.core.transport.ServerInstance;
import org.apache.pinot.pql.parsers.Pql2Compiler;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.sql.parsers.CalciteSqlCompiler;
@Api(tags = "Debug")
@Path("/")
// TODO: Add APIs to return the RoutingTable (with unavailable segments)
public class PinotBrokerDebug {
- private static final Pql2Compiler COMPILER = new Pql2Compiler();
+ private static final Pql2Compiler PQL_COMPILER = new Pql2Compiler();
+ private static final CalciteSqlCompiler CALCITE_COMPILER = new CalciteSqlCompiler();
@Inject
private RoutingManager _routingManager;
@@ -82,7 +84,7 @@ public class PinotBrokerDebug {
if (tableType != TableType.REALTIME) {
String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(tableName);
RoutingTable routingTable =
- _routingManager.getRoutingTable(COMPILER.compileToBrokerRequest("SELECT * FROM " + offlineTableName));
+ _routingManager.getRoutingTable(PQL_COMPILER.compileToBrokerRequest("SELECT * FROM " + offlineTableName));
if (routingTable != null) {
result.put(offlineTableName, routingTable.getServerInstanceToSegmentsMap());
}
@@ -90,7 +92,7 @@ public class PinotBrokerDebug {
if (tableType != TableType.OFFLINE) {
String realtimeTableName = TableNameBuilder.REALTIME.tableNameWithType(tableName);
RoutingTable routingTable =
- _routingManager.getRoutingTable(COMPILER.compileToBrokerRequest("SELECT * FROM " + realtimeTableName));
+ _routingManager.getRoutingTable(PQL_COMPILER.compileToBrokerRequest("SELECT * FROM " + realtimeTableName));
if (routingTable != null) {
result.put(realtimeTableName, routingTable.getServerInstanceToSegmentsMap());
}
@@ -109,11 +111,26 @@ public class PinotBrokerDebug {
@ApiResponses(value = {@ApiResponse(code = 200, message = "Routing table"), @ApiResponse(code = 404, message = "Routing not found"), @ApiResponse(code = 500, message = "Internal server error")})
public Map<ServerInstance, List<String>> getRoutingTableForQuery(
@ApiParam(value = "Pql query (table name should have type suffix)") @QueryParam("pql") String pql) {
- RoutingTable routingTable = _routingManager.getRoutingTable(COMPILER.compileToBrokerRequest(pql));
+ RoutingTable routingTable = _routingManager.getRoutingTable(PQL_COMPILER.compileToBrokerRequest(pql));
if (routingTable != null) {
return routingTable.getServerInstanceToSegmentsMap();
} else {
throw new WebApplicationException("Cannot find routing for query: " + pql, Response.Status.NOT_FOUND);
}
}
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/debug/routingTable/sql")
+ @ApiOperation(value = "Get the routing table for a SQL query")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Routing table"), @ApiResponse(code = 404, message = "Routing not found"), @ApiResponse(code = 500, message = "Internal server error")})
+ public Map<ServerInstance, List<String>> getRoutingTableForSQLQuery(
+ @ApiParam(value = "SQL query (table name should have type suffix)") @QueryParam("query") String query) {
+ RoutingTable routingTable = _routingManager.getRoutingTable(CALCITE_COMPILER.compileToBrokerRequest(query));
+ if (routingTable != null) {
+ return routingTable.getServerInstanceToSegmentsMap();
+ } else {
+ throw new WebApplicationException("Cannot find routing for query: " + query, Response.Status.NOT_FOUND);
+ }
+ }
}
diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
index fcbc1c5..d7eb42c 100644
--- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
+++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/HybridClusterIntegrationTest.java
@@ -20,7 +20,7 @@ package org.apache.pinot.integration.tests;
import java.io.File;
import java.io.FileNotFoundException;
-import java.util.ArrayList;
+import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
@@ -185,6 +185,19 @@ public class HybridClusterIntegrationTest extends BaseClusterIntegrationTestSet
}
@Test
+ public void testBrokerDebugRoutingTableSQL()
+ throws Exception {
+ String tableName = getTableName();
+ String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(tableName);
+ String realtimeTableName = TableNameBuilder.REALTIME.tableNameWithType(tableName);
+ String encodedSQL;
+ encodedSQL = URLEncoder.encode("select * from " + realtimeTableName, "UTF-8");
+ Assert.assertNotNull(getDebugInfo("debug/routingTable/sql?query=" + encodedSQL));
+ encodedSQL = URLEncoder.encode("select * from " + offlineTableName, "UTF-8");
+ Assert.assertNotNull(getDebugInfo("debug/routingTable/sql?query=" + encodedSQL));
+ }
+
+ @Test
@Override
public void testHardcodedQueries()
throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org