blob: cb854505c578089da197bcd52647df08e25e8041 [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[5314],{3905:(e,n,t)=>{t.d(n,{Zo:()=>p,kt:()=>y});var a=t(67294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,a,r=function(e,n){if(null==e)return{};var t,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var i=a.createContext({}),u=function(e){var n=a.useContext(i),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},p=function(e){var n=u(e.components);return a.createElement(i.Provider,{value:n},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},c=a.forwardRef((function(e,n){var t=e.components,r=e.mdxType,o=e.originalType,i=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=u(t),c=r,y=d["".concat(i,".").concat(c)]||d[c]||m[c]||o;return t?a.createElement(y,l(l({ref:n},p),{},{components:t})):a.createElement(y,l({ref:n},p))}));function y(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var o=t.length,l=new Array(o);l[0]=c;var s={};for(var i in n)hasOwnProperty.call(n,i)&&(s[i]=n[i]);s.originalType=e,s[d]="string"==typeof e?e:r,l[1]=s;for(var u=2;u<o;u++)l[u]=t[u];return a.createElement.apply(null,l)}return a.createElement.apply(null,t)}c.displayName="MDXCreateElement"},85162:(e,n,t)=>{t.d(n,{Z:()=>l});var a=t(67294),r=t(86010);const o={tabItem:"tabItem_Ymn6"};function l(e){var n=e.children,t=e.hidden,l=e.className;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(o.tabItem,l),hidden:t},n)}},74866:(e,n,t)=>{t.d(n,{Z:()=>v});var a=t(87462),r=t(67294),o=t(86010),l=t(12466),s=t(16550),i=t(91980),u=t(67392),p=t(50012);function d(e){return function(e){var n,t;return null!=(n=null==(t=r.Children.map(e,(function(e){if(!e||(0,r.isValidElement)(e)&&(n=e.props)&&"object"==typeof n&&"value"in n)return e;var n;throw new Error("Docusaurus error: Bad <Tabs> child <"+("string"==typeof e.type?e.type:e.type.name)+'>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.')})))?void 0:t.filter(Boolean))?n:[]}(e).map((function(e){var n=e.props;return{value:n.value,label:n.label,attributes:n.attributes,default:n.default}}))}function m(e){var n=e.values,t=e.children;return(0,r.useMemo)((function(){var e=null!=n?n:d(t);return function(e){var n=(0,u.l)(e,(function(e,n){return e.value===n.value}));if(n.length>0)throw new Error('Docusaurus error: Duplicate values "'+n.map((function(e){return e.value})).join(", ")+'" found in <Tabs>. Every value needs to be unique.')}(e),e}),[n,t])}function c(e){var n=e.value;return e.tabValues.some((function(e){return e.value===n}))}function y(e){var n=e.queryString,t=void 0!==n&&n,a=e.groupId,o=(0,s.k6)(),l=function(e){var n=e.queryString,t=void 0!==n&&n,a=e.groupId;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!a)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return null!=a?a:null}({queryString:t,groupId:a});return[(0,i._X)(l),(0,r.useCallback)((function(e){if(l){var n=new URLSearchParams(o.location.search);n.set(l,e),o.replace(Object.assign({},o.location,{search:n.toString()}))}}),[l,o])]}function h(e){var n,t,a,o,l=e.defaultValue,s=e.queryString,i=void 0!==s&&s,u=e.groupId,d=m(e),h=(0,r.useState)((function(){return function(e){var n,t=e.defaultValue,a=e.tabValues;if(0===a.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(t){if(!c({value:t,tabValues:a}))throw new Error('Docusaurus error: The <Tabs> has a defaultValue "'+t+'" but none of its children has the corresponding value. Available values are: '+a.map((function(e){return e.value})).join(", ")+". If you intend to show no default tab, use defaultValue={null} instead.");return t}var r=null!=(n=a.find((function(e){return e.default})))?n:a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:l,tabValues:d})})),k=h[0],N=h[1],T=y({queryString:i,groupId:u}),f=T[0],b=T[1],v=(n=function(e){return e?"docusaurus.tab."+e:null}({groupId:u}.groupId),t=(0,p.Nk)(n),a=t[0],o=t[1],[a,(0,r.useCallback)((function(e){n&&o.set(e)}),[n,o])]),g=v[0],q=v[1],R=function(){var e=null!=f?f:g;return c({value:e,tabValues:d})?e:null}();return(0,r.useLayoutEffect)((function(){R&&N(R)}),[R]),{selectedValue:k,selectValue:(0,r.useCallback)((function(e){if(!c({value:e,tabValues:d}))throw new Error("Can't select invalid tab value="+e);N(e),b(e),q(e)}),[b,q,d]),tabValues:d}}var k=t(72389);const N={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function T(e){var n=e.className,t=e.block,s=e.selectedValue,i=e.selectValue,u=e.tabValues,p=[],d=(0,l.o5)().blockElementScrollPositionUntilNextRender,m=function(e){var n=e.currentTarget,t=p.indexOf(n),a=u[t].value;a!==s&&(d(n),i(a))},c=function(e){var n,t=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":var a,r=p.indexOf(e.currentTarget)+1;t=null!=(a=p[r])?a:p[0];break;case"ArrowLeft":var o,l=p.indexOf(e.currentTarget)-1;t=null!=(o=p[l])?o:p[p.length-1]}null==(n=t)||n.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":t},n)},u.map((function(e){var n=e.value,t=e.label,l=e.attributes;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,key:n,ref:function(e){return p.push(e)},onKeyDown:c,onClick:m},l,{className:(0,o.Z)("tabs__item",N.tabItem,null==l?void 0:l.className,{"tabs__item--active":s===n})}),null!=t?t:n)})))}function f(e){var n=e.lazy,t=e.children,a=e.selectedValue,o=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){var l=o.find((function(e){return e.props.value===a}));return l?(0,r.cloneElement)(l,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},o.map((function(e,n){return(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})})))}function b(e){var n=h(e);return r.createElement("div",{className:(0,o.Z)("tabs-container",N.tabList)},r.createElement(T,(0,a.Z)({},e,n)),r.createElement(f,(0,a.Z)({},e,n)))}function v(e){var n=(0,k.Z)();return r.createElement(b,(0,a.Z)({key:String(n)},e))}},89549:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>m,contentTitle:()=>p,default:()=>k,frontMatter:()=>u,metadata:()=>d,toc:()=>c});var a=t(87462),r=t(63366),o=(t(67294),t(3905)),l=t(74866),s=t(85162),i=["components"],u={id:"sql-api",title:"Druid SQL API",sidebar_label:"Druid SQL"},p=void 0,d={unversionedId:"api-reference/sql-api",id:"api-reference/sql-api",title:"Druid SQL API",description:"\x3c!--",source:"@site/docs/29.0.1/api-reference/sql-api.md",sourceDirName:"api-reference",slug:"/api-reference/sql-api",permalink:"/docs/29.0.1/api-reference/sql-api",draft:!1,tags:[],version:"current",frontMatter:{id:"sql-api",title:"Druid SQL API",sidebar_label:"Druid SQL"},sidebar:"docs",previous:{title:"Overview",permalink:"/docs/29.0.1/api-reference/"},next:{title:"SQL-based ingestion",permalink:"/docs/29.0.1/api-reference/sql-ingestion-api"}},m={},c=[{value:"Query from Historicals",id:"query-from-historicals",level:2},{value:"Submit a query",id:"submit-a-query",level:3},{value:"URL",id:"url",level:4},{value:"Request body",id:"request-body",level:4},{value:"Responses",id:"responses",level:4},{value:"Client-side error handling and truncated responses",id:"client-side-error-handling-and-truncated-responses",level:4},{value:"Sample request",id:"sample-request",level:4},{value:"Sample response",id:"sample-response",level:4},{value:"Cancel a query",id:"cancel-a-query",level:3},{value:"URL",id:"url-1",level:4},{value:"Responses",id:"responses-1",level:4},{value:"Sample request",id:"sample-request-1",level:4},{value:"Sample response",id:"sample-response-1",level:4},{value:"Query output format",id:"query-output-format",level:3},{value:"Query from deep storage",id:"query-from-deep-storage",level:2},{value:"Submit a query",id:"submit-a-query-1",level:3},{value:"URL",id:"url-2",level:4},{value:"Request body",id:"request-body-1",level:4},{value:"Responses",id:"responses-2",level:4},{value:"Sample request",id:"sample-request-2",level:4},{value:"Sample response",id:"sample-response-2",level:4},{value:"Get query status",id:"get-query-status",level:3},{value:"URL",id:"url-3",level:4},{value:"Responses",id:"responses-3",level:4},{value:"Sample request",id:"sample-request-3",level:4},{value:"Sample response",id:"sample-response-3",level:4},{value:"Get query results",id:"get-query-results",level:3},{value:"URL",id:"url-4",level:4},{value:"Query parameters",id:"query-parameters",level:4},{value:"Responses",id:"responses-4",level:4},{value:"Sample request",id:"sample-request-4",level:4},{value:"Sample response",id:"sample-response-4",level:4},{value:"Cancel a query",id:"cancel-a-query-1",level:3},{value:"URL",id:"url-5",level:4},{value:"Responses",id:"responses-5",level:4},{value:"Sample request",id:"sample-request-5",level:4},{value:"Sample response",id:"sample-response-5",level:4}],y={toc:c},h="wrapper";function k(e){var n=e.components,t=(0,r.Z)(e,i);return(0,o.kt)(h,(0,a.Z)({},y,t,{components:n,mdxType:"MDXLayout"}),(0,o.kt)("admonition",{type:"info"},(0,o.kt)("p",{parentName:"admonition"}," Apache Druid supports two query languages: Druid SQL and ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/"},"native queries"),".\nThis document describes the SQL language.")),(0,o.kt)("p",null,"In this topic, ",(0,o.kt)("inlineCode",{parentName:"p"},"http://ROUTER_IP:ROUTER_PORT")," is a placeholder for your Router service address and port. Replace it with the information for your deployment. For example, use ",(0,o.kt)("inlineCode",{parentName:"p"},"http://localhost:8888")," for quickstart deployments."),(0,o.kt)("h2",{id:"query-from-historicals"},"Query from Historicals"),(0,o.kt)("h3",{id:"submit-a-query"},"Submit a query"),(0,o.kt)("p",null,"Submits a SQL-based query in the JSON request body. Returns a JSON object with the query results and optional metadata for the results. You can also use this endpoint to query ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/sql-metadata-tables"},"metadata tables"),"."),(0,o.kt)("p",null,"Each query has an associated SQL query ID. You can set this ID manually using the SQL context parameter ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId"),". If not set, Druid automatically generates ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," and returns it in the response header for ",(0,o.kt)("inlineCode",{parentName:"p"},"X-Druid-SQL-Query-Id"),". Note that you need the ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," to ",(0,o.kt)("a",{parentName:"p",href:"#cancel-a-query"},"cancel a query"),"."),(0,o.kt)("h4",{id:"url"},"URL"),(0,o.kt)("code",{class:"postAPI"},"POST")," ",(0,o.kt)("code",null,"/druid/v2/sql"),(0,o.kt)("h4",{id:"request-body"},"Request body"),(0,o.kt)("p",null,"The request body takes the following properties:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"query"),": SQL query string.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"resultFormat"),": String that indicates the format to return query results. Select one of the following formats:"),(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"object"),": Returns a JSON array of JSON objects with the HTTP response header ",(0,o.kt)("inlineCode",{parentName:"p"},"Content-Type: application/json"),".",(0,o.kt)("br",{parentName:"p"}),"\n","Object field names match the columns returned by the SQL query in the same order as the SQL query.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"array"),": Returns a JSON array of JSON arrays with the HTTP response header ",(0,o.kt)("inlineCode",{parentName:"p"},"Content-Type: application/json"),".",(0,o.kt)("br",{parentName:"p"}),"\n","Each inner array has elements matching the columns returned by the SQL query, in order.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"objectLines"),": Returns newline-delimited JSON objects with the HTTP response header ",(0,o.kt)("inlineCode",{parentName:"p"},"Content-Type: text/plain"),".",(0,o.kt)("br",{parentName:"p"}),"\n","Newline separation facilitates parsing the entire response set as a stream if you don't have a streaming JSON parser.\nThis format includes a single trailing newline character so you can detect a truncated response.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"arrayLines"),": Returns newline-delimited JSON arrays with the HTTP response header ",(0,o.kt)("inlineCode",{parentName:"p"},"Content-Type: text/plain"),".",(0,o.kt)("br",{parentName:"p"}),"\n","Newline separation facilitates parsing the entire response set as a stream if you don't have a streaming JSON parser.\nThis format includes a single trailing newline character so you can detect a truncated response.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"csv"),": Returns comma-separated values with one row per line. Sent with the HTTP response header ",(0,o.kt)("inlineCode",{parentName:"p"},"Content-Type: text/csv"),".",(0,o.kt)("br",{parentName:"p"}),"\n","Druid uses double quotes to escape individual field values. For example, a value with a comma returns ",(0,o.kt)("inlineCode",{parentName:"p"},'"A,B"'),".\nIf the field value contains a double quote character, Druid escapes it with a second double quote character.\nFor example, ",(0,o.kt)("inlineCode",{parentName:"p"},'foo"bar')," becomes ",(0,o.kt)("inlineCode",{parentName:"p"},'foo""bar'),".\nThis format includes a single trailing newline character so you can detect a truncated response.")))),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"header"),": Boolean value that determines whether to return information on column names. When set to ",(0,o.kt)("inlineCode",{parentName:"p"},"true"),", Druid returns the column names as the first row of the results. To also get information on the column types, set ",(0,o.kt)("inlineCode",{parentName:"p"},"typesHeader")," or ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," to ",(0,o.kt)("inlineCode",{parentName:"p"},"true"),". For a comparative overview of data formats and configurations for the header, see the ",(0,o.kt)("a",{parentName:"p",href:"#query-output-format"},"Query output format")," table.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"typesHeader"),": Adds Druid runtime type information in the header. Requires ",(0,o.kt)("inlineCode",{parentName:"p"},"header")," to be set to ",(0,o.kt)("inlineCode",{parentName:"p"},"true"),". Complex types, like sketches, will be reported as ",(0,o.kt)("inlineCode",{parentName:"p"},"COMPLEX<typeName>")," if a particular complex type name is known for that field, or as ",(0,o.kt)("inlineCode",{parentName:"p"},"COMPLEX")," if the particular type name is unknown or mixed.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader"),": Adds SQL type information in the header. Requires ",(0,o.kt)("inlineCode",{parentName:"p"},"header")," to be set to ",(0,o.kt)("inlineCode",{parentName:"p"},"true"),"."),(0,o.kt)("p",{parentName:"li"}," For compatibility, Druid returns the HTTP header ",(0,o.kt)("inlineCode",{parentName:"p"},"X-Druid-SQL-Header-Included: yes")," when all of the following conditions are met:"),(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},"The ",(0,o.kt)("inlineCode",{parentName:"li"},"header")," property is set to true."),(0,o.kt)("li",{parentName:"ul"},"The version of Druid supports ",(0,o.kt)("inlineCode",{parentName:"li"},"typesHeader")," and ",(0,o.kt)("inlineCode",{parentName:"li"},"sqlTypesHeader"),", regardless of whether either property is set."))),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"context"),": JSON object containing optional ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/sql-query-context"},"SQL query context parameters"),", such as to set the query ID, time zone, and whether to use an approximation algorithm for distinct count.")),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},(0,o.kt)("inlineCode",{parentName:"p"},"parameters"),": List of query parameters for parameterized queries. Each parameter in the array should be a JSON object containing the parameter's SQL data type and parameter value. For a list of supported SQL types, see ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/sql-data-types"},"Data types"),"."),(0,o.kt)("p",{parentName:"li"}," For example:"),(0,o.kt)("pre",{parentName:"li"},(0,o.kt)("code",{parentName:"pre",className:"language-json"},'"parameters": [\n {\n "type": "VARCHAR",\n "value": "bar"\n }\n]\n')))),(0,o.kt)("h4",{id:"responses"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"1",label:"200 SUCCESS",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully submitted query"))),(0,o.kt)(s.Z,{value:"2",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "A well-defined error code.",\n "errorMessage": "A message with additional details about the error.",\n "errorClass": "Class of exception that caused this error.",\n "host": "The host on which the error occurred."\n}\n'))),(0,o.kt)(s.Z,{value:"3",label:"500 INTERNAL SERVER ERROR",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Request not sent due to unexpected conditions. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "A well-defined error code.",\n "errorMessage": "A message with additional details about the error.",\n "errorClass": "Class of exception that caused this error.",\n "host": "The host on which the error occurred."\n}\n')))),(0,o.kt)("h4",{id:"client-side-error-handling-and-truncated-responses"},"Client-side error handling and truncated responses"),(0,o.kt)("p",null,"Druid reports errors that occur before the response body is sent as JSON with an HTTP 500 status code. The errors are reported using the same format as ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/#query-errors"},"native Druid query errors"),".\nIf an error occurs while Druid is sending the response body, the server handling the request stops the response midstream and logs an error."),(0,o.kt)("p",null,"This means that when you call the SQL API, you must properly handle response truncation.\nFor ",(0,o.kt)("inlineCode",{parentName:"p"},"object")," and ",(0,o.kt)("inlineCode",{parentName:"p"},"array")," formats, truncated responses are invalid JSON.\nFor line-oriented formats, Druid includes a newline character as the final character of every complete response. Absence of a final newline character indicates a truncated response."),(0,o.kt)("p",null,"If you detect a truncated response, treat it as an error."),(0,o.kt)("hr",null),(0,o.kt)("h4",{id:"sample-request"},"Sample request"),(0,o.kt)("p",null,"The following example retrieves all rows in the ",(0,o.kt)("inlineCode",{parentName:"p"},"wikipedia")," datasource where the ",(0,o.kt)("inlineCode",{parentName:"p"},"user")," is ",(0,o.kt)("inlineCode",{parentName:"p"},"BlueMoon2662"),". The query is assigned the ID ",(0,o.kt)("inlineCode",{parentName:"p"},"request01")," using the ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," context parameter. The optional properties ",(0,o.kt)("inlineCode",{parentName:"p"},"header"),", ",(0,o.kt)("inlineCode",{parentName:"p"},"typesHeader"),", and ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," are set to ",(0,o.kt)("inlineCode",{parentName:"p"},"true")," to include type information to the response."),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"4",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql" \\\n--header \'Content-Type: application/json\' \\\n--data \'{\n "query": "SELECT * FROM wikipedia WHERE user=\'\\\'\'BlueMoon2662\'\\\'\'",\n "context" : {"sqlQueryId" : "request01"},\n "header" : true,\n "typesHeader" : true,\n "sqlTypesHeader" : true\n}\'\n'))),(0,o.kt)(s.Z,{value:"5",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},'POST /druid/v2/sql HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\nContent-Type: application/json\nContent-Length: 192\n\n{\n "query": "SELECT * FROM wikipedia WHERE user=\'BlueMoon2662\'",\n "context" : {"sqlQueryId" : "request01"},\n "header" : true,\n "typesHeader" : true,\n "sqlTypesHeader" : true\n}\n')))),(0,o.kt)("h4",{id:"sample-response"},"Sample response"),(0,o.kt)("details",null,(0,o.kt)("summary",null,"Click to show sample response"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'[\n {\n "__time": {\n "type": "LONG",\n "sqlType": "TIMESTAMP"\n },\n "channel": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "cityName": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "comment": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "countryIsoCode": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "countryName": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "isAnonymous": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "isMinor": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "isNew": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "isRobot": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "isUnpatrolled": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "metroCode": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "namespace": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "page": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "regionIsoCode": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "regionName": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "user": {\n "type": "STRING",\n "sqlType": "VARCHAR"\n },\n "delta": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "added": {\n "type": "LONG",\n "sqlType": "BIGINT"\n },\n "deleted": {\n "type": "LONG",\n "sqlType": "BIGINT"\n }\n },\n {\n "__time": "2015-09-12T00:47:53.259Z",\n "channel": "#ja.wikipedia",\n "cityName": "",\n "comment": "/* \u5bfe\u6226\u901a\u7b97\u6210\u7e3e\u3068\u5f97\u5931\u70b9 */",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 1,\n "isNew": 0,\n "isRobot": 0,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "\u30a2\u30eb\u30d3\u30ec\u30c3\u30af\u30b9\u65b0\u6f5f\u306e\u5e74\u5ea6\u5225\u6210\u7e3e\u4e00\u89a7",\n "regionIsoCode": "",\n "regionName": "",\n "user": "BlueMoon2662",\n "delta": 14,\n "added": 14,\n "deleted": 0\n }\n]\n'))),(0,o.kt)("h3",{id:"cancel-a-query"},"Cancel a query"),(0,o.kt)("p",null,"Cancels a query on the Router or the Broker with the associated ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId"),". The ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," can be manually set when the query is submitted in the query context parameter, or if not set, Druid will generate one and return it in the response header when the query is successfully submitted. Note that Druid does not enforce a unique ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," in the query context. If you've set the same ",(0,o.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," for multiple queries, Druid cancels all requests with that query ID."),(0,o.kt)("p",null,"When you cancel a query, Druid handles the cancellation in a best-effort manner. Druid immediately marks the query as canceled and aborts the query execution as soon as possible. However, the query may continue running for a short time after you make the cancellation request."),(0,o.kt)("p",null,"Cancellation requests require READ permission on all resources used in the SQL query."),(0,o.kt)("h4",{id:"url-1"},"URL"),(0,o.kt)("code",{class:"deleteAPI"},"DELETE")," ",(0,o.kt)("code",null,"/druid/v2/sql/:sqlQueryId"),(0,o.kt)("h4",{id:"responses-1"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"6",label:"202 SUCCESS",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully deleted query"))),(0,o.kt)(s.Z,{value:"7",label:"403 FORBIDDEN",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Authorization failure"))),(0,o.kt)(s.Z,{value:"8",label:"404 NOT FOUND",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Invalid ",(0,o.kt)("inlineCode",{parentName:"em"},"sqlQueryId")," or query was completed before cancellation request")))),(0,o.kt)("hr",null),(0,o.kt)("h4",{id:"sample-request-1"},"Sample request"),(0,o.kt)("p",null,"The following example cancels a request with the set query ID ",(0,o.kt)("inlineCode",{parentName:"p"},"request01"),"."),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"9",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl --request DELETE "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql/request01"\n'))),(0,o.kt)(s.Z,{value:"10",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},"DELETE /druid/v2/sql/request01 HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\n")))),(0,o.kt)("h4",{id:"sample-response-1"},"Sample response"),(0,o.kt)("p",null,"A successful response results in an ",(0,o.kt)("inlineCode",{parentName:"p"},"HTTP 202")," message code and an empty response body."),(0,o.kt)("h3",{id:"query-output-format"},"Query output format"),(0,o.kt)("p",null,"The following table shows examples of how Druid returns the column names and data types based on the result format and the type request.\nIn all cases, ",(0,o.kt)("inlineCode",{parentName:"p"},"header")," is true.\nThe examples includes the first row of results, where the value of ",(0,o.kt)("inlineCode",{parentName:"p"},"user")," is ",(0,o.kt)("inlineCode",{parentName:"p"},"BlueMoon2662"),"."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},'| Format | typesHeader | sqlTypesHeader | Example output |\n|--------|-------------|----------------|--------------------------------------------------------------------------------------------|\n| object | true | false | [ { "user" : { "type" : "STRING" } }, { "user" : "BlueMoon2662" } ] |\n| object | true | true | [ { "user" : { "type" : "STRING", "sqlType" : "VARCHAR" } }, { "user" : "BlueMoon2662" } ] |\n| object | false | true | [ { "user" : { "sqlType" : "VARCHAR" } }, { "user" : "BlueMoon2662" } ] |\n| object | false | false | [ { "user" : null }, { "user" : "BlueMoon2662" } ] |\n| array | true | false | [ [ "user" ], [ "STRING" ], [ "BlueMoon2662" ] ] |\n| array | true | true | [ [ "user" ], [ "STRING" ], [ "VARCHAR" ], [ "BlueMoon2662" ] ] |\n| array | false | true | [ [ "user" ], [ "VARCHAR" ], [ "BlueMoon2662" ] ] |\n| array | false | false | [ [ "user" ], [ "BlueMoon2662" ] ] |\n| csv | true | false | user STRING BlueMoon2662 |\n| csv | true | true | user STRING VARCHAR BlueMoon2662 |\n| csv | false | true | user VARCHAR BlueMoon2662 |\n| csv | false | false | user BlueMoon2662 |\n')),(0,o.kt)("h2",{id:"query-from-deep-storage"},"Query from deep storage"),(0,o.kt)("p",null,"You can use the ",(0,o.kt)("inlineCode",{parentName:"p"},"sql/statements")," endpoint to query segments that exist only in deep storage and are not loaded onto your Historical processes as determined by your load rules."),(0,o.kt)("p",null,"Note that at least one segment of a datasource must be available on a Historical process so that the Broker can plan your query. A quick way to check if this is true is whether or not a datasource is visible in the Druid console."),(0,o.kt)("p",null,"For more information, see ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/querying/query-deep-storage"},"Query from deep storage"),"."),(0,o.kt)("h3",{id:"submit-a-query-1"},"Submit a query"),(0,o.kt)("p",null,'Submit a query for data stored in deep storage. Any data ingested into Druid is placed into deep storage. The query is contained in the "query" field in the JSON object within the request payload.'),(0,o.kt)("p",null,"Note that at least part of a datasource must be available on a Historical process so that Druid can plan your query and only the user who submits a query can see the results."),(0,o.kt)("h4",{id:"url-2"},"URL"),(0,o.kt)("code",{class:"postAPI"},"POST")," ",(0,o.kt)("code",null,"/druid/v2/sql/statements"),(0,o.kt)("h4",{id:"request-body-1"},"Request body"),(0,o.kt)("p",null,"Generally, the ",(0,o.kt)("inlineCode",{parentName:"p"},"sql")," and ",(0,o.kt)("inlineCode",{parentName:"p"},"sql/statements")," endpoints support the same response body fields with minor differences. For general information about the available fields, see ",(0,o.kt)("a",{parentName:"p",href:"#submit-a-query"},"Submit a query to the ",(0,o.kt)("inlineCode",{parentName:"a"},"sql")," endpoint"),"."),(0,o.kt)("p",null,"Keep the following in mind when submitting queries to the ",(0,o.kt)("inlineCode",{parentName:"p"},"sql/statements")," endpoint:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("p",{parentName:"li"},"Apart from the context parameters mentioned ",(0,o.kt)("a",{parentName:"p",href:"/docs/29.0.1/multi-stage-query/reference#context-parameters"},"here")," there are additional context parameters for ",(0,o.kt)("inlineCode",{parentName:"p"},"sql/statements")," specifically:"),(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"executionMode")," determines how query results are fetched. Druid currently only supports ",(0,o.kt)("inlineCode",{parentName:"li"},"ASYNC"),". You must manually retrieve your results after the query completes."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"selectDestination")," determines where final results get written. By default, results are written to task reports. Set this parameter to ",(0,o.kt)("inlineCode",{parentName:"li"},"durableStorage")," to instruct Druid to write the results from SELECT queries to durable storage, which allows you to fetch larger result sets. For result sets with more than 3000 rows, it is highly recommended to use ",(0,o.kt)("inlineCode",{parentName:"li"},"durableStorage"),". Note that this requires you to have ",(0,o.kt)("a",{parentName:"li",href:"/docs/29.0.1/operations/durable-storage"},"durable storage for MSQ")," enabled.")))),(0,o.kt)("h4",{id:"responses-2"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"1",label:"200 SUCCESS",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully queried from deep storage"))),(0,o.kt)(s.Z,{value:"2",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "Summary of the encountered error.",\n "errorClass": "Class of exception that caused this error.",\n "host": "The host on which the error occurred.",\n "errorCode": "Well-defined error code.",\n "persona": "Role or persona associated with the error.",\n "category": "Classification of the error.",\n "errorMessage": "Summary of the encountered issue with expanded information.",\n "context": "Additional context about the error."\n}\n')))),(0,o.kt)("hr",null),(0,o.kt)("h4",{id:"sample-request-2"},"Sample request"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"3",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql/statements" \\\n--header \'Content-Type: application/json\' \\\n--data \'{\n "query": "SELECT * FROM wikipedia WHERE user=\'\\\'\'BlueMoon2662\'\\\'\'",\n "context": {\n "executionMode":"ASYNC"\n }\n}\'\n'))),(0,o.kt)(s.Z,{value:"4",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},'POST /druid/v2/sql/statements HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\nContent-Type: application/json\nContent-Length: 134\n\n{\n "query": "SELECT * FROM wikipedia WHERE user=\'BlueMoon2662\'",\n "context": {\n "executionMode":"ASYNC"\n }\n}\n')))),(0,o.kt)("h4",{id:"sample-response-2"},"Sample response"),(0,o.kt)("details",null,(0,o.kt)("summary",null,"Click to show sample response"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "queryId": "query-b82a7049-b94f-41f2-a230-7fef94768745",\n "state": "ACCEPTED",\n "createdAt": "2023-07-26T21:16:25.324Z",\n "schema": [\n {\n "name": "__time",\n "type": "TIMESTAMP",\n "nativeType": "LONG"\n },\n {\n "name": "channel",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "cityName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "comment",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "countryIsoCode",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "countryName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "isAnonymous",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isMinor",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isNew",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isRobot",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isUnpatrolled",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "metroCode",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "namespace",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "page",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "regionIsoCode",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "regionName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "user",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "delta",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "added",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "deleted",\n "type": "BIGINT",\n "nativeType": "LONG"\n }\n ],\n "durationMs": -1\n}\n'))),(0,o.kt)("h3",{id:"get-query-status"},"Get query status"),(0,o.kt)("p",null,"Retrieves information about the query associated with the given query ID. The response matches the response from the POST API if the query is accepted or running and the execution mode is ",(0,o.kt)("inlineCode",{parentName:"p"},"ASYNC"),". In addition to the fields that this endpoint shares with ",(0,o.kt)("inlineCode",{parentName:"p"},"POST /sql/statements"),", a completed query's status includes the following:"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"A ",(0,o.kt)("inlineCode",{parentName:"li"},"result")," object that summarizes information about your results, such as the total number of rows and sample records."),(0,o.kt)("li",{parentName:"ul"},"A ",(0,o.kt)("inlineCode",{parentName:"li"},"pages")," object that includes the following information for each page of results:",(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"numRows"),": the number of rows in that page of results."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"sizeInBytes"),": the size of the page."),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"id"),": the page number that you can use to reference a specific page when you get query results.")))),(0,o.kt)("h4",{id:"url-3"},"URL"),(0,o.kt)("code",{class:"getAPI"},"GET")," ",(0,o.kt)("code",null,"/druid/v2/sql/statements/:queryId"),(0,o.kt)("h4",{id:"responses-3"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"5",label:"200 SUCCESS",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully retrieved query status"))),(0,o.kt)(s.Z,{value:"6",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "Summary of the encountered error.",\n "errorCode": "Well-defined error code.",\n "persona": "Role or persona associated with the error.",\n "category": "Classification of the error.",\n "errorMessage": "Summary of the encountered issue with expanded information.",\n "context": "Additional context about the error."\n}\n')))),(0,o.kt)("h4",{id:"sample-request-3"},"Sample request"),(0,o.kt)("p",null,"The following example retrieves the status of a query with specified ID ",(0,o.kt)("inlineCode",{parentName:"p"},"query-9b93f6f7-ab0e-48f5-986a-3520f84f0804"),"."),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"7",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql/statements/query-9b93f6f7-ab0e-48f5-986a-3520f84f0804"\n'))),(0,o.kt)(s.Z,{value:"8",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},"GET /druid/v2/sql/statements/query-9b93f6f7-ab0e-48f5-986a-3520f84f0804 HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\n")))),(0,o.kt)("h4",{id:"sample-response-3"},"Sample response"),(0,o.kt)("details",null,(0,o.kt)("summary",null,"Click to show sample response"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "queryId": "query-9b93f6f7-ab0e-48f5-986a-3520f84f0804",\n "state": "SUCCESS",\n "createdAt": "2023-07-26T22:57:46.620Z",\n "schema": [\n {\n "name": "__time",\n "type": "TIMESTAMP",\n "nativeType": "LONG"\n },\n {\n "name": "channel",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "cityName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "comment",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "countryIsoCode",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "countryName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "isAnonymous",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isMinor",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isNew",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isRobot",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "isUnpatrolled",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "metroCode",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "namespace",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "page",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "regionIsoCode",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "regionName",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "user",\n "type": "VARCHAR",\n "nativeType": "STRING"\n },\n {\n "name": "delta",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "added",\n "type": "BIGINT",\n "nativeType": "LONG"\n },\n {\n "name": "deleted",\n "type": "BIGINT",\n "nativeType": "LONG"\n }\n ],\n "durationMs": 25591,\n "result": {\n "numTotalRows": 1,\n "totalSizeInBytes": 375,\n "dataSource": "__query_select",\n "sampleRecords": [\n [\n 1442018873259,\n "#ja.wikipedia",\n "",\n "/* \u5bfe\u6226\u901a\u7b97\u6210\u7e3e\u3068\u5f97\u5931\u70b9 */",\n "",\n "",\n 0,\n 1,\n 0,\n 0,\n 0,\n 0,\n "Main",\n "\u30a2\u30eb\u30d3\u30ec\u30c3\u30af\u30b9\u65b0\u6f5f\u306e\u5e74\u5ea6\u5225\u6210\u7e3e\u4e00\u89a7",\n "",\n "",\n "BlueMoon2662",\n 14,\n 14,\n 0\n ]\n ],\n "pages": [\n {\n "id": 0,\n "numRows": 1,\n "sizeInBytes": 375\n }\n ]\n }\n}\n'))),(0,o.kt)("h3",{id:"get-query-results"},"Get query results"),(0,o.kt)("p",null,"Retrieves results for completed queries. Results are separated into pages, so you can use the optional ",(0,o.kt)("inlineCode",{parentName:"p"},"page")," parameter to refine the results you get. Druid returns information about the composition of each page and its page number (",(0,o.kt)("inlineCode",{parentName:"p"},"id"),"). For information about pages, see ",(0,o.kt)("a",{parentName:"p",href:"#get-query-status"},"Get query status"),"."),(0,o.kt)("p",null,"If a page number isn't passed, all results are returned sequentially in the same response. If you have large result sets, you may encounter timeouts based on the value configured for ",(0,o.kt)("inlineCode",{parentName:"p"},"druid.router.http.readTimeout"),"."),(0,o.kt)("p",null,"Getting the query results for an ingestion query returns an empty response."),(0,o.kt)("h4",{id:"url-4"},"URL"),(0,o.kt)("code",{class:"getAPI"},"GET")," ",(0,o.kt)("code",null,"/druid/v2/sql/statements/:queryId/results"),(0,o.kt)("h4",{id:"query-parameters"},"Query parameters"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"page")," (optional)",(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},"Type: Int"),(0,o.kt)("li",{parentName:"ul"},"Fetch results based on page numbers. If not specified, all results are returned sequentially starting from page 0 to N in the same response."))),(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("inlineCode",{parentName:"li"},"resultFormat")," (optional)",(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},"Type: String"),(0,o.kt)("li",{parentName:"ul"},"Defines the format in which the results are presented. The following options are supported ",(0,o.kt)("inlineCode",{parentName:"li"},"arrayLines"),",",(0,o.kt)("inlineCode",{parentName:"li"},"objectLines"),",",(0,o.kt)("inlineCode",{parentName:"li"},"array"),",",(0,o.kt)("inlineCode",{parentName:"li"},"object"),", and ",(0,o.kt)("inlineCode",{parentName:"li"},"csv"),". The default is ",(0,o.kt)("inlineCode",{parentName:"li"},"object"),".")))),(0,o.kt)("h4",{id:"responses-4"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"9",label:"200 SUCCESS",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully retrieved query results"))),(0,o.kt)(s.Z,{value:"10",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Query in progress. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "Summary of the encountered error.",\n "errorCode": "Well-defined error code.",\n "persona": "Role or persona associated with the error.",\n "category": "Classification of the error.",\n "errorMessage": "Summary of the encountered issue with expanded information.",\n "context": "Additional context about the error."\n}\n'))),(0,o.kt)(s.Z,{value:"11",label:"404 NOT FOUND",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Query not found, failed or canceled"))),(0,o.kt)(s.Z,{value:"12",label:"500 SERVER ERROR",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "Summary of the encountered error.",\n "errorCode": "Well-defined error code.",\n "persona": "Role or persona associated with the error.",\n "category": "Classification of the error.",\n "errorMessage": "Summary of the encountered issue with expanded information.",\n "context": "Additional context about the error."\n}\n')))),(0,o.kt)("hr",null),(0,o.kt)("h4",{id:"sample-request-4"},"Sample request"),(0,o.kt)("p",null,"The following example retrieves the status of a query with specified ID ",(0,o.kt)("inlineCode",{parentName:"p"},"query-f3bca219-173d-44d4-bdc7-5002e910352f"),"."),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"13",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql/statements/query-f3bca219-173d-44d4-bdc7-5002e910352f/results"\n'))),(0,o.kt)(s.Z,{value:"14",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},"GET /druid/v2/sql/statements/query-f3bca219-173d-44d4-bdc7-5002e910352f/results HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\n")))),(0,o.kt)("h4",{id:"sample-response-4"},"Sample response"),(0,o.kt)("details",null,(0,o.kt)("summary",null,"Click to show sample response"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'[\n {\n "__time": 1442018818771,\n "channel": "#en.wikipedia",\n "cityName": "",\n "comment": "added project",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 0,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Talk",\n "page": "Talk:Oswald Tilghman",\n "regionIsoCode": "",\n "regionName": "",\n "user": "GELongstreet",\n "delta": 36,\n "added": 36,\n "deleted": 0\n },\n {\n "__time": 1442018820496,\n "channel": "#ca.wikipedia",\n "cityName": "",\n "comment": "Robot inserta {{Commonscat}} que enlla\xe7a amb [[commons:category:Rallicula]]",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 1,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Rallicula",\n "regionIsoCode": "",\n "regionName": "",\n "user": "PereBot",\n "delta": 17,\n "added": 17,\n "deleted": 0\n },\n {\n "__time": 1442018825474,\n "channel": "#en.wikipedia",\n "cityName": "Auburn",\n "comment": "/* Status of peremptory norms under international law */ fixed spelling of \'Wimbledon\'",\n "countryIsoCode": "AU",\n "countryName": "Australia",\n "isAnonymous": 1,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 0,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Peremptory norm",\n "regionIsoCode": "NSW",\n "regionName": "New South Wales",\n "user": "60.225.66.142",\n "delta": 0,\n "added": 0,\n "deleted": 0\n },\n {\n "__time": 1442018828770,\n "channel": "#vi.wikipedia",\n "cityName": "",\n "comment": "fix L\u1ed7i CS1: ng\xe0y th\xe1ng",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 1,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Apamea abruzzorum",\n "regionIsoCode": "",\n "regionName": "",\n "user": "Cheers!-bot",\n "delta": 18,\n "added": 18,\n "deleted": 0\n },\n {\n "__time": 1442018831862,\n "channel": "#vi.wikipedia",\n "cityName": "",\n "comment": "clean up using [[Project:AWB|AWB]]",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Atractus flammigerus",\n "regionIsoCode": "",\n "regionName": "",\n "user": "ThitxongkhoiAWB",\n "delta": 18,\n "added": 18,\n "deleted": 0\n },\n {\n "__time": 1442018833987,\n "channel": "#vi.wikipedia",\n "cityName": "",\n "comment": "clean up using [[Project:AWB|AWB]]",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Agama mossambica",\n "regionIsoCode": "",\n "regionName": "",\n "user": "ThitxongkhoiAWB",\n "delta": 18,\n "added": 18,\n "deleted": 0\n },\n {\n "__time": 1442018837009,\n "channel": "#ca.wikipedia",\n "cityName": "",\n "comment": "/* Imperi Austrohongar\xe8s */",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 0,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Campanya dels Balcans (1914-1918)",\n "regionIsoCode": "",\n "regionName": "",\n "user": "Jaumellecha",\n "delta": -20,\n "added": 0,\n "deleted": 20\n },\n {\n "__time": 1442018839591,\n "channel": "#en.wikipedia",\n "cityName": "",\n "comment": "adding comment on notability and possible COI",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 1,\n "isRobot": 0,\n "isUnpatrolled": 1,\n "metroCode": 0,\n "namespace": "Talk",\n "page": "Talk:Dani Ploeger",\n "regionIsoCode": "",\n "regionName": "",\n "user": "New Media Theorist",\n "delta": 345,\n "added": 345,\n "deleted": 0\n },\n {\n "__time": 1442018841578,\n "channel": "#en.wikipedia",\n "cityName": "",\n "comment": "Copying assessment table to wiki",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "User",\n "page": "User:WP 1.0 bot/Tables/Project/Pubs",\n "regionIsoCode": "",\n "regionName": "",\n "user": "WP 1.0 bot",\n "delta": 121,\n "added": 121,\n "deleted": 0\n },\n {\n "__time": 1442018845821,\n "channel": "#vi.wikipedia",\n "cityName": "",\n "comment": "clean up using [[Project:AWB|AWB]]",\n "countryIsoCode": "",\n "countryName": "",\n "isAnonymous": 0,\n "isMinor": 0,\n "isNew": 0,\n "isRobot": 1,\n "isUnpatrolled": 0,\n "metroCode": 0,\n "namespace": "Main",\n "page": "Agama persimilis",\n "regionIsoCode": "",\n "regionName": "",\n "user": "ThitxongkhoiAWB",\n "delta": 18,\n "added": 18,\n "deleted": 0\n }\n]\n'))),(0,o.kt)("h3",{id:"cancel-a-query-1"},"Cancel a query"),(0,o.kt)("p",null,"Cancels a running or accepted query."),(0,o.kt)("h4",{id:"url-5"},"URL"),(0,o.kt)("code",{class:"deleteAPI"},"DELETE")," ",(0,o.kt)("code",null,"/druid/v2/sql/statements/:queryId"),(0,o.kt)("h4",{id:"responses-5"},"Responses"),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"15",label:"200 OK",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"A no op operation since the query is not in a state to be cancelled"))),(0,o.kt)(s.Z,{value:"16",label:"202 ACCEPTED",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Successfully accepted query for cancellation"))),(0,o.kt)(s.Z,{value:"17",label:"404 SERVER ERROR",mdxType:"TabItem"},(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Invalid query ID. Returns a JSON object detailing the error with the following format:")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "error": "Summary of the encountered error.",\n "errorCode": "Well-defined error code.",\n "persona": "Role or persona associated with the error.",\n "category": "Classification of the error.",\n "errorMessage": "Summary of the encountered issue with expanded information.",\n "context": "Additional context about the error."\n}\n')))),(0,o.kt)("hr",null),(0,o.kt)("h4",{id:"sample-request-5"},"Sample request"),(0,o.kt)("p",null,"The following example cancels a query with specified ID ",(0,o.kt)("inlineCode",{parentName:"p"},"query-945c9633-2fa2-49ab-80ae-8221c38c024da"),"."),(0,o.kt)(l.Z,{mdxType:"Tabs"},(0,o.kt)(s.Z,{value:"18",label:"cURL",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'curl --request DELETE "http://ROUTER_IP:ROUTER_PORT/druid/v2/sql/statements/query-945c9633-2fa2-49ab-80ae-8221c38c024da"\n'))),(0,o.kt)(s.Z,{value:"19",label:"HTTP",mdxType:"TabItem"},(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-HTTP"},"DELETE /druid/v2/sql/statements/query-945c9633-2fa2-49ab-80ae-8221c38c024da HTTP/1.1\nHost: http://ROUTER_IP:ROUTER_PORT\n")))),(0,o.kt)("h4",{id:"sample-response-5"},"Sample response"),(0,o.kt)("p",null,"A successful request returns an HTTP ",(0,o.kt)("inlineCode",{parentName:"p"},"202 ACCEPTED")," message code and an empty response body."))}k.isMDXComponent=!0}}]);