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

Proposal to add new resultFormat - to wrap the Druid SQL JSON result array in a JSON object. #8816

Open
abhishekrb19 opened this issue Nov 3, 2019 · 2 comments

Comments

@abhishekrb19
Copy link
Contributor

abhishekrb19 commented Nov 3, 2019

Description

As of 0.16.0, Druid SQL queries made using JSON over HTTP to the Druid broker would by default return a JSON array of JSON objects (with "resultFormat": "object").

This is an alternative resultFormat proposal which is similar to the default object, but returns a JSON object wrapping the JSON result array.

Motivation

Two primary reasons for this proposal:

  • This would keep the successful response consistent with the error response, also containing a JSON object as shown here.
  • In addition, some serialization formats like JSON<->protobuf today don't support (un)marshaling a top-level JSON array, so a JSON object would be preferred (instead of manually concatenating the JSON array results) - more details can be found here.

The new resultFormat will be a JSON object containing a key, for example "data", and then have the resulting JSON array as the value. This is similar to the “error” response case, where we have "error", "errorMessage", etc., as the keys in the response object.

Example of current behavior:

[
  {
    "page": "Wikipedia:Vandalismusmeldung",
    "Edits": 33
  },
  {
    "page": "User:Cyde/List of candidates for speedy deletion/Subpage",
    "Edits": 28
  },
  {
    "page": "Jeremy Corbyn",
    "Edits": 27
  }
]

Proposal format:

{
  "data": [
   {
    "page": "Wikipedia:Vandalismusmeldung",
    "Edits": 33
   },
   {
    "page": "User:Cyde/List of candidates for speedy deletion/Subpage",
    "Edits": 28
   },
   {
    "page": "Jeremy Corbyn",
    "Edits": 27
   }
 ]
}
@vogievetsky
Copy link
Contributor

that would be a cool result format, another motivation (which is really no longer the case on modern browsers but still: https://cheatsheetseries.owasp.org/cheatsheets/AJAX_Security_Cheat_Sheet.html#always-return-json-with-an-object-on-the-outside

@sbespalov
Copy link

@abbondanza @vogievetsky the PR is green now. Can you please review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants