MXS-3295: Fix layout of the classify endpoint
The values were stored in the parameters object which is used for configuration parameters in other endpoints. The proper place for them is inside the attributes object.
This commit is contained in:
@ -606,7 +606,6 @@ GET /v1/maxscale/query_classifier/classify?sql=SELECT+1
|
|||||||
"id": "classify",
|
"id": "classify",
|
||||||
"type": "classify",
|
"type": "classify",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"parameters": {
|
|
||||||
"parse_result": "QC_QUERY_PARSED",
|
"parse_result": "QC_QUERY_PARSED",
|
||||||
"type_mask": "QUERY_TYPE_READ",
|
"type_mask": "QUERY_TYPE_READ",
|
||||||
"operation": "QUERY_OP_SELECT",
|
"operation": "QUERY_OP_SELECT",
|
||||||
@ -616,5 +615,4 @@ GET /v1/maxscale/query_classifier/classify?sql=SELECT+1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
require('./common.js')()
|
require('./common.js')()
|
||||||
|
|
||||||
const classify_fields = [
|
const classify_fields = [
|
||||||
{'Parse result': 'attributes.parameters.parse_result'},
|
{'Parse result': 'attributes.parse_result'},
|
||||||
{'Type mask': 'attributes.parameters.type_mask'},
|
{'Type mask': 'attributes.type_mask'},
|
||||||
{'Operation': 'attributes.parameters.operation'},
|
{'Operation': 'attributes.operation'},
|
||||||
{'Has where clause': 'attributes.parameters.has_where_clause'},
|
{'Has where clause': 'attributes.has_where_clause'},
|
||||||
{'Fields': 'attributes.parameters.fields'},
|
{'Fields': 'attributes.fields'},
|
||||||
{'Functions': 'attributes.parameters.functions'}
|
{'Functions': 'attributes.functions'}
|
||||||
]
|
]
|
||||||
|
|
||||||
exports.command = 'classify <statement>'
|
exports.command = 'classify <statement>'
|
||||||
@ -28,12 +28,12 @@ exports.handler = function (argv) {
|
|||||||
return doRequest(host,
|
return doRequest(host,
|
||||||
'maxscale/query_classifier/classify?sql=' + argv.statement,
|
'maxscale/query_classifier/classify?sql=' + argv.statement,
|
||||||
(res) => {
|
(res) => {
|
||||||
if (res.data.attributes.parameters.functions) {
|
if (res.data.attributes.functions) {
|
||||||
var a = res.data.attributes.parameters.functions.map((f) => {
|
var a = res.data.attributes.functions.map((f) => {
|
||||||
return f.name + ': (' + f.arguments.join(', ') + ')'
|
return f.name + ': (' + f.arguments.join(', ') + ')'
|
||||||
});
|
});
|
||||||
|
|
||||||
res.data.attributes.parameters.functions = a;
|
res.data.attributes.functions = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatResource(classify_fields, res.data)
|
return formatResource(classify_fields, res.data)
|
||||||
|
@ -1518,32 +1518,30 @@ void append_function_info(json_t* pParams, GWBUF* pBuffer)
|
|||||||
|
|
||||||
std::unique_ptr<json_t> qc_classify_as_json(const char* zHost, const std::string& statement)
|
std::unique_ptr<json_t> qc_classify_as_json(const char* zHost, const std::string& statement)
|
||||||
{
|
{
|
||||||
json_t* pParams = json_object();
|
json_t* pAttributes = json_object();
|
||||||
|
|
||||||
std::unique_ptr<GWBUF> sBuffer(modutil_create_query(statement.c_str()));
|
std::unique_ptr<GWBUF> sBuffer(modutil_create_query(statement.c_str()));
|
||||||
GWBUF* pBuffer = sBuffer.get();
|
GWBUF* pBuffer = sBuffer.get();
|
||||||
|
|
||||||
qc_parse_result result = qc_parse(pBuffer, QC_COLLECT_ALL);
|
qc_parse_result result = qc_parse(pBuffer, QC_COLLECT_ALL);
|
||||||
|
|
||||||
json_object_set_new(pParams, CN_PARSE_RESULT, json_string(qc_result_to_string(result)));
|
json_object_set_new(pAttributes, CN_PARSE_RESULT, json_string(qc_result_to_string(result)));
|
||||||
|
|
||||||
if (result != QC_QUERY_INVALID)
|
if (result != QC_QUERY_INVALID)
|
||||||
{
|
{
|
||||||
char* zType_mask = qc_typemask_to_string(qc_get_type_mask(pBuffer));
|
char* zType_mask = qc_typemask_to_string(qc_get_type_mask(pBuffer));
|
||||||
json_object_set_new(pParams, CN_TYPE_MASK, json_string(zType_mask));
|
json_object_set_new(pAttributes, CN_TYPE_MASK, json_string(zType_mask));
|
||||||
MXS_FREE(zType_mask);
|
MXS_FREE(zType_mask);
|
||||||
|
|
||||||
json_object_set_new(pParams, CN_OPERATION, json_string(qc_op_to_string(qc_get_operation(pBuffer))));
|
json_object_set_new(pAttributes, CN_OPERATION,
|
||||||
|
json_string(qc_op_to_string(qc_get_operation(pBuffer))));
|
||||||
bool has_clause = qc_query_has_clause(pBuffer);
|
bool has_clause = qc_query_has_clause(pBuffer);
|
||||||
json_object_set_new(pParams, CN_HAS_WHERE_CLAUSE, json_boolean(has_clause));
|
json_object_set_new(pAttributes, CN_HAS_WHERE_CLAUSE, json_boolean(has_clause));
|
||||||
|
|
||||||
append_field_info(pParams, pBuffer);
|
append_field_info(pAttributes, pBuffer);
|
||||||
append_function_info(pParams, pBuffer);
|
append_function_info(pAttributes, pBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* pAttributes = json_object();
|
|
||||||
json_object_set_new(pAttributes, CN_PARAMETERS, pParams);
|
|
||||||
|
|
||||||
json_t* pSelf = json_object();
|
json_t* pSelf = json_object();
|
||||||
json_object_set_new(pSelf, CN_ID, json_string(CN_CLASSIFY));
|
json_object_set_new(pSelf, CN_ID, json_string(CN_CLASSIFY));
|
||||||
json_object_set_new(pSelf, CN_TYPE, json_string(CN_CLASSIFY));
|
json_object_set_new(pSelf, CN_TYPE, json_string(CN_CLASSIFY));
|
||||||
|
Reference in New Issue
Block a user