This is an automated email from the ASF dual-hosted git repository.
abhishekrb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 3a2220c68d5 Refactor: Move some classes from `sql` to `processing` &
`server` for reusability (#17542)
3a2220c68d5 is described below
commit 3a2220c68d5ce9f8443106f448c38c739929993d
Author: Abhishek Radhakrishnan <[email protected]>
AuthorDate: Fri Dec 6 11:32:03 2024 -0600
Refactor: Move some classes from `sql` to `processing` & `server` for
reusability (#17542)
This PR contains non-functional / refactoring changes of the following
classes in the sql module:
1. Move ExplainPlan and ExplainAttributes
fromsql/src/main/java/org/apache/druid/sql/http to
processing/src/main/java/org/apache/druid/query/explain
2. Move sql/src/main/java/org/apache/druid/sql/SqlTaskStatus.java ->
processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java
3. Add a new class
processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java that
is effectively a thin POJO version of SqlQuery in the sql module but without
any of the Calcite functionality and business logic.
4. Move BrokerClient, BrokerClientImpl and Broker classes from
sql/src/main/java/org/apache/druid/sql/client to
server/src/main/java/org/apache/druid/client/broker.
5. Remove BrokerServiceModule that provided the BrokerClient. The
functionality is now contained in ServiceClientModule in the server package
itself which provides all the clients as well.
This is done so that we can reuse the said classes in #17353 without
brining in Calcite and other dependencies to the Overlord.
---
.../druid/msq/sql/resources/SqlTaskResource.java | 2 +-
.../catalog/ITCatalogIngestAndQueryTest.java | 2 +-
.../testsEx/catalog/ITCatalogIngestErrorTest.java | 2 +-
.../msq/ITKeyStatisticsSketchMergeMode.java | 2 +-
.../msq/ITMultiStageQueryWorkerFaultTolerance.java | 2 +-
.../apache/druid/testsEx/msq/MultiStageQuery.java | 2 +-
.../druid/testing/utils/MsqTestQueryHelper.java | 2 +-
.../druid/query/explain}/ExplainAttributes.java | 2 +-
.../apache/druid/query/explain}/ExplainPlan.java | 3 +-
.../druid/query/http/ClientSqlParameter.java | 76 +++++++++++++
.../apache/druid/query/http/ClientSqlQuery.java | 119 +++++++--------------
.../apache/druid/query}/http/SqlTaskStatus.java | 2 +-
.../query/explain}/ExplainAttributesTest.java | 4 +-
.../druid/query/explain}/ExplainPlanTest.java | 3 +-
.../druid/query/http/ClientSqlQueryTest.java | 47 ++++----
.../druid/query}/http/SqlTaskStatusTest.java | 2 +-
.../org/apache/druid/client/broker}/Broker.java | 2 +-
.../apache/druid/client/broker}/BrokerClient.java | 12 +--
.../druid/client/broker}/BrokerClientImpl.java | 14 +--
.../druid/rpc/guice/ServiceClientModule.java | 31 +++++-
.../druid/client/broker}/BrokerClientImplTest.java | 28 +++--
.../druid/rpc/guice/ServiceClientModuleTest.java | 7 ++
.../druid/sql/calcite/planner/IngestHandler.java | 1 +
.../druid/sql/calcite/planner/PlannerContext.java | 1 +
.../druid/sql/calcite/planner/QueryHandler.java | 1 +
.../sql/calcite/planner/SqlStatementHandler.java | 1 +
.../druid/sql/guice/BrokerServiceModule.java | 91 ----------------
.../org/apache/druid/sql/http/SqlParameter.java | 5 +
.../java/org/apache/druid/sql/http/SqlQuery.java | 6 ++
.../druid/sql/calcite/http/SqlQueryTest.java | 64 ++++++++++-
.../druid/sql/guice/BrokerServiceModuleTest.java | 114 --------------------
31 files changed, 294 insertions(+), 356 deletions(-)
diff --git
a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java
b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java
index a07ef2c403f..11e39bfa126 100644
---
a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java
+++
b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java
@@ -34,6 +34,7 @@ import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.msq.guice.MultiStageQuery;
import org.apache.druid.msq.sql.MSQTaskSqlEngine;
import org.apache.druid.query.QueryException;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.server.QueryResponse;
import org.apache.druid.server.initialization.ServerConfig;
import org.apache.druid.server.security.Access;
@@ -47,7 +48,6 @@ import org.apache.druid.sql.SqlStatementFactory;
import org.apache.druid.sql.http.ResultFormat;
import org.apache.druid.sql.http.SqlQuery;
import org.apache.druid.sql.http.SqlResource;
-import org.apache.druid.sql.http.SqlTaskStatus;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
diff --git
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java
index 1a756910bf2..849ef1c4c2c 100644
---
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java
+++
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java
@@ -30,8 +30,8 @@ import org.apache.druid.catalog.model.table.TableBuilder;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.apache.druid.testing.utils.DataLoaderHelper;
import org.apache.druid.testing.utils.MsqTestQueryHelper;
import org.apache.druid.testsEx.cluster.CatalogClient;
diff --git
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java
index e075462d0bb..fa5489dca80 100644
---
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java
+++
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java
@@ -27,8 +27,8 @@ import org.apache.druid.catalog.model.TableMetadata;
import org.apache.druid.catalog.model.table.DatasourceDefn;
import org.apache.druid.catalog.model.table.TableBuilder;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.apache.druid.testing.utils.MsqTestQueryHelper;
import org.apache.druid.testsEx.categories.Catalog;
import org.apache.druid.testsEx.cluster.CatalogClient;
diff --git
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java
index b0dee9e713e..8fb325b1c65 100644
---
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java
+++
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java
@@ -24,8 +24,8 @@ import com.google.inject.Inject;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.msq.exec.ClusterStatisticsMergeMode;
import org.apache.druid.msq.util.MultiStageQueryContext;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
import org.apache.druid.testing.utils.DataLoaderHelper;
import org.apache.druid.testing.utils.MsqTestQueryHelper;
diff --git
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java
index 13c3fdc3846..5cc405045fd 100644
---
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java
+++
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java
@@ -26,7 +26,7 @@ import org.apache.druid.java.util.common.Pair;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.msq.util.MultiStageQueryContext;
-import org.apache.druid.sql.http.SqlTaskStatus;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
import org.apache.druid.testing.utils.DataLoaderHelper;
import org.apache.druid.testing.utils.ITRetryUtil;
diff --git
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java
index 3cdc57c37bf..d77d5dfe2c9 100644
---
a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java
+++
b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java
@@ -29,7 +29,7 @@ import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.msq.indexing.report.MSQResultsReport;
import org.apache.druid.msq.indexing.report.MSQTaskReport;
import org.apache.druid.msq.indexing.report.MSQTaskReportPayload;
-import org.apache.druid.sql.http.SqlTaskStatus;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.storage.local.LocalFileExportStorageProvider;
import org.apache.druid.testing.clients.CoordinatorResourceTestClient;
import org.apache.druid.testing.utils.DataLoaderHelper;
diff --git
a/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java
b/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java
index 2a4d04f42db..c4a70a475e5 100644
---
a/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java
+++
b/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java
@@ -37,8 +37,8 @@ import org.apache.druid.msq.guice.MSQIndexingModule;
import org.apache.druid.msq.indexing.report.MSQResultsReport;
import org.apache.druid.msq.indexing.report.MSQTaskReport;
import org.apache.druid.msq.indexing.report.MSQTaskReportPayload;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.apache.druid.testing.IntegrationTestingConfig;
import org.apache.druid.testing.clients.OverlordResourceTestClient;
import org.apache.druid.testing.clients.SqlResourceTestClient;
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java
b/processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java
similarity index 99%
rename from
sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java
rename to
processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java
index 533de7d58f2..5c5a4735606 100644
---
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java
+++
b/processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.calcite.planner;
+package org.apache.druid.query.explain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
diff --git a/sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java
b/processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java
similarity index 97%
rename from sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java
rename to
processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java
index 68defc4b2a4..5e19aef7758 100644
--- a/sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java
+++ b/processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.http;
+package org.apache.druid.query.explain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import org.apache.druid.sql.calcite.planner.ExplainAttributes;
import java.io.IOException;
import java.util.Objects;
diff --git
a/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java
b/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java
new file mode 100644
index 00000000000..cc562034e93
--- /dev/null
+++
b/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.query.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+/**
+ * Client representation of {@link org.apache.druid.sql.http.SqlParameter}.
This is effectively a lightweight POJO class
+ * for use by clients that excludes Calcite dependencies and server-side logic
from the Broker.
+ */
+public class ClientSqlParameter
+{
+ @JsonProperty
+ private final String type;
+
+ @JsonProperty
+ private final Object value;
+
+ @JsonCreator
+ public ClientSqlParameter(
+ @JsonProperty("type") String type,
+ @JsonProperty("value") Object value
+ )
+ {
+ this.type = type;
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ClientSqlParameter that = (ClientSqlParameter) o;
+ return Objects.equals(type, that.type) && Objects.equals(value,
that.value);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(type, value);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ClientSqlParameter{" +
+ "type='" + type + '\'' +
+ ", value=" + value +
+ '}';
+ }
+}
diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java
similarity index 50%
copy from sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
copy to processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java
index 1364332aaa1..3b3a2a23980 100644
--- a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
+++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java
@@ -17,139 +17,98 @@
* under the License.
*/
-package org.apache.druid.sql.http;
+package org.apache.druid.query.http;
import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import org.apache.calcite.avatica.remote.TypedValue;
-import org.apache.druid.java.util.common.ISE;
-import org.apache.druid.query.QueryContext;
-
-import javax.annotation.Nullable;
+
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
-public class SqlQuery
+/**
+ * Client representation of {@link org.apache.druid.sql.http.SqlQuery}. This
is effectively a lightweight POJO class for
+ * use by clients such as {@link org.apache.druid.client.broker.BrokerClient}
that doesn't bring in any of the
+ * Calcite dependencies and server-side logic from the Broker.
+ */
+public class ClientSqlQuery
{
- public static List<TypedValue> getParameterList(List<SqlParameter>
parameters)
- {
- return parameters.stream()
- // null params are not good!
- // we pass them to the planner, so that it can generate a
proper error message.
- // see SqlParameterizerShuttle and
RelParameterizerShuttle.
- .map(p -> p == null ? null : p.getTypedValue())
- .collect(Collectors.toList());
- }
-
+ @JsonProperty
private final String query;
- private final ResultFormat resultFormat;
+
+ @JsonProperty
+ private final String resultFormat;
+
+ @JsonProperty
private final boolean header;
+
+ @JsonProperty
private final boolean typesHeader;
+
+ @JsonProperty
private final boolean sqlTypesHeader;
+
+ @JsonProperty
private final Map<String, Object> context;
- private final List<SqlParameter> parameters;
+
+ @JsonProperty
+ private final List<ClientSqlParameter> parameters;
@JsonCreator
- public SqlQuery(
+ public ClientSqlQuery(
@JsonProperty("query") final String query,
- @JsonProperty("resultFormat") @Nullable final ResultFormat resultFormat,
+ @JsonProperty("resultFormat") final String resultFormat,
@JsonProperty("header") final boolean header,
@JsonProperty("typesHeader") final boolean typesHeader,
@JsonProperty("sqlTypesHeader") final boolean sqlTypesHeader,
- @JsonProperty("context") @Nullable final Map<String, Object> context,
- @JsonProperty("parameters") @Nullable final List<SqlParameter> parameters
+ @JsonProperty("context") final Map<String, Object> context,
+ @JsonProperty("parameters") final List<ClientSqlParameter> parameters
)
{
- this.query = Preconditions.checkNotNull(query, "query");
- this.resultFormat = resultFormat == null ?
ResultFormat.DEFAULT_RESULT_FORMAT : resultFormat;
+ this.query = query;
+ this.resultFormat = resultFormat;
this.header = header;
this.typesHeader = typesHeader;
this.sqlTypesHeader = sqlTypesHeader;
- this.context = context == null ? ImmutableMap.of() : context;
- this.parameters = parameters == null ? ImmutableList.of() : parameters;
-
- if (typesHeader && !header) {
- throw new ISE("Cannot include 'typesHeader' without 'header'");
- }
-
- if (sqlTypesHeader && !header) {
- throw new ISE("Cannot include 'sqlTypesHeader' without 'header'");
- }
+ this.context = context;
+ this.parameters = parameters;
}
- public SqlQuery withOverridenContext(Map<String, Object> overridenContext)
- {
- return new SqlQuery(
- getQuery(),
- getResultFormat(),
- includeHeader(),
- includeTypesHeader(),
- includeSqlTypesHeader(),
- overridenContext,
- getParameters()
- );
- }
-
- @JsonProperty
public String getQuery()
{
return query;
}
- @JsonProperty
- public ResultFormat getResultFormat()
+ public String getResultFormat()
{
return resultFormat;
}
- @JsonProperty("header")
- @JsonInclude(JsonInclude.Include.NON_DEFAULT)
- public boolean includeHeader()
+ public boolean isHeader()
{
return header;
}
- @JsonProperty("typesHeader")
- @JsonInclude(JsonInclude.Include.NON_DEFAULT)
- public boolean includeTypesHeader()
+ public boolean isTypesHeader()
{
return typesHeader;
}
- @JsonProperty("sqlTypesHeader")
- @JsonInclude(JsonInclude.Include.NON_DEFAULT)
- public boolean includeSqlTypesHeader()
+ public boolean isSqlTypesHeader()
{
return sqlTypesHeader;
}
- @JsonProperty
public Map<String, Object> getContext()
{
return context;
}
- public QueryContext queryContext()
- {
- return QueryContext.of(context);
- }
-
- @JsonProperty
- public List<SqlParameter> getParameters()
+ public List<ClientSqlParameter> getParameters()
{
return parameters;
}
- public List<TypedValue> getParameterList()
- {
- return getParameterList(parameters);
- }
@Override
public boolean equals(final Object o)
@@ -160,12 +119,12 @@ public class SqlQuery
if (o == null || getClass() != o.getClass()) {
return false;
}
- final SqlQuery sqlQuery = (SqlQuery) o;
+ final ClientSqlQuery sqlQuery = (ClientSqlQuery) o;
return header == sqlQuery.header &&
typesHeader == sqlQuery.typesHeader &&
sqlTypesHeader == sqlQuery.sqlTypesHeader &&
Objects.equals(query, sqlQuery.query) &&
- resultFormat == sqlQuery.resultFormat &&
+ Objects.equals(resultFormat, sqlQuery.resultFormat) &&
Objects.equals(context, sqlQuery.context) &&
Objects.equals(parameters, sqlQuery.parameters);
}
@@ -179,7 +138,7 @@ public class SqlQuery
@Override
public String toString()
{
- return "SqlQuery{" +
+ return "ClientSqlQuery{" +
"query='" + query + '\'' +
", resultFormat=" + resultFormat +
", header=" + header +
diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java
b/processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java
similarity index 98%
rename from sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java
rename to
processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java
index 765891ec20a..557cc5a7db0 100644
--- a/sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java
+++ b/processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.http;
+package org.apache.druid.query.http;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java
b/processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java
similarity index 98%
rename from
sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java
rename to
processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java
index d203dd34002..affaf6e3ddf 100644
---
a/sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java
+++
b/processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.calcite.planner;
+package org.apache.druid.query.explain;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.druid.error.DruidException;
@@ -38,7 +38,7 @@ public class ExplainAttributesTest
public void testGetters()
{
final ExplainAttributes selectAttributes = new ExplainAttributes("SELECT",
null, null, null, null);
- Assert.assertEquals("SELECT", selectAttributes.getStatementType());
+ assertEquals("SELECT", selectAttributes.getStatementType());
Assert.assertNull(selectAttributes.getTargetDataSource());
Assert.assertNull(selectAttributes.getPartitionedBy());
Assert.assertNull(selectAttributes.getClusteredBy());
diff --git a/sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java
b/processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java
similarity index 98%
rename from sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java
rename to
processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java
index e3385fc5f51..7ff56b7c6fd 100644
--- a/sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java
+++
b/processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.http;
+package org.apache.druid.query.explain;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableMap;
import org.apache.druid.error.DruidException;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.granularity.Granularities;
-import org.apache.druid.sql.calcite.planner.ExplainAttributes;
import org.junit.Test;
import java.util.List;
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java
similarity index 50%
copy from sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
copy to
processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java
index f9c083864f3..10379b3146a 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
+++
b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java
@@ -17,43 +17,46 @@
* under the License.
*/
-package org.apache.druid.sql.calcite.http;
+package org.apache.druid.query.http;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import nl.jqno.equalsverifier.EqualsVerifier;
-import org.apache.calcite.avatica.SqlType;
-import org.apache.druid.segment.TestHelper;
-import org.apache.druid.sql.calcite.util.CalciteTestBase;
-import org.apache.druid.sql.http.ResultFormat;
-import org.apache.druid.sql.http.SqlParameter;
-import org.apache.druid.sql.http.SqlQuery;
+import org.apache.druid.jackson.DefaultObjectMapper;
import org.junit.Assert;
-import org.junit.jupiter.api.Test;
+import org.junit.Test;
-public class SqlQueryTest extends CalciteTestBase
+public class ClientSqlQueryTest
{
@Test
- public void testSerde() throws Exception
+ public void testSerde() throws JsonProcessingException
{
- final ObjectMapper jsonMapper = TestHelper.makeJsonMapper();
- final SqlQuery query = new SqlQuery(
- "SELECT ?",
- ResultFormat.ARRAY,
+ final ObjectMapper jsonMapper = new DefaultObjectMapper();
+ final ClientSqlQuery query = new ClientSqlQuery(
+ "SELECT 1",
+ "array",
true,
true,
true,
- ImmutableMap.of("useCache", false),
- ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1))
+ null,
+ null
);
- Assert.assertEquals(query,
jsonMapper.readValue(jsonMapper.writeValueAsString(query), SqlQuery.class));
+ Assert.assertEquals(query,
jsonMapper.readValue(jsonMapper.writeValueAsString(query),
ClientSqlQuery.class));
}
@Test
- public void testEquals()
+ public void testSerdeWithParameters() throws JsonProcessingException
{
-
EqualsVerifier.forClass(SqlQuery.class).withNonnullFields("query").usingGetClass().verify();
-
EqualsVerifier.forClass(SqlParameter.class).withNonnullFields("type").usingGetClass().verify();
+ final ObjectMapper jsonMapper = new DefaultObjectMapper();
+ final ClientSqlQuery query = new ClientSqlQuery(
+ "SELECT 1",
+ "array",
+ true,
+ true,
+ true,
+ null,
+ ImmutableList.of(new ClientSqlParameter("ARRAY",
ImmutableList.of(-25.7, 20.2, 36.85)))
+ );
+ Assert.assertEquals(query,
jsonMapper.readValue(jsonMapper.writeValueAsString(query),
ClientSqlQuery.class));
}
}
diff --git a/sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java
b/processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java
similarity index 98%
rename from sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java
rename to
processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java
index c73e8d3cddb..c587f44fdcc 100644
--- a/sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java
+++
b/processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.http;
+package org.apache.druid.query.http;
import com.fasterxml.jackson.databind.ObjectMapper;
import nl.jqno.equalsverifier.EqualsVerifier;
diff --git a/sql/src/main/java/org/apache/druid/sql/client/Broker.java
b/server/src/main/java/org/apache/druid/client/broker/Broker.java
similarity index 96%
rename from sql/src/main/java/org/apache/druid/sql/client/Broker.java
rename to server/src/main/java/org/apache/druid/client/broker/Broker.java
index fb20c5166c8..ac47c66a7cf 100644
--- a/sql/src/main/java/org/apache/druid/sql/client/Broker.java
+++ b/server/src/main/java/org/apache/druid/client/broker/Broker.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.client;
+package org.apache.druid.client.broker;
import com.google.inject.BindingAnnotation;
diff --git a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java
b/server/src/main/java/org/apache/druid/client/broker/BrokerClient.java
similarity index 82%
rename from sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java
rename to server/src/main/java/org/apache/druid/client/broker/BrokerClient.java
index 14cbbb7bff6..611e6399ee6 100644
--- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java
+++ b/server/src/main/java/org/apache/druid/client/broker/BrokerClient.java
@@ -17,12 +17,12 @@
* under the License.
*/
-package org.apache.druid.sql.client;
+package org.apache.druid.client.broker;
import com.google.common.util.concurrent.ListenableFuture;
-import org.apache.druid.sql.http.ExplainPlan;
-import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
+import org.apache.druid.query.explain.ExplainPlan;
+import org.apache.druid.query.http.ClientSqlQuery;
+import org.apache.druid.query.http.SqlTaskStatus;
import java.util.List;
@@ -40,12 +40,12 @@ public interface BrokerClient
/**
* Submit the given {@code sqlQuery} to the Broker's SQL task endpoint.
*/
- ListenableFuture<SqlTaskStatus> submitSqlTask(SqlQuery sqlQuery);
+ ListenableFuture<SqlTaskStatus> submitSqlTask(ClientSqlQuery sqlQuery);
/**
* Fetches the explain plan for the given {@code sqlQuery} from the Broker's
SQL task endpoint.
*
* @param sqlQuery the SQL query for which the {@code EXPLAIN PLAN FOR}
information is to be fetched
*/
- ListenableFuture<List<ExplainPlan>> fetchExplainPlan(SqlQuery sqlQuery);
+ ListenableFuture<List<ExplainPlan>> fetchExplainPlan(ClientSqlQuery
sqlQuery);
}
diff --git
a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java
b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java
similarity index 87%
rename from sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java
rename to
server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java
index b3e064341e6..012aea74618 100644
--- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java
+++ b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.druid.sql.client;
+package org.apache.druid.client.broker;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -26,11 +26,11 @@ import org.apache.druid.common.guava.FutureUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.jackson.JacksonUtils;
import
org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.query.explain.ExplainPlan;
+import org.apache.druid.query.http.ClientSqlQuery;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.rpc.RequestBuilder;
import org.apache.druid.rpc.ServiceClient;
-import org.apache.druid.sql.http.ExplainPlan;
-import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.jboss.netty.handler.codec.http.HttpMethod;
import java.util.List;
@@ -47,7 +47,7 @@ public class BrokerClientImpl implements BrokerClient
}
@Override
- public ListenableFuture<SqlTaskStatus> submitSqlTask(final SqlQuery sqlQuery)
+ public ListenableFuture<SqlTaskStatus> submitSqlTask(final ClientSqlQuery
sqlQuery)
{
return FutureUtils.transform(
client.asyncRequest(
@@ -60,9 +60,9 @@ public class BrokerClientImpl implements BrokerClient
}
@Override
- public ListenableFuture<List<ExplainPlan>> fetchExplainPlan(final SqlQuery
sqlQuery)
+ public ListenableFuture<List<ExplainPlan>> fetchExplainPlan(final
ClientSqlQuery sqlQuery)
{
- final SqlQuery explainSqlQuery = new SqlQuery(
+ final ClientSqlQuery explainSqlQuery = new ClientSqlQuery(
StringUtils.format("EXPLAIN PLAN FOR %s", sqlQuery.getQuery()),
null,
false,
diff --git
a/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java
b/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java
index 94dfeb29d95..a0d9a5e3725 100644
--- a/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java
+++ b/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java
@@ -22,6 +22,9 @@ package org.apache.druid.rpc.guice;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Binder;
import com.google.inject.Provides;
+import org.apache.druid.client.broker.Broker;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
import org.apache.druid.client.coordinator.Coordinator;
import org.apache.druid.client.coordinator.CoordinatorClient;
import org.apache.druid.client.coordinator.CoordinatorClientImpl;
@@ -47,7 +50,7 @@ import java.util.concurrent.ScheduledExecutorService;
public class ServiceClientModule implements DruidModule
{
- public static final int CLIENT_MAX_ATTEMPTS = 6;
+ private static final int CLIENT_MAX_ATTEMPTS = 6;
private static final int CONNECT_EXEC_THREADS = 4;
@Override
@@ -116,6 +119,32 @@ public class ServiceClientModule implements DruidModule
);
}
+ @Provides
+ @ManageLifecycle
+ @Broker
+ public ServiceLocator makeBrokerServiceLocator(final
DruidNodeDiscoveryProvider discoveryProvider)
+ {
+ return new DiscoveryServiceLocator(discoveryProvider, NodeRole.BROKER);
+ }
+
+ @Provides
+ @LazySingleton
+ public BrokerClient makeBrokerClient(
+ @Json final ObjectMapper jsonMapper,
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ @Broker final ServiceLocator serviceLocator
+ )
+ {
+ return new BrokerClientImpl(
+ clientFactory.makeClient(
+ NodeRole.BROKER.getJsonName(),
+ serviceLocator,
+
StandardRetryPolicy.builder().maxAttempts(ServiceClientModule.CLIENT_MAX_ATTEMPTS).build()
+ ),
+ jsonMapper
+ );
+ }
+
public static ServiceClientFactory makeServiceClientFactory(@EscalatedGlobal
final HttpClient httpClient)
{
final ScheduledExecutorService connectExec =
diff --git
a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java
b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java
similarity index 88%
rename from
sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java
rename to
server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java
index 51d66f03816..90d1b49534d 100644
--- a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java
+++
b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java
@@ -17,24 +17,21 @@
* under the License.
*/
-package org.apache.druid.sql.client;
+package org.apache.druid.client.broker;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import org.apache.calcite.avatica.SqlType;
import org.apache.druid.indexer.TaskState;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.query.explain.ExplainAttributes;
+import org.apache.druid.query.explain.ExplainPlan;
+import org.apache.druid.query.http.ClientSqlQuery;
+import org.apache.druid.query.http.SqlTaskStatus;
import org.apache.druid.rpc.MockServiceClient;
import org.apache.druid.rpc.RequestBuilder;
-import org.apache.druid.sql.calcite.planner.ExplainAttributes;
-import org.apache.druid.sql.http.ExplainPlan;
-import org.apache.druid.sql.http.ResultFormat;
-import org.apache.druid.sql.http.SqlParameter;
-import org.apache.druid.sql.http.SqlQuery;
-import org.apache.druid.sql.http.SqlTaskStatus;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.junit.After;
@@ -43,7 +40,6 @@ import org.junit.Test;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-
import java.util.List;
import java.util.Map;
@@ -72,14 +68,14 @@ public class BrokerClientImplTest
@Test
public void testSubmitSqlTask() throws Exception
{
- final SqlQuery query = new SqlQuery(
+ final ClientSqlQuery query = new ClientSqlQuery(
"REPLACE INTO foo OVERWRITE ALL SELECT * FROM bar PARTITIONED BY ALL",
- ResultFormat.ARRAY,
+ null,
true,
true,
true,
ImmutableMap.of("useCache", false),
- ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1))
+ null
);
final SqlTaskStatus taskStatus = new SqlTaskStatus("taskId1",
TaskState.RUNNING, null);
@@ -97,16 +93,16 @@ public class BrokerClientImplTest
@Test
public void testFetchExplainPlan() throws Exception
{
- final SqlQuery query = new SqlQuery(
+ final ClientSqlQuery query = new ClientSqlQuery(
"REPLACE INTO foo OVERWRITE ALL SELECT * FROM bar PARTITIONED BY ALL",
- ResultFormat.ARRAY,
+ null,
true,
true,
true,
ImmutableMap.of("useCache", false),
- ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1))
+ null
);
- final SqlQuery explainQuery = new SqlQuery(
+ final ClientSqlQuery explainQuery = new ClientSqlQuery(
StringUtils.format("EXPLAIN PLAN FOR %s", query.getQuery()),
null,
false,
diff --git
a/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java
b/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java
index 5d8a07d20a8..94647fe64ae 100644
---
a/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java
+++
b/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java
@@ -22,6 +22,7 @@ package org.apache.druid.rpc.guice;
import com.google.common.collect.ImmutableList;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import org.apache.druid.client.broker.BrokerClient;
import org.apache.druid.client.coordinator.CoordinatorClient;
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
import org.apache.druid.guice.DruidGuiceExtensions;
@@ -96,4 +97,10 @@ public class ServiceClientModuleTest
{
assertNotNull(injector.getInstance(CoordinatorClient.class));
}
+
+ @Test
+ public void testGetBrokerClient()
+ {
+ assertNotNull(injector.getInstance(BrokerClient.class));
+ }
}
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
index 3569864cae7..49a943aded7 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java
@@ -37,6 +37,7 @@ import org.apache.druid.common.utils.IdUtils;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.InvalidSqlInput;
import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.query.explain.ExplainAttributes;
import org.apache.druid.server.security.Action;
import org.apache.druid.server.security.Resource;
import org.apache.druid.server.security.ResourceAction;
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java
index c02cb3cd8bd..51be1f93502 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java
@@ -39,6 +39,7 @@ import org.apache.druid.math.expr.Expr;
import org.apache.druid.math.expr.ExprMacroTable;
import org.apache.druid.query.QueryContext;
import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.explain.ExplainAttributes;
import org.apache.druid.query.filter.InDimFilter;
import org.apache.druid.query.filter.TypedInFilter;
import org.apache.druid.query.lookup.LookupExtractor;
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
index 67cc7f2f44c..8481efdbcbd 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
@@ -63,6 +63,7 @@ import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.java.util.emitter.EmittingLogger;
import org.apache.druid.query.Query;
import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.explain.ExplainAttributes;
import org.apache.druid.server.QueryResponse;
import org.apache.druid.server.security.Action;
import org.apache.druid.server.security.Resource;
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
index 267feae1f0f..393363587f7 100644
---
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
+++
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java
@@ -22,6 +22,7 @@ package org.apache.druid.sql.calcite.planner;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.druid.query.QueryContext;
+import org.apache.druid.query.explain.ExplainAttributes;
import org.apache.druid.server.security.ResourceAction;
import org.apache.druid.sql.calcite.run.SqlEngine;
import org.joda.time.DateTimeZone;
diff --git
a/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java
b/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java
deleted file mode 100644
index 05e022f8310..00000000000
--- a/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.druid.sql.guice;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.inject.Binder;
-import com.google.inject.Provides;
-import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
-import org.apache.druid.discovery.NodeRole;
-import org.apache.druid.guice.LazySingleton;
-import org.apache.druid.guice.ManageLifecycle;
-import org.apache.druid.guice.annotations.EscalatedGlobal;
-import org.apache.druid.guice.annotations.Json;
-import org.apache.druid.initialization.DruidModule;
-import org.apache.druid.java.util.http.client.HttpClient;
-import org.apache.druid.rpc.DiscoveryServiceLocator;
-import org.apache.druid.rpc.ServiceClientFactory;
-import org.apache.druid.rpc.ServiceLocator;
-import org.apache.druid.rpc.StandardRetryPolicy;
-import org.apache.druid.rpc.guice.ServiceClientModule;
-import org.apache.druid.sql.client.Broker;
-import org.apache.druid.sql.client.BrokerClient;
-import org.apache.druid.sql.client.BrokerClientImpl;
-
-/**
- * Module that processes can install if they require a {@link BrokerClient}.
- * <p>
- * Similar to {@link ServiceClientModule}, but since {@link BrokerClient}
depends
- * on classes from the sql module, this is a separate module within the sql
package.
- * </p>
- */
-public class BrokerServiceModule implements DruidModule
-{
- @Override
- public void configure(Binder binder)
- {
- // Nothing to do.
- }
-
- @Provides
- @LazySingleton
- @EscalatedGlobal
- public ServiceClientFactory getServiceClientFactory(@EscalatedGlobal final
HttpClient httpClient)
- {
- return ServiceClientModule.makeServiceClientFactory(httpClient);
- }
-
- @Provides
- @ManageLifecycle
- @Broker
- public ServiceLocator makeBrokerServiceLocator(final
DruidNodeDiscoveryProvider discoveryProvider)
- {
- return new DiscoveryServiceLocator(discoveryProvider, NodeRole.BROKER);
- }
-
- @Provides
- @LazySingleton
- public BrokerClient makeBrokerClient(
- @Json final ObjectMapper jsonMapper,
- @EscalatedGlobal final ServiceClientFactory clientFactory,
- @Broker final ServiceLocator serviceLocator
- )
- {
- return new BrokerClientImpl(
- clientFactory.makeClient(
- NodeRole.BROKER.getJsonName(),
- serviceLocator,
-
StandardRetryPolicy.builder().maxAttempts(ServiceClientModule.CLIENT_MAX_ATTEMPTS).build()
- ),
- jsonMapper
- );
- }
-}
-
diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java
b/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java
index 7e8e190d3ef..79c3a145fd6 100644
--- a/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java
+++ b/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java
@@ -34,6 +34,11 @@ import javax.annotation.Nullable;
import java.sql.Date;
import java.util.Objects;
+/**
+ * See {@link org.apache.druid.query.http.ClientSqlParameter} for the
equivalent POJO class used on the client side.
+ * Note: The field {@link #type} relies on a Calcite data type, which prevents
this class from being moved
+ * to the processing module for reuse.
+ */
public class SqlParameter
{
private final SqlType type;
diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
b/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
index 1364332aaa1..7b54ae39fad 100644
--- a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
+++ b/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java
@@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableMap;
import org.apache.calcite.avatica.remote.TypedValue;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.query.QueryContext;
+import org.apache.druid.query.http.ClientSqlQuery;
import javax.annotation.Nullable;
import java.util.List;
@@ -35,6 +36,11 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
+/**
+ * See {@link ClientSqlQuery} for the equivalent POJO class used on the client
side to interact with the Broker.
+ * Note: The fields {@link #resultFormat} and {@link #parameters} rely on
Calcite data types,
+ * preventing this class from being moved to the processing module for reuse.
+ */
public class SqlQuery
{
public static List<TypedValue> getParameterList(List<SqlParameter>
parameters)
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
index f9c083864f3..fc62cb05fba 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java
@@ -19,11 +19,14 @@
package org.apache.druid.sql.calcite.http;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.calcite.avatica.SqlType;
+import org.apache.druid.query.http.ClientSqlParameter;
+import org.apache.druid.query.http.ClientSqlQuery;
import org.apache.druid.segment.TestHelper;
import org.apache.druid.sql.calcite.util.CalciteTestBase;
import org.apache.druid.sql.http.ResultFormat;
@@ -34,10 +37,11 @@ import org.junit.jupiter.api.Test;
public class SqlQueryTest extends CalciteTestBase
{
+ private static final ObjectMapper JSON_MAPPER = TestHelper.makeJsonMapper();
+
@Test
public void testSerde() throws Exception
{
- final ObjectMapper jsonMapper = TestHelper.makeJsonMapper();
final SqlQuery query = new SqlQuery(
"SELECT ?",
ResultFormat.ARRAY,
@@ -47,7 +51,63 @@ public class SqlQueryTest extends CalciteTestBase
ImmutableMap.of("useCache", false),
ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1))
);
- Assert.assertEquals(query,
jsonMapper.readValue(jsonMapper.writeValueAsString(query), SqlQuery.class));
+ Assert.assertEquals(query,
JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(query), SqlQuery.class));
+ }
+
+ @Test
+ public void testClientSqlQueryToSqlQueryConversion() throws
JsonProcessingException
+ {
+ final ClientSqlQuery givenClientSqlQuery = new ClientSqlQuery(
+ "SELECT ?",
+ "array",
+ true,
+ true,
+ true,
+ ImmutableMap.of("useCache", false),
+ null
+ );
+
+ final SqlQuery expectedSqlQuery = new SqlQuery(
+ "SELECT ?",
+ ResultFormat.ARRAY,
+ true,
+ true,
+ true,
+ ImmutableMap.of("useCache", false),
+ null
+ );
+
+ final SqlQuery observedSqlQuery =
+
JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(givenClientSqlQuery),
SqlQuery.class);
+ Assert.assertEquals(expectedSqlQuery, observedSqlQuery);
+ }
+
+ @Test
+ public void testClientSqlQueryToSqlQueryConversion2() throws
JsonProcessingException
+ {
+ final ClientSqlQuery givenClientSqlQuery = new ClientSqlQuery(
+ "SELECT ?",
+ "arrayLines",
+ false,
+ false,
+ false,
+ ImmutableMap.of("useCache", false),
+ ImmutableList.of(new ClientSqlParameter("INTEGER", 1), new
ClientSqlParameter("VARCHAR", "foo"))
+ );
+
+ final SqlQuery expectedSqlQuery = new SqlQuery(
+ "SELECT ?",
+ ResultFormat.ARRAYLINES,
+ false,
+ false,
+ false,
+ ImmutableMap.of("useCache", false),
+ ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1), new
SqlParameter(SqlType.VARCHAR, "foo"))
+ );
+
+ final SqlQuery observedSqlQuery =
+
JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(givenClientSqlQuery),
SqlQuery.class);
+ Assert.assertEquals(expectedSqlQuery, observedSqlQuery);
}
@Test
diff --git
a/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java
b/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java
deleted file mode 100644
index 9b59ad86733..00000000000
--- a/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.druid.sql.guice;
-
-import com.google.common.collect.ImmutableList;
-import com.google.inject.ConfigurationException;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.druid.client.coordinator.CoordinatorClient;
-import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
-import org.apache.druid.guice.DruidGuiceExtensions;
-import org.apache.druid.guice.LifecycleModule;
-import org.apache.druid.guice.annotations.EscalatedGlobal;
-import org.apache.druid.jackson.JacksonModule;
-import org.apache.druid.java.util.http.client.HttpClient;
-import org.apache.druid.rpc.ServiceClientFactory;
-import org.apache.druid.rpc.ServiceLocator;
-import org.apache.druid.rpc.indexing.OverlordClient;
-import org.apache.druid.sql.client.BrokerClient;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-
-public class BrokerServiceModuleTest
-{
- private Injector injector;
-
- @Rule
- public MockitoRule mockitoRule = MockitoJUnit.rule();
-
- @Mock
- private HttpClient httpClient;
-
- @Mock
- private DruidNodeDiscoveryProvider discoveryProvider;
-
- @Mock
- private ServiceLocator serviceLocator;
-
- @Mock
- private ServiceClientFactory serviceClientFactory;
-
- @Before
- public void setUp()
- {
- injector = Guice.createInjector(
- ImmutableList.of(
- new DruidGuiceExtensions(),
- new LifecycleModule(),
- new JacksonModule(),
- new BrokerServiceModule(),
- binder -> {
-
binder.bind(HttpClient.class).annotatedWith(EscalatedGlobal.class).toInstance(httpClient);
- binder.bind(ServiceLocator.class).toInstance(serviceLocator);
-
binder.bind(DruidNodeDiscoveryProvider.class).toInstance(discoveryProvider);
-
binder.bind(ServiceClientFactory.class).toInstance(serviceClientFactory);
- }
- )
- );
- }
-
- @Test
- public void testGetServiceClientFactory()
- {
- assertNotNull(injector.getInstance(ServiceClientFactory.class));
- }
-
- @Test
- public void testGetBrokerClient()
- {
- assertNotNull(injector.getInstance(BrokerClient.class));
- }
-
- @Test
- public void testGetCoordinatorClient()
- {
- assertThrows(
- ConfigurationException.class,
- () -> injector.getInstance(CoordinatorClient.class)
- );
- }
-
- @Test
- public void testGetOverlordClient()
- {
- assertThrows(
- ConfigurationException.class,
- () -> injector.getInstance(OverlordClient.class)
- );
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]