blob: b5b70f24d967f69235e140ee646128109a285a9c [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[2458],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>y});var a=n(67294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},l=Object.keys(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),u=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=u(e.components);return a.createElement(s.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,s=e.parentName,p=i(e,["components","mdxType","originalType","parentName"]),d=u(n),c=r,y=d["".concat(s,".").concat(c)]||d[c]||m[c]||l;return n?a.createElement(y,o(o({ref:t},p),{},{components:n})):a.createElement(y,o({ref:t},p))}));function y(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,o=new Array(l);o[0]=c;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[d]="string"==typeof e?e:r,o[1]=i;for(var u=2;u<l;u++)o[u]=n[u];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}c.displayName="MDXCreateElement"},85162:(e,t,n)=>{n.d(t,{Z:()=>o});var a=n(67294),r=n(86010);const l={tabItem:"tabItem_Ymn6"};function o(e){var t=e.children,n=e.hidden,o=e.className;return a.createElement("div",{role:"tabpanel",className:(0,r.Z)(l.tabItem,o),hidden:n},t)}},74866:(e,t,n)=>{n.d(t,{Z:()=>g});var a=n(87462),r=n(67294),l=n(86010),o=n(12466),i=n(16550),s=n(91980),u=n(67392),p=n(50012);function d(e){return function(e){var t,n;return null!=(t=null==(n=r.Children.map(e,(function(e){if(!e||(0,r.isValidElement)(e)&&(t=e.props)&&"object"==typeof t&&"value"in t)return e;var t;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:n.filter(Boolean))?t:[]}(e).map((function(e){var t=e.props;return{value:t.value,label:t.label,attributes:t.attributes,default:t.default}}))}function m(e){var t=e.values,n=e.children;return(0,r.useMemo)((function(){var e=null!=t?t:d(n);return function(e){var t=(0,u.l)(e,(function(e,t){return e.value===t.value}));if(t.length>0)throw new Error('Docusaurus error: Duplicate values "'+t.map((function(e){return e.value})).join(", ")+'" found in <Tabs>. Every value needs to be unique.')}(e),e}),[t,n])}function c(e){var t=e.value;return e.tabValues.some((function(e){return e.value===t}))}function y(e){var t=e.queryString,n=void 0!==t&&t,a=e.groupId,l=(0,i.k6)(),o=function(e){var t=e.queryString,n=void 0!==t&&t,a=e.groupId;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:a});return[(0,s._X)(o),(0,r.useCallback)((function(e){if(o){var t=new URLSearchParams(l.location.search);t.set(o,e),l.replace(Object.assign({},l.location,{search:t.toString()}))}}),[o,l])]}function h(e){var t,n,a,l,o=e.defaultValue,i=e.queryString,s=void 0!==i&&i,u=e.groupId,d=m(e),h=(0,r.useState)((function(){return function(e){var t,n=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(n){if(!c({value:n,tabValues:a}))throw new Error('Docusaurus error: The <Tabs> has a defaultValue "'+n+'" 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 n}var r=null!=(t=a.find((function(e){return e.default})))?t:a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:o,tabValues:d})})),k=h[0],N=h[1],f=y({queryString:s,groupId:u}),T=f[0],b=f[1],g=(t=function(e){return e?"docusaurus.tab."+e:null}({groupId:u}.groupId),n=(0,p.Nk)(t),a=n[0],l=n[1],[a,(0,r.useCallback)((function(e){t&&l.set(e)}),[t,l])]),v=g[0],q=g[1],C=function(){var e=null!=T?T:v;return c({value:e,tabValues:d})?e:null}();return(0,r.useLayoutEffect)((function(){C&&N(C)}),[C]),{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=n(72389);const N={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};function f(e){var t=e.className,n=e.block,i=e.selectedValue,s=e.selectValue,u=e.tabValues,p=[],d=(0,o.o5)().blockElementScrollPositionUntilNextRender,m=function(e){var t=e.currentTarget,n=p.indexOf(t),a=u[n].value;a!==i&&(d(t),s(a))},c=function(e){var t,n=null;switch(e.key){case"Enter":m(e);break;case"ArrowRight":var a,r=p.indexOf(e.currentTarget)+1;n=null!=(a=p[r])?a:p[0];break;case"ArrowLeft":var l,o=p.indexOf(e.currentTarget)-1;n=null!=(l=p[o])?l:p[p.length-1]}null==(t=n)||t.focus()};return r.createElement("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":n},t)},u.map((function(e){var t=e.value,n=e.label,o=e.attributes;return r.createElement("li",(0,a.Z)({role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,key:t,ref:function(e){return p.push(e)},onKeyDown:c,onClick:m},o,{className:(0,l.Z)("tabs__item",N.tabItem,null==o?void 0:o.className,{"tabs__item--active":i===t})}),null!=n?n:t)})))}function T(e){var t=e.lazy,n=e.children,a=e.selectedValue,l=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){var o=l.find((function(e){return e.props.value===a}));return o?(0,r.cloneElement)(o,{className:"margin-top--md"}):null}return r.createElement("div",{className:"margin-top--md"},l.map((function(e,t){return(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})})))}function b(e){var t=h(e);return r.createElement("div",{className:(0,l.Z)("tabs-container",N.tabList)},r.createElement(f,(0,a.Z)({},e,t)),r.createElement(T,(0,a.Z)({},e,t)))}function g(e){var t=(0,k.Z)();return r.createElement(b,(0,a.Z)({key:String(t)},e))}},40290:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>m,contentTitle:()=>p,default:()=>k,frontMatter:()=>u,metadata:()=>d,toc:()=>c});var a=n(87462),r=n(63366),l=(n(67294),n(3905)),o=n(74866),i=n(85162),s=["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/27.0.0/api-reference/sql-api.md",sourceDirName:"api-reference",slug:"/api-reference/sql-api",permalink:"/docs/27.0.0/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/27.0.0/api-reference/"},next:{title:"SQL-based ingestion",permalink:"/docs/27.0.0/api-reference/sql-ingestion-api"}},m={},c=[{value:"Submit a query",id:"submit-a-query",level:2},{value:"Request body",id:"request-body",level:3},{value:"Responses",id:"responses",level:3},{value:"Result formats",id:"result-formats",level:4},{value:"Errors",id:"errors",level:4},{value:"Cancel a query",id:"cancel-a-query",level:2},{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",level:4},{value:"Request body",id:"request-body-1",level:4},{value:"Responses",id:"responses-1",level:4},{value:"Sample request",id:"sample-request",level:4},{value:"Sample response",id:"sample-response",level:4},{value:"Get query status",id:"get-query-status",level:3},{value:"URL",id:"url-1",level:4},{value:"Responses",id:"responses-2",level:4},{value:"Sample request",id:"sample-request-1",level:4},{value:"Sample response",id:"sample-response-1",level:4},{value:"Get query results",id:"get-query-results",level:3},{value:"URL",id:"url-2",level:4},{value:"Query parameters",id:"query-parameters",level:4},{value:"Responses",id:"responses-3",level:4},{value:"Sample request",id:"sample-request-2",level:4},{value:"Sample response",id:"sample-response-2",level:4},{value:"Cancel a query",id:"cancel-a-query-1",level:3},{value:"URL",id:"url-3",level:4},{value:"Responses",id:"responses-4",level:4},{value:"Sample request",id:"sample-request-3",level:4},{value:"Sample response",id:"sample-response-3",level:4}],y={toc:c},h="wrapper";function k(e){var t=e.components,n=(0,r.Z)(e,s);return(0,l.kt)(h,(0,a.Z)({},y,n,{components:t,mdxType:"MDXLayout"}),(0,l.kt)("admonition",{type:"info"},(0,l.kt)("p",{parentName:"admonition"}," Apache Druid supports two query languages: Druid SQL and ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/"},"native queries"),".\nThis document describes the SQL language.")),(0,l.kt)("p",null,"You can submit and cancel ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql"},"Druid SQL")," queries using the Druid SQL API.\nThe Druid SQL API is available at ",(0,l.kt)("inlineCode",{parentName:"p"},"https://ROUTER:8888/druid/v2/sql"),", where ",(0,l.kt)("inlineCode",{parentName:"p"},"ROUTER")," is the IP address of the Druid Router."),(0,l.kt)("h2",{id:"submit-a-query"},"Submit a query"),(0,l.kt)("p",null,"To use the SQL API to make Druid SQL queries, send your query to the Router using the POST method:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"POST https://ROUTER:8888/druid/v2/sql/\n")),(0,l.kt)("p",null,'Submit your query as the value of a "query" field in the JSON object within the request payload. For example:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json"},'{"query" : "SELECT COUNT(*) FROM data_source WHERE foo = \'bar\'"}\n')),(0,l.kt)("h3",{id:"request-body"},"Request body"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Property"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"),(0,l.kt)("th",{parentName:"tr",align:null},"Default"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"query")),(0,l.kt)("td",{parentName:"tr",align:null},"SQL query string."),(0,l.kt)("td",{parentName:"tr",align:null},"none (required)")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"resultFormat")),(0,l.kt)("td",{parentName:"tr",align:null},"Format of query results. See ",(0,l.kt)("a",{parentName:"td",href:"#responses"},"Responses")," for details."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},'"object"'))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"header")),(0,l.kt)("td",{parentName:"tr",align:null},"Whether or not to include a header row for the query result. See ",(0,l.kt)("a",{parentName:"td",href:"#responses"},"Responses")," for details."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"false"))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"typesHeader")),(0,l.kt)("td",{parentName:"tr",align:null},"Whether or not to include type information in the header. Can only be set when ",(0,l.kt)("inlineCode",{parentName:"td"},"header")," is also ",(0,l.kt)("inlineCode",{parentName:"td"},"true"),". See ",(0,l.kt)("a",{parentName:"td",href:"#responses"},"Responses")," for details."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"false"))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"sqlTypesHeader")),(0,l.kt)("td",{parentName:"tr",align:null},"Whether or not to include SQL type information in the header. Can only be set when ",(0,l.kt)("inlineCode",{parentName:"td"},"header")," is also ",(0,l.kt)("inlineCode",{parentName:"td"},"true"),". See ",(0,l.kt)("a",{parentName:"td",href:"#responses"},"Responses")," for details."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"false"))),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"context")),(0,l.kt)("td",{parentName:"tr",align:null},"JSON object containing ",(0,l.kt)("a",{parentName:"td",href:"/docs/27.0.0/querying/sql-query-context"},"SQL query context parameters"),"."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"{}")," (empty)")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"parameters")),(0,l.kt)("td",{parentName:"tr",align:null},"List of query parameters for parameterized queries. Each parameter in the list should be a JSON object like ",(0,l.kt)("inlineCode",{parentName:"td"},'{"type": "VARCHAR", "value": "foo"}'),". The type should be a SQL type; see ",(0,l.kt)("a",{parentName:"td",href:"/docs/27.0.0/querying/sql-data-types"},"Data types")," for a list of supported SQL types."),(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"[]")," (empty)")))),(0,l.kt)("p",null,"You can use ",(0,l.kt)("em",{parentName:"p"},"curl")," to send SQL queries from the command-line:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},'$ cat query.json\n{"query":"SELECT COUNT(*) AS TheCount FROM data_source"}\n\n$ curl -XPOST -H\'Content-Type: application/json\' http://ROUTER:8888/druid/v2/sql/ -d @query.json\n[{"TheCount":24433}]\n')),(0,l.kt)("p",null,"There are a variety of ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-query-context"},"SQL query context parameters"),' you can provide by adding a "context" map,\nlike:'),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json"},'{\n "query" : "SELECT COUNT(*) FROM data_source WHERE foo = \'bar\' AND __time > TIMESTAMP \'2000-01-01 00:00:00\'",\n "context" : {\n "sqlTimeZone" : "America/Los_Angeles"\n }\n}\n')),(0,l.kt)("p",null,"Parameterized SQL queries are also supported:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json"},'{\n "query" : "SELECT COUNT(*) FROM data_source WHERE foo = ? AND __time > ?",\n "parameters": [\n { "type": "VARCHAR", "value": "bar"},\n { "type": "TIMESTAMP", "value": "2000-01-01 00:00:00" }\n ]\n}\n')),(0,l.kt)("p",null,"Metadata is available over HTTP POST by querying ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-metadata-tables"},"metadata tables"),"."),(0,l.kt)("h3",{id:"responses"},"Responses"),(0,l.kt)("h4",{id:"result-formats"},"Result formats"),(0,l.kt)("p",null,"Druid SQL's HTTP POST API supports a variety of result formats. You can specify these by adding a ",(0,l.kt)("inlineCode",{parentName:"p"},"resultFormat")," parameter, like:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json"},'{\n "query" : "SELECT COUNT(*) FROM data_source WHERE foo = \'bar\' AND __time > TIMESTAMP \'2000-01-01 00:00:00\'",\n "resultFormat" : "array"\n}\n')),(0,l.kt)("p",null,"To request a header with information about column names, set ",(0,l.kt)("inlineCode",{parentName:"p"},"header")," to true in your request.\nWhen you set ",(0,l.kt)("inlineCode",{parentName:"p"},"header")," to true, you can optionally include ",(0,l.kt)("inlineCode",{parentName:"p"},"typesHeader")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," as well, which gives\nyou information about ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-data-types"},"Druid runtime and SQL types")," respectively. You can request all these headers\nwith a request like:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-json"},'{\n "query" : "SELECT COUNT(*) FROM data_source WHERE foo = \'bar\' AND __time > TIMESTAMP \'2000-01-01 00:00:00\'",\n "resultFormat" : "array",\n "header" : true,\n "typesHeader" : true,\n "sqlTypesHeader" : true\n}\n')),(0,l.kt)("p",null,"The following table shows supported result formats:"),(0,l.kt)("table",null,(0,l.kt)("thead",{parentName:"table"},(0,l.kt)("tr",{parentName:"thead"},(0,l.kt)("th",{parentName:"tr",align:null},"Format"),(0,l.kt)("th",{parentName:"tr",align:null},"Description"),(0,l.kt)("th",{parentName:"tr",align:null},"Header description"),(0,l.kt)("th",{parentName:"tr",align:null},"Content-Type"))),(0,l.kt)("tbody",{parentName:"table"},(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"object")),(0,l.kt)("td",{parentName:"tr",align:null},"The default, a JSON array of JSON objects. Each object's field names match the columns returned by the SQL query, and are provided in the same order as the SQL query."),(0,l.kt)("td",{parentName:"tr",align:null},"If ",(0,l.kt)("inlineCode",{parentName:"td"},"header")," is true, the first row is an object where the fields are column names. Each field's value is either null (if ",(0,l.kt)("inlineCode",{parentName:"td"},"typesHeader")," and ",(0,l.kt)("inlineCode",{parentName:"td"},"sqlTypesHeader")," are false) or an object that contains the Druid type as ",(0,l.kt)("inlineCode",{parentName:"td"},"type")," (if ",(0,l.kt)("inlineCode",{parentName:"td"},"typesHeader")," is true) and the SQL type as ",(0,l.kt)("inlineCode",{parentName:"td"},"sqlType")," (if ",(0,l.kt)("inlineCode",{parentName:"td"},"sqlTypesHeader")," is true)."),(0,l.kt)("td",{parentName:"tr",align:null},"application/json")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"array")),(0,l.kt)("td",{parentName:"tr",align:null},"JSON array of JSON arrays. Each inner array has elements matching the columns returned by the SQL query, in order."),(0,l.kt)("td",{parentName:"tr",align:null},"If ",(0,l.kt)("inlineCode",{parentName:"td"},"header")," is true, the first row is an array of column names. If ",(0,l.kt)("inlineCode",{parentName:"td"},"typesHeader")," is true, the next row is an array of Druid types. If ",(0,l.kt)("inlineCode",{parentName:"td"},"sqlTypesHeader")," is true, the next row is an array of SQL types."),(0,l.kt)("td",{parentName:"tr",align:null},"application/json")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"objectLines")),(0,l.kt)("td",{parentName:"tr",align:null},"Like ",(0,l.kt)("inlineCode",{parentName:"td"},"object"),", but the JSON objects are separated by newlines instead of being wrapped in a JSON array. This can make it easier to parse the entire response set as a stream, if you do not have ready access to a streaming JSON parser. To make it possible to detect a truncated response, this format includes a trailer of one blank line."),(0,l.kt)("td",{parentName:"tr",align:null},"Same as ",(0,l.kt)("inlineCode",{parentName:"td"},"object"),"."),(0,l.kt)("td",{parentName:"tr",align:null},"text/plain")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"arrayLines")),(0,l.kt)("td",{parentName:"tr",align:null},"Like ",(0,l.kt)("inlineCode",{parentName:"td"},"array"),", but the JSON arrays are separated by newlines instead of being wrapped in a JSON array. This can make it easier to parse the entire response set as a stream, if you do not have ready access to a streaming JSON parser. To make it possible to detect a truncated response, this format includes a trailer of one blank line."),(0,l.kt)("td",{parentName:"tr",align:null},"Same as ",(0,l.kt)("inlineCode",{parentName:"td"},"array"),", except the rows are separated by newlines."),(0,l.kt)("td",{parentName:"tr",align:null},"text/plain")),(0,l.kt)("tr",{parentName:"tbody"},(0,l.kt)("td",{parentName:"tr",align:null},(0,l.kt)("inlineCode",{parentName:"td"},"csv")),(0,l.kt)("td",{parentName:"tr",align:null},"Comma-separated values, with one row per line. Individual field values may be escaped by being surrounded in double quotes. If double quotes appear in a field value, they will be escaped by replacing them with double-double-quotes like ",(0,l.kt)("inlineCode",{parentName:"td"},'""this""'),". To make it possible to detect a truncated response, this format includes a trailer of one blank line."),(0,l.kt)("td",{parentName:"tr",align:null},"Same as ",(0,l.kt)("inlineCode",{parentName:"td"},"array"),", except the lists are in CSV format."),(0,l.kt)("td",{parentName:"tr",align:null},"text/csv")))),(0,l.kt)("p",null,"If ",(0,l.kt)("inlineCode",{parentName:"p"},"typesHeader")," is set to true, ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-data-types"},"Druid type")," information is included in the response. Complex types,\nlike sketches, will be reported as ",(0,l.kt)("inlineCode",{parentName:"p"},"COMPLEX<typeName>")," if a particular complex type name is known for that field,\nor as ",(0,l.kt)("inlineCode",{parentName:"p"},"COMPLEX")," if the particular type name is unknown or mixed. If ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," is set to true,\n",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-data-types"},"SQL type")," information is included in the response. It is possible to set both ",(0,l.kt)("inlineCode",{parentName:"p"},"typesHeader")," and\n",(0,l.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," at once. Both parameters require that ",(0,l.kt)("inlineCode",{parentName:"p"},"header")," is also set."),(0,l.kt)("p",null,"To aid in building clients that are compatible with older Druid versions, Druid returns the HTTP header\n",(0,l.kt)("inlineCode",{parentName:"p"},"X-Druid-SQL-Header-Included: yes")," if ",(0,l.kt)("inlineCode",{parentName:"p"},"header")," was set to true and if the version of Druid the client is connected to\nunderstands the ",(0,l.kt)("inlineCode",{parentName:"p"},"typesHeader")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," parameters. This HTTP response header is present irrespective of\nwhether ",(0,l.kt)("inlineCode",{parentName:"p"},"typesHeader")," or ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlTypesHeader")," are set or not."),(0,l.kt)("p",null,"Druid returns the SQL query identifier in the ",(0,l.kt)("inlineCode",{parentName:"p"},"X-Druid-SQL-Query-Id")," HTTP header.\nThis query id will be assigned the value of ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," from the ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/sql-query-context"},"query context parameters"),"\nif specified, else Druid will generate a SQL query id for you."),(0,l.kt)("h4",{id:"errors"},"Errors"),(0,l.kt)("p",null,"Errors that occur before the response body is sent will be reported in JSON, with an HTTP 500 status code, in the\nsame format as ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/#query-errors"},"native Druid query errors"),". If an error occurs while the response body is\nbeing sent, at that point it is too late to change the HTTP status code or report a JSON error, so the response will\nsimply end midstream and an error will be logged by the Druid server that was handling your request."),(0,l.kt)("p",null,"As a caller, it is important that you properly handle response truncation. This is easy for the ",(0,l.kt)("inlineCode",{parentName:"p"},"object")," and ",(0,l.kt)("inlineCode",{parentName:"p"},"array"),"\nformats, since truncated responses will be invalid JSON. For the line-oriented formats, you should check the\ntrailer they all include: one blank line at the end of the result set. If you detect a truncated response, either\nthrough a JSON parsing error or through a missing trailing newline, you should assume the response was not fully\ndelivered due to an error."),(0,l.kt)("h2",{id:"cancel-a-query"},"Cancel a query"),(0,l.kt)("p",null,"You can use the HTTP DELETE method to cancel a SQL query on either the Router or the Broker. When you cancel a query, Druid handles the cancellation in a best-effort manner. It marks the query canceled immediately and aborts the query execution as soon as possible. However, your query may run for a short time after your cancellation request."),(0,l.kt)("p",null,"Druid SQL's HTTP DELETE method uses the following syntax:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre"},"DELETE https://ROUTER:8888/druid/v2/sql/{sqlQueryId}\n")),(0,l.kt)("p",null,"The DELETE method requires the ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," path parameter. To predict the query id you must set it in the query context. Druid does not enforce unique ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," in the query context. If you issue a cancel request for a ",(0,l.kt)("inlineCode",{parentName:"p"},"sqlQueryId")," active in more than one query context, Druid cancels all requests that use the query id."),(0,l.kt)("p",null,"For example if you issue the following query:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},'curl --request POST \'https://ROUTER:8888/druid/v2/sql\' \\\n--header \'Content-Type: application/json\' \\\n--data-raw \'{"query" : "SELECT sleep(CASE WHEN sum_added > 0 THEN 1 ELSE 0 END) FROM wikiticker WHERE sum_added > 0 LIMIT 15",\n"context" : {"sqlQueryId" : "myQuery01"}}\'\n')),(0,l.kt)("p",null,"You can cancel the query using the query id ",(0,l.kt)("inlineCode",{parentName:"p"},"myQuery01")," as follows:"),(0,l.kt)("pre",null,(0,l.kt)("code",{parentName:"pre",className:"language-bash"},"curl --request DELETE 'https://ROUTER:8888/druid/v2/sql/myQuery01' \\\n")),(0,l.kt)("p",null,"Cancellation requests require READ permission on all resources used in the SQL query."),(0,l.kt)("p",null,"Druid returns an HTTP 202 response for successful deletion requests."),(0,l.kt)("p",null,"Druid returns an HTTP 404 response in the following cases:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"sqlQueryId")," is incorrect."),(0,l.kt)("li",{parentName:"ul"},"The query completes before your cancellation request is processed.")),(0,l.kt)("p",null,"Druid returns an HTTP 403 response for authorization failure."),(0,l.kt)("h2",{id:"query-from-deep-storage"},"Query from deep storage"),(0,l.kt)("blockquote",null,(0,l.kt)("p",{parentName:"blockquote"},"Query from deep storage is an ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/development/experimental"},"experimental feature"),".")),(0,l.kt)("p",null,"You can use the ",(0,l.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,l.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,l.kt)("p",null,"For more information, see ",(0,l.kt)("a",{parentName:"p",href:"/docs/27.0.0/querying/query-deep-storage"},"Query from deep storage"),"."),(0,l.kt)("h3",{id:"submit-a-query-1"},"Submit a query"),(0,l.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,l.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,l.kt)("h4",{id:"url"},"URL"),(0,l.kt)("code",{class:"postAPI"},"POST")," ",(0,l.kt)("code",null,"/druid/v2/sql/statements"),(0,l.kt)("h4",{id:"request-body-1"},"Request body"),(0,l.kt)("p",null,"Generally, the ",(0,l.kt)("inlineCode",{parentName:"p"},"sql")," and ",(0,l.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,l.kt)("a",{parentName:"p",href:"#submit-a-query"},"Submit a query to the ",(0,l.kt)("inlineCode",{parentName:"a"},"sql")," endpoint"),"."),(0,l.kt)("p",null,"Keep the following in mind when submitting queries to the ",(0,l.kt)("inlineCode",{parentName:"p"},"sql/statements")," endpoint:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("p",{parentName:"li"},"There are additional context parameters for ",(0,l.kt)("inlineCode",{parentName:"p"},"sql/statements"),":"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"executionMode")," determines how query results are fetched. Druid currently only supports ",(0,l.kt)("inlineCode",{parentName:"li"},"ASYNC"),". You must manually retrieve your results after the query completes."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"selectDestination")," determines where final results get written. By default, results are written to task reports. Set this parameter to ",(0,l.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. Note that this requires you to have ",(0,l.kt)("a",{parentName:"li",href:"/docs/27.0.0/operations/durable-storage"},"durable storage for MSQ enabled"),"."))),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("p",{parentName:"li"},"The only supported value for ",(0,l.kt)("inlineCode",{parentName:"p"},"resultFormat")," is JSON LINES."))),(0,l.kt)("h4",{id:"responses-1"},"Responses"),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"1",label:"200 SUCCESS",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Successfully queried from deep storage"))),(0,l.kt)(i.Z,{value:"2",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,l.kt)("pre",null,(0,l.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,l.kt)("hr",null),(0,l.kt)("h4",{id:"sample-request"},"Sample request"),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"3",label:"cURL",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)(i.Z,{value:"4",label:"HTTP",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)("h4",{id:"sample-response"},"Sample response"),(0,l.kt)("details",null,(0,l.kt)("summary",null,"Click to show sample response"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"get-query-status"},"Get query status"),(0,l.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,l.kt)("inlineCode",{parentName:"p"},"ASYNC"),". In addition to the fields that this endpoint shares with ",(0,l.kt)("inlineCode",{parentName:"p"},"POST /sql/statements"),", a completed query's status includes the following:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"A ",(0,l.kt)("inlineCode",{parentName:"li"},"result")," object that summarizes information about your results, such as the total number of rows and sample records."),(0,l.kt)("li",{parentName:"ul"},"A ",(0,l.kt)("inlineCode",{parentName:"li"},"pages")," object that includes the following information for each page of results:",(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"numRows"),": the number of rows in that page of results."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"sizeInBytes"),": the size of the page."),(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"id"),": the page number that you can use to reference a specific page when you get query results.")))),(0,l.kt)("h4",{id:"url-1"},"URL"),(0,l.kt)("code",{class:"getAPI"},"GET")," ",(0,l.kt)("code",null,"/druid/v2/sql/statements/:queryId"),(0,l.kt)("h4",{id:"responses-2"},"Responses"),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"5",label:"200 SUCCESS",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Successfully retrieved query status"))),(0,l.kt)(i.Z,{value:"6",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,l.kt)("pre",null,(0,l.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,l.kt)("h4",{id:"sample-request-1"},"Sample request"),(0,l.kt)("p",null,"The following example retrieves the status of a query with specified ID ",(0,l.kt)("inlineCode",{parentName:"p"},"query-9b93f6f7-ab0e-48f5-986a-3520f84f0804"),"."),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"7",label:"cURL",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)(i.Z,{value:"8",label:"HTTP",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)("h4",{id:"sample-response-1"},"Sample response"),(0,l.kt)("details",null,(0,l.kt)("summary",null,"Click to show sample response"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"get-query-results"},"Get query results"),(0,l.kt)("p",null,"Retrieves results for completed queries. Results are separated into pages, so you can use the optional ",(0,l.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,l.kt)("inlineCode",{parentName:"p"},"id"),"). For information about pages, see ",(0,l.kt)("a",{parentName:"p",href:"#get-query-status"},"Get query status"),"."),(0,l.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,l.kt)("inlineCode",{parentName:"p"},"druid.router.http.readTimeout"),"."),(0,l.kt)("p",null,"When getting query results, keep the following in mind:"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},"JSON Lines is the only supported result format."),(0,l.kt)("li",{parentName:"ul"},"Getting the query results for an ingestion query returns an empty response.")),(0,l.kt)("h4",{id:"url-2"},"URL"),(0,l.kt)("code",{class:"getAPI"},"GET")," ",(0,l.kt)("code",null,"/druid/v2/sql/statements/:queryId/results"),(0,l.kt)("h4",{id:"query-parameters"},"Query parameters"),(0,l.kt)("ul",null,(0,l.kt)("li",{parentName:"ul"},(0,l.kt)("inlineCode",{parentName:"li"},"page"),(0,l.kt)("ul",{parentName:"li"},(0,l.kt)("li",{parentName:"ul"},"Int (optional)"),(0,l.kt)("li",{parentName:"ul"},"Refine paginated results")))),(0,l.kt)("h4",{id:"responses-3"},"Responses"),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"9",label:"200 SUCCESS",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Successfully retrieved query results"))),(0,l.kt)(i.Z,{value:"10",label:"400 BAD REQUEST",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Query in progress. Returns a JSON object detailing the error with the following format:")),(0,l.kt)("pre",null,(0,l.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,l.kt)(i.Z,{value:"11",label:"404 NOT FOUND",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Query not found, failed or canceled"))),(0,l.kt)(i.Z,{value:"12",label:"500 SERVER ERROR",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Error thrown due to bad query. Returns a JSON object detailing the error with the following format:")),(0,l.kt)("pre",null,(0,l.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,l.kt)("hr",null),(0,l.kt)("h4",{id:"sample-request-2"},"Sample request"),(0,l.kt)("p",null,"The following example retrieves the status of a query with specified ID ",(0,l.kt)("inlineCode",{parentName:"p"},"query-f3bca219-173d-44d4-bdc7-5002e910352f"),"."),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"13",label:"cURL",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)(i.Z,{value:"14",label:"HTTP",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)("h4",{id:"sample-response-2"},"Sample response"),(0,l.kt)("details",null,(0,l.kt)("summary",null,"Click to show sample response"),(0,l.kt)("pre",null,(0,l.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,l.kt)("h3",{id:"cancel-a-query-1"},"Cancel a query"),(0,l.kt)("p",null,"Cancels a running or accepted query."),(0,l.kt)("h4",{id:"url-3"},"URL"),(0,l.kt)("code",{class:"deleteAPI"},"DELETE")," ",(0,l.kt)("code",null,"/druid/v2/sql/statements/:queryId"),(0,l.kt)("h4",{id:"responses-4"},"Responses"),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"15",label:"200 OK",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"A no op operation since the query is not in a state to be cancelled"))),(0,l.kt)(i.Z,{value:"16",label:"202 ACCEPTED",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Successfully accepted query for cancellation"))),(0,l.kt)(i.Z,{value:"17",label:"404 SERVER ERROR",mdxType:"TabItem"},(0,l.kt)("p",null,(0,l.kt)("em",{parentName:"p"},"Invalid query ID. Returns a JSON object detailing the error with the following format:")),(0,l.kt)("pre",null,(0,l.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,l.kt)("hr",null),(0,l.kt)("h4",{id:"sample-request-3"},"Sample request"),(0,l.kt)("p",null,"The following example cancels a query with specified ID ",(0,l.kt)("inlineCode",{parentName:"p"},"query-945c9633-2fa2-49ab-80ae-8221c38c024da"),"."),(0,l.kt)(o.Z,{mdxType:"Tabs"},(0,l.kt)(i.Z,{value:"18",label:"cURL",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)(i.Z,{value:"19",label:"HTTP",mdxType:"TabItem"},(0,l.kt)("pre",null,(0,l.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,l.kt)("h4",{id:"sample-response-3"},"Sample response"),(0,l.kt)("p",null,"A successful request returns a ",(0,l.kt)("inlineCode",{parentName:"p"},"202 ACCEPTED")," response and an empty response."))}k.isMDXComponent=!0}}]);