Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Move some classes from sql to processing & server for reusability #17542

Merged
merged 12 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* 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.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
* 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
{
@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<String, Object> context;

@JsonProperty
private final List<String> 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<String, Object> context,
@JsonProperty("parameters") final List<String> 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 isHeader()
{
return header;
}

public boolean isTypesHeader()
{
return typesHeader;
}

public boolean isSqlTypesHeader()
{
return sqlTypesHeader;
}

public Map<String, Object> getContext()
{
return context;
}

public List<String> getParameters()
{
return parameters;
}


@Override
public boolean equals(final Object o)
{
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);
}

@Override
public int hashCode()
{
return Objects.hash(query, resultFormat, header, typesHeader, sqlTypesHeader, context, parameters);
}

@Override
public String toString()
{
return "ClientSqlQuery{" +
"query='" + query + '\'' +
", resultFormat=" + resultFormat +
", header=" + header +
", typesHeader=" + typesHeader +
", sqlTypesHeader=" + sqlTypesHeader +
", context=" + context +
", parameters=" + parameters +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a test in SqlQueryTest to test inter-conversion between SqlQuery and ClientSqlQuery.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also, fixed a related bug with parameters caught in the unit test.

{
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.druid.sql.client;
package org.apache.druid.client.broker;

import com.google.inject.BindingAnnotation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Loading
Loading