-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
abhishekrb19
merged 12 commits into
apache:master
from
abhishekrb19:refactor_broker_classes
Dec 6, 2024
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9bfeafc
Move ExplainPlan and ExplainPlanAttributes classes to processing modu…
abhishekrb19 5429f4f
Move SqlTaskStatus to processing for better reuse.
abhishekrb19 9ac43d4
Add ClientSqlQuery and ClientSqlQueryTest placeholders in processing.
abhishekrb19 a9f6725
Move Broker, BrokerClient and BrokerClientImpl to server package alon…
abhishekrb19 eaaaf7b
Add simple test for ClientSqlQuery and clean up methods.
abhishekrb19 9cb3edf
Checkstyle fixes.
abhishekrb19 bd90cbc
Add back getters as we need them.
abhishekrb19 bea8b3f
Guice provider for BrokerClient in the ServiceClientModule. Remove Br…
abhishekrb19 0a4747d
Checkstyle fix.
abhishekrb19 0616081
Review comments and add ClientSqlParameter for the equivalent SqlPara…
abhishekrb19 b77d143
One more checkstyle import fix.
abhishekrb19 460941c
More checkstyle import order fixes...Checstyle --fail-at-end doesn't …
abhishekrb19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 betweenSqlQuery
andClientSqlQuery
.There was a problem hiding this comment.
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.