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

SQL: Add a media type parser for SQL requests #74116

Merged
merged 4 commits into from
Jun 21, 2021

Conversation

bpintea
Copy link
Contributor

@bpintea bpintea commented Jun 15, 2021

This adds a (branch-specific) media type parser for SQL requests as a
near-drop-in replacement for the (master-only) per-REST-endpoint media
types parser (#64406).

Required for porting #73991.

This adds a (branch-specific) media type parser as a near-drop-in
replacement for the (master-only) per-REST-endpoint media types parser
(elastic#64406).
@bpintea bpintea marked this pull request as ready for review June 15, 2021 17:35
@bpintea bpintea added the :Analytics/SQL SQL querying label Jun 15, 2021
@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Jun 15, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@bpintea bpintea requested review from astefan, costin, matriv and Luegg June 15, 2021 17:35
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

Thx! Left some comments.

}

protected SqlQueryRequest createTestInstance(boolean binaryCommunication, Mode mode, boolean columnar) {
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

left over

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, removed.

}}).build();
}

protected SqlQueryRequest createTestInstance(boolean binaryCommunication, Mode mode, boolean columnar) {
Copy link
Contributor

Choose a reason for hiding this comment

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

binaryCommunications seems to be always false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And so the rest of the parameters were always having the same value. I've removed them.

* isn't but there is a {@code Accept} header then we use that. If there
* isn't then we use the {@code Content-Type} header which is required.
*/
public static SqlMediaType getResponseMediaType(RestRequest request, SqlQueryRequest sqlRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do those methods need to be public? As far as I can see they're used only for testing, could they be package private?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was also wondering: which methods need to be public for the backport?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Accessibility corrected.

private static SqlMediaType checkNonNullMediaType(SqlMediaType mediaType, RestRequest request) {
if (mediaType == null) {
String msg = String.format(Locale.ROOT, "Invalid request content type: Accept=[%s], Content-Type=[%s], format=[%s]",
request.header("Accept"), request.header("Content-Type"), request.param("format"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
request.header("Accept"), request.header("Content-Type"), request.param("format"));
request.header("Accept"), request.header("Content-Type"), request.param(URL_PARAM_FORMAT));

Only a nitpick but I noticed you're using the constant everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, replaced.

* isn't but there is a {@code Accept} header then we use that. If there
* isn't then we use the {@code Content-Type} header which is required.
*/
public static SqlMediaType getResponseMediaType(RestRequest request, SqlQueryRequest sqlRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was also wondering: which methods need to be public for the backport?

- remove stale comments;
- restricted methods access.
@bpintea
Copy link
Contributor Author

bpintea commented Jun 16, 2021

@elasticmachine update branch

if (mediaType == null) {
String msg = String.format(Locale.ROOT, "Invalid request content type: Accept=[%s], Content-Type=[%s], format=[%s]",
request.header("Accept"), request.header("Content-Type"), request.param(URL_PARAM_FORMAT));
throw new IllegalArgumentException(msg);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a more suitable ElasticsearchStatusException instead of the generic IAE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, that might be more suitable, but master emits the IAE in this case, it might be better to keep it as is for consistency.

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Thx!

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@bpintea bpintea merged commit a9bbebe into elastic:7.x Jun 21, 2021
@bpintea bpintea deleted the feat/7x_sql_media_parser branch June 21, 2021 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >refactoring Team:QL (Deprecated) Meta label for query languages team v7.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants