Currently, I am updating Cursor::_stream_query() from db/api.py function as per my requirement. Is there any way (like callbacks, etc) that we can send our custom payload and headers to PyDruid without such code-customization ?
Updated Code:
def _stream_query(self, query):
self.description = None
headers = {'Content-Type': 'application/json',
'x-functions-key': 'eyJ0eXAiOiJKV1QiLCJhbGciOiABC123ABC123',
'session_id': '1234567'}
payload = {
"info": {
"offering": "ABC_offering",
"tenant": "tenant_1"
},
"maxRowCount": 100,
"outputFormat": "JSON",
"queryId": str(uuid.uuid4()),
"queryType": "druid",
"request": "executeQuery",
"sql": query,
"header" : "true"
}
# Streaming = False, RAL won't stream response
r = requests.post(self.url, stream=False, headers=headers, json=payload)
if r.encoding is None:
r.encoding = 'utf-8'
# raise any error messages
if r.status_code != 200:
payload = r.json()
msg = (
'{error} ({errorClass}): {errorMessage}'.format(**payload)
)
raise exceptions.ProgrammingError(msg)
data = json.loads(r.text, object_pairs_hook=OrderedDict)
Row = None
# Note: Reading directly from param "result"
for row in data["result"]:
# update description
if self.description is None:
self.description = get_description_from_row(row)
# header is true, Skip the first row
continue
# return row in namedtuple
if Row is None:
Row = namedtuple('Row', row.keys(), rename=True)
yield Row(*row.values())
Currently, we are having REST API Layer (RAL) on top of Druid and our app( SQLAlchemy based) sends query through RAL.
RAL is expecting,
info
,maxRowCount
,etc (Refer below)code
,elapse
,etc (Refer below)Sample HTTP request: [Actual query to be executed is under
sql
param]Sample HTTP response: [Actual result received is under
result
param]Currently, I am updating
Cursor::_stream_query()
fromdb/api.py
function as per my requirement. Is there any way (like callbacks, etc) that we can send our custom payload and headers to PyDruid without such code-customization ?Updated Code: