-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Raw SQL Support on HTTP endpoints #17937
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
Conversation
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.
Pull Request Overview
This PR adds support for accepting raw SQL directly in the HTTP request body on the /druid/v2/sql endpoint while preserving the traditional JSON-based SQL submission when the Content-Type is application/json. Key changes include:
- Removing the @consumes(MediaType.APPLICATION_JSON) annotation to allow raw SQL for non-JSON content types.
- Introducing overloaded endpoints that use HttpContext to distinguish raw SQL from JSON SQL.
- Updating integration tests and documentation to cover the new behavior.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sql/src/main/java/org/apache/druid/sql/http/SqlResource.java | Updated endpoint to derive SqlQuery from HttpContext instead of relying solely on JSON input. |
| sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java | Added static helper methods to construct SqlQuery from HttpContext or HttpServletRequest, handling both JSON and raw SQL formats. |
| services/src/main/java/org/apache/druid/server/AsyncQueryForwardingServlet.java | Changed SQL query deserialization to use the new SqlQuery.from(request, objectMapper) method and ensured proper header setting when forwarding. |
| extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java | Modified endpoint to leverage HttpContext-based SqlQuery creation similar to the SQL resource. |
| extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/controller/http/DartSqlResource.java | Updated HTTP POST endpoint to use HttpContext for retrieving raw SQL queries. |
| docs/api-reference/sql-api.md | Revised API documentation to explain the raw text SQL input option and clarify handling of Content-Type headers. |
| integration-tests/src/test/java/org/apache/druid/tests/query/ITSqlQueryTest.java | Added integration tests validating different Content-Type header scenarios for SQL queries. |
integration-tests/src/test/java/org/apache/druid/tests/query/ITSqlQueryTest.java
Fixed
Show fixed
Hide fixed
|
The failed test is about coverage of UT, which is expected because I didn't add UT, but add IT for end-to-end test. |
|
@FrankChen021 I am currently unsure about the usecase here. Adding different flavors of the same API has a bunch of issues.
For all the above reasons I have my reservations against this PR. More 1 than 2 tbh. |
|
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.
Pull Request Overview
This PR adds support for raw SQL queries on HTTP endpoints by accepting non‑JSON content types, and updates both the query handling logic and corresponding tests.
- Updated SQL resource classes to support raw text queries via HTTP body with different Content-Type values
- Extended error handling and exception mapping for malformed or unsupported queries
- Updated integration tests and documentation to cover new raw SQL behaviors
Reviewed Changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sql/src/main/java/org/apache/druid/sql/http/SqlResource.java | Updated doPost signature to use HttpContext for raw SQL support |
| sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java | Enhanced extraction logic to support JSON, text/plain and form URL-encoded SQL queries |
| services/src/test/java/org/apache/druid/server/AsyncQueryForwardingServletTest.java | Modified test expectations for Content-Type header usage |
| services/src/main/java/org/apache/druid/server/AsyncQueryForwardingServlet.java | Updated SQL query creation and error handling with HttpException |
| server/src/main/java/org/apache/druid/server/initialization/jetty/*.java | Introduced new HttpException and exception mapper for uniform error responses |
| integration-tests/src/test/java/org/apache/druid/tests/query/ITSqlQueryTest.java | Added tests for various Content-Type values and raw SQL endpoint behaviors |
| extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/* | Adjusted SQL resource endpoints for raw SQL support in multi-stage query modules |
| docs/api-reference/sql-api.md | Revised documentation to include raw text SQL format instructions |
Files not reviewed (2)
- integration-tests/pom.xml: Language not supported
- sql/pom.xml: Language not supported
integration-tests/src/test/java/org/apache/druid/tests/query/ITSqlQueryTest.java
Outdated
Show resolved
Hide resolved
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.
LGTM, I just tried it locally and the examples and error paths seem to work well. TY!
I'll ignore the coverage checker when merging, because coverage is achieved through integration tests.
|
@FrankChen021 The IT tests added seem to be failing on new PRs. |
|
@adarshsanjeev interesting, why didn't the IT run against this PR as well as the main branch after it was merged? let me take a look at the failed IT on new PRs |
|
The IT failures were not seen because the migration to a different CI approach was not fully finished - which as a sideffect blocks ITs even if jacoco fails like in this case @FrankChen021 @gianm: adding |
|
I'm unsure if this PR was the main problem or some other things which were at play....there were multiple PRs merged even after this... |
|
@kgyrtkirk , there is a PR in-progress trying to address the race conditions causing the flakiness in |
|
@kgyrtkirk the change in this PR should have nothing to do with the failure of TaskQueueConcurrencyTest I'm still trying to run the IT against the auto brought up docker containers, but still have not made it because coordinator always exit abnormally. |
that's what I was suspecting - that's why I've left the second comment: there seems to be multiple independent things causing the current failures sorry for the noise - and thanks for checking it out! |
|
Since this is causing active failures in all PR's lets disable both the This will give time to @FrankChen021 to figure the failure out. |
|
The error log shows that: It turns out that integration tests configure the basic http authenticator in the |
Ah, I didn't know about the label |
I didn't notice that the IT didn't run, nor did I know there's such label to skip the coverage. |
|
sorry guys - I did mentioned it in a mail to dev list here |
Thanks, I remember seeing the mail but of course I forgot about the |
A part of #17769.
Description
Allow raw sql in the HTTP body on http endpoints. This helps reduce the client side complexity which requires users to do character escaping when the SQL is placed in the JSON document. The following example demonstrates the usage:
Release note
Druid now supports raw text format SQL on
/druid/v2/sqlendpoint. The content in the HTTP body of a HTTP request which does not setContent-Typetoapplication/jsonwill be treated as a raw sql text.Key changed/added classes in this PR
Content-Type: application/jsonwill be parsed as traditional JSON format SQLThis PR has: