From 9bfeafc83e6da3954a512cd1e92deb68fbdf3509 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:07:32 -0600 Subject: [PATCH 01/12] Move ExplainPlan and ExplainPlanAttributes classes to processing module for reuse. --- .../org/apache/druid/query/explain}/ExplainAttributes.java | 2 +- .../java/org/apache/druid/query/explain}/ExplainPlan.java | 3 +-- .../apache/druid/query/explain}/ExplainAttributesTest.java | 4 ++-- .../java/org/apache/druid/query/explain}/ExplainPlanTest.java | 3 +-- .../org/apache/druid/sql/calcite/planner/IngestHandler.java | 1 + .../org/apache/druid/sql/calcite/planner/PlannerContext.java | 1 + .../org/apache/druid/sql/calcite/planner/QueryHandler.java | 1 + .../apache/druid/sql/calcite/planner/SqlStatementHandler.java | 1 + .../main/java/org/apache/druid/sql/client/BrokerClient.java | 2 +- .../java/org/apache/druid/sql/client/BrokerClientImpl.java | 2 +- .../org/apache/druid/sql/client/BrokerClientImplTest.java | 4 ++-- 11 files changed, 13 insertions(+), 11 deletions(-) rename {sql/src/main/java/org/apache/druid/sql/calcite/planner => processing/src/main/java/org/apache/druid/query/explain}/ExplainAttributes.java (99%) rename {sql/src/main/java/org/apache/druid/sql/http => processing/src/main/java/org/apache/druid/query/explain}/ExplainPlan.java (97%) rename {sql/src/test/java/org/apache/druid/sql/calcite/planner => processing/src/test/java/org/apache/druid/query/explain}/ExplainAttributesTest.java (98%) rename {sql/src/test/java/org/apache/druid/sql/http => processing/src/test/java/org/apache/druid/query/explain}/ExplainPlanTest.java (98%) 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 533de7d58f2f..5c5a47356062 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 68defc4b2a4d..5e19aef7758d 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.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/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 d203dd340028..affaf6e3ddfb 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 e3385fc5f518..7ff56b7c6fd9 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 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/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java index 3569864cae78..49a943aded76 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.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 c02cb3cd8bd7..51be1f93502a 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.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 67cc7f2f44c1..8481efdbcbd1 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.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 267feae1f0f3..393363587f7d 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 @@ 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/client/BrokerClient.java b/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java index 14cbbb7bff6a..da28a126db47 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java +++ b/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java @@ -20,7 +20,7 @@ package org.apache.druid.sql.client; import com.google.common.util.concurrent.ListenableFuture; -import org.apache.druid.sql.http.ExplainPlan; +import org.apache.druid.query.explain.ExplainPlan; import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.sql.http.SqlTaskStatus; diff --git a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java b/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java index b3e064341e63..18cef8ccde7e 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java +++ b/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java @@ -28,7 +28,7 @@ import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler; import org.apache.druid.rpc.RequestBuilder; import org.apache.druid.rpc.ServiceClient; -import org.apache.druid.sql.http.ExplainPlan; +import org.apache.druid.query.explain.ExplainPlan; import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.sql.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; diff --git a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java b/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java index 51d66f03816d..1a4ca3a055f3 100644 --- a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java +++ b/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java @@ -29,8 +29,8 @@ import org.apache.druid.java.util.common.granularity.Granularities; 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.query.explain.ExplainAttributes; +import org.apache.druid.query.explain.ExplainPlan; import org.apache.druid.sql.http.ResultFormat; import org.apache.druid.sql.http.SqlParameter; import org.apache.druid.sql.http.SqlQuery; From 5429f4f849ea43188d2e51dc2fa659a6ecf3bdc8 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:23:01 -0600 Subject: [PATCH 02/12] Move SqlTaskStatus to processing for better reuse. --- .../org/apache/druid/msq/sql/resources/SqlTaskResource.java | 2 +- .../druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java | 2 +- .../druid/testsEx/catalog/ITCatalogIngestErrorTest.java | 2 +- .../druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java | 2 +- .../testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java | 2 +- .../java/org/apache/druid/testsEx/msq/MultiStageQuery.java | 2 +- .../org/apache/druid/testing/utils/MsqTestQueryHelper.java | 2 +- .../main/java/org/apache/druid/query}/http/SqlTaskStatus.java | 2 +- .../java/org/apache/druid/query}/http/SqlTaskStatusTest.java | 2 +- .../main/java/org/apache/druid/sql/client/BrokerClient.java | 2 +- .../java/org/apache/druid/sql/client/BrokerClientImpl.java | 2 +- sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java | 4 ++++ .../org/apache/druid/sql/client/BrokerClientImplTest.java | 2 +- 13 files changed, 16 insertions(+), 12 deletions(-) rename {sql/src/main/java/org/apache/druid/sql => processing/src/main/java/org/apache/druid/query}/http/SqlTaskStatus.java (98%) rename {sql/src/test/java/org/apache/druid/sql => processing/src/test/java/org/apache/druid/query}/http/SqlTaskStatusTest.java (98%) 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 a07ef2c403fb..da0bfe28b652 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 @@ -47,7 +47,7 @@ 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 org.apache.druid.query.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 1a756910bf24..6fa924b8b086 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 @@ -31,7 +31,7 @@ import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.query.QueryContexts; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.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 e075462d0bb6..47c1a84656e7 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 @@ -28,7 +28,7 @@ import org.apache.druid.catalog.model.table.TableBuilder; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.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 b0dee9e713eb..353f30052042 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 @@ -25,7 +25,7 @@ import org.apache.druid.msq.exec.ClusterStatisticsMergeMode; import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.sql.http.SqlQuery; -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.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 13c3fdc38463..5cc405045fd1 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.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 3cdc57c37bfa..d77d5dfe2c99 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.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 2a4d04f42dbd..5dca52f940ea 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 @@ -38,7 +38,7 @@ import org.apache.druid.msq.indexing.report.MSQTaskReport; import org.apache.druid.msq.indexing.report.MSQTaskReportPayload; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.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/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 765891ec20a1..557cc5a7db07 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/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 c73e8d3cddbd..c587f44fdccd 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/BrokerClient.java b/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java index da28a126db47..bdf1dfc24fd7 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java +++ b/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java @@ -22,7 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture; import org.apache.druid.query.explain.ExplainPlan; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.http.SqlTaskStatus; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java b/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java index 18cef8ccde7e..3ffade7f74ef 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java +++ b/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java @@ -30,7 +30,7 @@ import org.apache.druid.rpc.ServiceClient; import org.apache.druid.query.explain.ExplainPlan; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import java.util.List; 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 1364332aaa13..b087a79ea089 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 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,9 @@ import java.util.Objects; import java.util.stream.Collectors; +/** + * @see ClientSqlQuery for the equivalent POJO class for use on the client side. + */ public class SqlQuery { public static List getParameterList(List parameters) diff --git a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java b/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java index 1a4ca3a055f3..5fa60431e60e 100644 --- a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java +++ b/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java @@ -34,7 +34,7 @@ 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.apache.druid.query.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.junit.After; From 9ac43d4de848ce1f0b61bbfc693415f019b70e6a Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:23:56 -0600 Subject: [PATCH 03/12] Add ClientSqlQuery and ClientSqlQueryTest placeholders in processing. --- .../druid/query/http/ClientSqlQuery.java | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java new file mode 100644 index 000000000000..1d474811711e --- /dev/null +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -0,0 +1,130 @@ +/* + * 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 org.apache.druid.query.QueryContext; + +import java.util.List; +import java.util.Map; + +/** + * Similar to {@link org.apache.druid.sql.http.SqlQuery}, but should be used only when interacting with the + * Broker. This is effectively a thin POJO class for use by clients without brining in any of the Calcite dependencies + * and server-side business logic. + */ +public class ClientSqlQuery +{ + @JsonProperty + private final String query; + + @JsonProperty + private final String resultFormat; + + @JsonProperty + private final boolean header; + + @JsonProperty + private final boolean typesHeader; + + @JsonProperty + private final boolean sqlTypesHeader; + + @JsonProperty + private final Map context; + + @JsonProperty + private final List parameters; + + @JsonCreator + public ClientSqlQuery( + @JsonProperty("query") final String query, + @JsonProperty("resultFormat") final String resultFormat, + @JsonProperty("header") final boolean header, + @JsonProperty("typesHeader") final boolean typesHeader, + @JsonProperty("sqlTypesHeader") final boolean sqlTypesHeader, + @JsonProperty("context") final Map context, + @JsonProperty("parameters") final List parameters + ) + { + this.query = query; + this.resultFormat = resultFormat; + this.header = header; + this.typesHeader = typesHeader; + this.sqlTypesHeader = sqlTypesHeader; + this.context = context;; + this.parameters = parameters; + } + + public String getQuery() + { + return query; + } + + public String getResultFormat() + { + return resultFormat; + } + + public boolean includeHeader() + { + return header; + } + + public boolean includeTypesHeader() + { + return typesHeader; + } + + public boolean includeSqlTypesHeader() + { + return sqlTypesHeader; + } + + public Map getContext() + { + return context; + } + + public QueryContext queryContext() + { + return QueryContext.of(context); + } + + public List getParameters() + { + return parameters; + } + + @Override + public String toString() + { + return "ClientSqlQuery{" + + "query='" + query + '\'' + + ", resultFormat=" + resultFormat + + ", header=" + header + + ", typesHeader=" + typesHeader + + ", sqlTypesHeader=" + sqlTypesHeader + + ", context=" + context + + ", parameters=" + parameters + + '}'; + } +} From a9f6725e3a601dd98a40a172b153022f4d25f876 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:32:44 -0600 Subject: [PATCH 04/12] Move Broker, BrokerClient and BrokerClientImpl to server package along with other server clients. --- .../druid/query/http/ClientSqlQuery.java | 8 +++---- .../apache/druid/client/broker}/Broker.java | 2 +- .../druid/client/broker}/BrokerClient.java | 8 +++---- .../client/broker}/BrokerClientImpl.java | 10 ++++----- .../client/broker}/BrokerClientImplTest.java | 21 ++++++++----------- .../druid/sql/guice/BrokerServiceModule.java | 6 +++--- .../sql/guice/BrokerServiceModuleTest.java | 2 +- 7 files changed, 27 insertions(+), 30 deletions(-) rename {sql/src/main/java/org/apache/druid/sql/client => server/src/main/java/org/apache/druid/client/broker}/Broker.java (96%) rename {sql/src/main/java/org/apache/druid/sql/client => server/src/main/java/org/apache/druid/client/broker}/BrokerClient.java (87%) rename {sql/src/main/java/org/apache/druid/sql/client => server/src/main/java/org/apache/druid/client/broker}/BrokerClientImpl.java (91%) rename {sql/src/test/java/org/apache/druid/sql/client => server/src/test/java/org/apache/druid/client/broker}/BrokerClientImplTest.java (91%) diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java index 1d474811711e..896600938b3f 100644 --- a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -27,9 +27,9 @@ import java.util.Map; /** - * Similar to {@link org.apache.druid.sql.http.SqlQuery}, but should be used only when interacting with the - * Broker. This is effectively a thin POJO class for use by clients without brining in any of the Calcite dependencies - * and server-side business logic. + * Client representation of {@link org.apache.druid.sql.http.SqlQuery}. This is effectively a thin 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 { @@ -70,7 +70,7 @@ public ClientSqlQuery( this.header = header; this.typesHeader = typesHeader; this.sqlTypesHeader = sqlTypesHeader; - this.context = context;; + this.context = context; this.parameters = parameters; } 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 fb20c5166c8f..ac47c66a7cf5 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 87% 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 bdf1dfc24fd7..611e6399ee69 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,11 +17,11 @@ * 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.query.explain.ExplainPlan; -import org.apache.druid.sql.http.SqlQuery; +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 submitSqlTask(SqlQuery sqlQuery); + ListenableFuture 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> fetchExplainPlan(SqlQuery sqlQuery); + ListenableFuture> 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 91% 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 3ffade7f74ef..80af4da0a83e 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,10 +26,10 @@ 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.http.ClientSqlQuery; import org.apache.druid.rpc.RequestBuilder; import org.apache.druid.rpc.ServiceClient; import org.apache.druid.query.explain.ExplainPlan; -import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.query.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; @@ -47,7 +47,7 @@ public BrokerClientImpl(final ServiceClient client, final ObjectMapper jsonMappe } @Override - public ListenableFuture submitSqlTask(final SqlQuery sqlQuery) + public ListenableFuture submitSqlTask(final ClientSqlQuery sqlQuery) { return FutureUtils.transform( client.asyncRequest( @@ -60,9 +60,9 @@ public ListenableFuture submitSqlTask(final SqlQuery sqlQuery) } @Override - public ListenableFuture> fetchExplainPlan(final SqlQuery sqlQuery) + public ListenableFuture> 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/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 91% 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 5fa60431e60e..db0f6b80a9e8 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,23 +17,20 @@ * 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.http.ClientSqlQuery; import org.apache.druid.rpc.MockServiceClient; import org.apache.druid.rpc.RequestBuilder; import org.apache.druid.query.explain.ExplainAttributes; import org.apache.druid.query.explain.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.query.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponseStatus; @@ -72,14 +69,14 @@ public void tearDown() @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 +94,16 @@ public void testSubmitSqlTask() throws Exception @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/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java b/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java index 05e022f83107..c09b03fadad5 100644 --- a/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java +++ b/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java @@ -35,9 +35,9 @@ 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; +import org.apache.druid.client.broker.Broker; +import org.apache.druid.client.broker.BrokerClient; +import org.apache.druid.client.broker.BrokerClientImpl; /** * Module that processes can install if they require a {@link BrokerClient}. 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 index 9b59ad86733e..88bd30e8ecc5 100644 --- a/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java +++ b/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java @@ -33,7 +33,7 @@ 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.apache.druid.client.broker.BrokerClient; import org.junit.Before; import org.junit.Rule; import org.junit.Test; From eaaaf7bce8a381f0c54c2fea28bb6323a3044ddd Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:48:34 -0600 Subject: [PATCH 05/12] Add simple test for ClientSqlQuery and clean up methods. --- .../druid/query/http/ClientSqlQuery.java | 55 +++++++------------ .../druid/query/http/ClientSqlQueryTest.java | 45 +++++++++++++++ 2 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java index 896600938b3f..aae5c0270ba7 100644 --- a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -21,10 +21,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.druid.query.QueryContext; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Client representation of {@link org.apache.druid.sql.http.SqlQuery}. This is effectively a thin POJO class for @@ -74,44 +74,29 @@ public ClientSqlQuery( this.parameters = parameters; } - public String getQuery() - { - return query; - } - - public String getResultFormat() - { - return resultFormat; - } - - public boolean includeHeader() - { - return header; - } - - public boolean includeTypesHeader() - { - return typesHeader; - } - - public boolean includeSqlTypesHeader() - { - return sqlTypesHeader; - } - - public Map getContext() - { - return context; - } - - public QueryContext queryContext() + @Override + public boolean equals(final Object o) { - return QueryContext.of(context); + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ClientSqlQuery sqlQuery = (ClientSqlQuery) o; + return header == sqlQuery.header && + typesHeader == sqlQuery.typesHeader && + sqlTypesHeader == sqlQuery.sqlTypesHeader && + Objects.equals(query, sqlQuery.query) && + Objects.equals(resultFormat, sqlQuery.resultFormat) && + Objects.equals(context, sqlQuery.context) && + Objects.equals(parameters, sqlQuery.parameters); } - public List getParameters() + @Override + public int hashCode() { - return parameters; + return Objects.hash(query, resultFormat, header, typesHeader, sqlTypesHeader, context, parameters); } @Override diff --git a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java new file mode 100644 index 000000000000..40b2b6c78c24 --- /dev/null +++ b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java @@ -0,0 +1,45 @@ +/* + * 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.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +public class ClientSqlQueryTest +{ + @Test + public void testSerde() throws JsonProcessingException + { + final ObjectMapper jsonMapper = new DefaultObjectMapper(); + final ClientSqlQuery query = new ClientSqlQuery( + "SELECT 1", + "array", + true, + true, + true, + null, + null + ); + Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), ClientSqlQuery.class)); + } +} \ No newline at end of file From 9cb3edf63324112e93f8708f4be5a2e29ae8fcbf Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:51:32 -0600 Subject: [PATCH 06/12] Checkstyle fixes. --- .../org/apache/druid/query/http/ClientSqlQueryTest.java | 2 +- .../org/apache/druid/client/broker/BrokerClientImpl.java | 4 ++-- .../apache/druid/client/broker/BrokerClientImplTest.java | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java index 40b2b6c78c24..6fb12ec7ada0 100644 --- a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java +++ b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java @@ -42,4 +42,4 @@ public void testSerde() throws JsonProcessingException ); Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), ClientSqlQuery.class)); } -} \ No newline at end of file +} diff --git a/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java index 80af4da0a83e..012aea746181 100644 --- a/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java +++ b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java @@ -26,11 +26,11 @@ 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.query.explain.ExplainPlan; -import org.apache.druid.query.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import java.util.List; diff --git a/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java index db0f6b80a9e8..90d1b49534d3 100644 --- a/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java +++ b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java @@ -26,12 +26,12 @@ 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.http.ClientSqlQuery; -import org.apache.druid.rpc.MockServiceClient; -import org.apache.druid.rpc.RequestBuilder; 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.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.junit.After; @@ -40,7 +40,6 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; - import java.util.List; import java.util.Map; From bd90cbc04571e10d744e47f3ee2c3cda30e7e3da Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 19:57:48 -0600 Subject: [PATCH 07/12] Add back getters as we need them. --- .../druid/query/http/ClientSqlQuery.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java index aae5c0270ba7..ebeed3dacdb9 100644 --- a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -74,6 +74,42 @@ public ClientSqlQuery( this.parameters = parameters; } + public String getQuery() + { + return query; + } + + public String getResultFormat() + { + return resultFormat; + } + + public boolean isHeader() + { + return header; + } + + public boolean isTypesHeader() + { + return typesHeader; + } + + public boolean isSqlTypesHeader() + { + return sqlTypesHeader; + } + + public Map getContext() + { + return context; + } + + public List getParameters() + { + return parameters; + } + + @Override public boolean equals(final Object o) { From bea8b3f15b281493a217d9cf280a3f8df17c000c Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 20:02:38 -0600 Subject: [PATCH 08/12] Guice provider for BrokerClient in the ServiceClientModule. Remove BrokerServiceModule. --- .../druid/rpc/guice/ServiceClientModule.java | 31 ++++- .../rpc/guice/ServiceClientModuleTest.java | 7 ++ .../druid/sql/guice/BrokerServiceModule.java | 91 -------------- .../sql/guice/BrokerServiceModuleTest.java | 114 ------------------ 4 files changed, 37 insertions(+), 206 deletions(-) delete mode 100644 sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java delete mode 100644 sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java 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 94dfeb29d957..a0d9a5e3725c 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 @@ 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 @@ 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 CoordinatorClient makeCoordinatorClient( ); } + @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/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java b/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java index 5d8a07d20a8a..94647fe64aef 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 @@ 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 void testGetCoordinatorClient() { 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/guice/BrokerServiceModule.java b/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java deleted file mode 100644 index c09b03fadad5..000000000000 --- 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.client.broker.Broker; -import org.apache.druid.client.broker.BrokerClient; -import org.apache.druid.client.broker.BrokerClientImpl; - -/** - * Module that processes can install if they require a {@link BrokerClient}. - *

- * Similar to {@link ServiceClientModule}, but since {@link BrokerClient} depends - * on classes from the sql module, this is a separate module within the sql package. - *

- */ -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/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 88bd30e8ecc5..000000000000 --- 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.client.broker.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) - ); - } -} From 0a4747d0313a077371197adfcc858be998fb77b2 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 21:40:48 -0800 Subject: [PATCH 09/12] Checkstyle fix. --- .../org/apache/druid/msq/sql/resources/SqlTaskResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 da0bfe28b652..11e39bfa1267 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.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.http.ResultFormat; import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.sql.http.SqlResource; -import org.apache.druid.query.http.SqlTaskStatus; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; From 0616081078fc3fbbe94152881133deae6c201e94 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 22:11:14 -0800 Subject: [PATCH 10/12] Review comments and add ClientSqlParameter for the equivalent SqlParamter. --- .../druid/query/http/ClientSqlParameter.java | 76 +++++++++++++++++++ .../druid/query/http/ClientSqlQuery.java | 8 +- .../druid/query/http/ClientSqlQueryTest.java | 17 +++++ .../apache/druid/sql/http/SqlParameter.java | 5 ++ .../org/apache/druid/sql/http/SqlQuery.java | 4 +- .../druid/sql/calcite/http/SqlQueryTest.java | 64 +++++++++++++++- 6 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java 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 000000000000..cc562034e93a --- /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/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java index ebeed3dacdb9..3b3a2a239806 100644 --- a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -27,7 +27,7 @@ import java.util.Objects; /** - * Client representation of {@link org.apache.druid.sql.http.SqlQuery}. This is effectively a thin POJO class for + * 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. */ @@ -52,7 +52,7 @@ public class ClientSqlQuery private final Map context; @JsonProperty - private final List parameters; + private final List parameters; @JsonCreator public ClientSqlQuery( @@ -62,7 +62,7 @@ public ClientSqlQuery( @JsonProperty("typesHeader") final boolean typesHeader, @JsonProperty("sqlTypesHeader") final boolean sqlTypesHeader, @JsonProperty("context") final Map context, - @JsonProperty("parameters") final List parameters + @JsonProperty("parameters") final List parameters ) { this.query = query; @@ -104,7 +104,7 @@ public Map getContext() return context; } - public List getParameters() + public List getParameters() { return parameters; } diff --git a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java index 6fb12ec7ada0..10379b3146ac 100644 --- a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java +++ b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; import org.apache.druid.jackson.DefaultObjectMapper; import org.junit.Assert; import org.junit.Test; @@ -42,4 +43,20 @@ public void testSerde() throws JsonProcessingException ); Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), ClientSqlQuery.class)); } + + @Test + public void testSerdeWithParameters() throws JsonProcessingException + { + 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/main/java/org/apache/druid/sql/http/SqlParameter.java b/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java index 7e8e190d3efa..79c3a145fd61 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 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 b087a79ea089..7b54ae39fadf 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 @@ -37,7 +37,9 @@ import java.util.stream.Collectors; /** - * @see ClientSqlQuery for the equivalent POJO class for use on the client side. + * 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 { 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 f9c083864f34..fc62cb05fba7 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 @@ 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 void testSerde() throws Exception 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 From b77d143e7727224de9a112615fa1ae0a5328708f Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 23:00:04 -0800 Subject: [PATCH 11/12] One more checkstyle import fix. --- .../java/org/apache/druid/testing/utils/MsqTestQueryHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5dca52f940ea..c4a70a475e5d 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.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.SqlQuery; import org.apache.druid.query.http.SqlTaskStatus; +import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.testing.IntegrationTestingConfig; import org.apache.druid.testing.clients.OverlordResourceTestClient; import org.apache.druid.testing.clients.SqlResourceTestClient; From 460941c2b3002c898875af2292ecc016a0598ae3 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Thu, 5 Dec 2024 23:32:26 -0800 Subject: [PATCH 12/12] More checkstyle import order fixes...Checstyle --fail-at-end doesn't work as intended. --- .../druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java | 2 +- .../apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java | 2 +- .../druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 6fa924b8b086..849ef1c4c2c0 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.java.util.common.StringUtils; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.query.QueryContexts; -import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.query.http.SqlTaskStatus; +import org.apache.druid.sql.http.SqlQuery; 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 47c1a84656e7..fa5489dca80c 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.table.DatasourceDefn; import org.apache.druid.catalog.model.table.TableBuilder; import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.query.http.SqlTaskStatus; +import org.apache.druid.sql.http.SqlQuery; 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 353f30052042..8fb325b1c651 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 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.sql.http.SqlQuery; import org.apache.druid.query.http.SqlTaskStatus; +import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.testing.clients.CoordinatorResourceTestClient; import org.apache.druid.testing.utils.DataLoaderHelper; import org.apache.druid.testing.utils.MsqTestQueryHelper;