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 type headers to response formats. #11914

Merged
merged 3 commits into from
Nov 13, 2021

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Nov 11, 2021

This allows clients to interpret the results of SQL queries without having to guess types.

This allows clients to interpret the results of SQL queries without
having to guess types.
@vogievetsky
Copy link
Contributor

I reviewed the docs and also tried out locally all the combinations of results format and type headers. Looks great to me!

image

@@ -879,6 +879,8 @@ Submit your query as the value of a "query" field in the JSON object within the
|`query`|SQL query string.| none (required)|
|`resultFormat`|Format of query results. See [Responses](#responses) for details.|`"object"`|
|`header`|Whether or not to include a header row for the query result. See [Responses](#responses) for details.|`false`|
|`typesHeader`|Whether or not to include type information in the header. Only applicable when `header` is `true`. See [Responses](#responses) for details.|`false`|
|`sqlTypesHeader`|Whether or not to include type information in the header. Only applicable when `header` is `true`. See [Responses](#responses) for details.|`false`|
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
|`sqlTypesHeader`|Whether or not to include type information in the header. Only applicable when `header` is `true`. See [Responses](#responses) for details.|`false`|
|`sqlTypesHeader`|Whether or not to include SQL type information in the header. Only applicable when `header` is `true`. See [Responses](#responses) for details.|`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.

Whoops, missed that. Fixed.

@@ -93,4 +96,44 @@ public void close() throws IOException
{
jsonGenerator.close();
}

static void writeHeader(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep these new methods static?
If it's for testing, we could test these by calling the writeHeader method provided by the interface ResultFormat.Writer.

Same comment in other writer implementations too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ObjectWriter.writeHeader is static because ObjectLinesWriter also uses it; same for ArrayWriter.writeHeader and ArrayLinesWriter.

Comment on lines 969 to 971
`X-Druid-SQL-Header-Included: yes` if `header` was set to true and if the version of Druid you are talking to
understands the `typesHeader` and `sqlTypesHeader` parameters. This happens even if you do not set `typesHeader`
or `sqlTypesHeader`.
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
`X-Druid-SQL-Header-Included: yes` if `header` was set to true and if the version of Druid you are talking to
understands the `typesHeader` and `sqlTypesHeader` parameters. This happens even if you do not set `typesHeader`
or `sqlTypesHeader`.
`X-Druid-SQL-Header-Included: yes` if `header` was set to true and if the version of Druid the client is connected to
understands the `typesHeader` and `sqlTypesHeader` parameters. Note that this header is set irrespective of whether `typesHeader`
or `sqlTypesHeader` are set or not.

Copy link
Contributor Author

@gianm gianm Nov 12, 2021

Choose a reason for hiding this comment

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

I adopted similar language. Thanks for the suggestion.

Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

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

LGTM

@abhishekagarwal87 abhishekagarwal87 merged commit 6f6e88e into apache:master Nov 13, 2021
@abhishekagarwal87 abhishekagarwal87 added this to the 0.23.0 milestone May 11, 2022
@gianm gianm deleted the sql-types-header branch September 23, 2022 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants