1
0
Fork 0

explain bind param support, view + aardvark

This commit is contained in:
hkernbach 2015-11-17 13:24:21 +01:00
parent bb814f1c5d
commit 068bee4c80
2 changed files with 112 additions and 95 deletions

View File

@ -170,11 +170,17 @@ controller.post("disableVersionCheck", function(req, res) {
*/
controller.post("/query/explain", function(req, res) {
var explain, query = req.body().query;
var explain, query = req.body().query,
bindVars = req.body().bindVars;
if (query.length > 0) {
try {
explain = require("org/arangodb/aql/explainer").explain(query, {colors: false}, false);
if (bindVars) {
explain = require("org/arangodb/aql/explainer").explain(query, {colors: false}, false, bindVars);
}
else {
explain = require("org/arangodb/aql/explainer").explain(query, {colors: false}, false);
}
}
catch (e) {
explain = JSON.stringify(e);

View File

@ -102,7 +102,7 @@
inputEditor = ace.edit("aqlEditor"),
varsEditor = ace.edit("varsEditor");
inputEditor.setValue(this.getCustomQueryValueByName(queryName));
varsEditor.setValue(this.getCustomQueryParameterByName(queryName));
varsEditor.setValue(JSON.stringify(this.getCustomQueryParameterByName(queryName)));
this.deselect(varsEditor);
this.deselect(inputEditor);
$('#querySelect').val(queryName);
@ -541,6 +541,14 @@
bindVars = '{}';
}
if (typeof bindVars === 'string') {
try {
bindVars = JSON.parse(bindVars);
}
catch (err) {
console.log("could not parse bind parameter");
}
}
this.collection.add({
name: saveName,
parameter: bindVars,
@ -672,6 +680,7 @@
};
var bindVars = varsEditor.getValue();
if (bindVars.length > 0) {
try {
var params = JSON.parse(bindVars);
@ -681,6 +690,7 @@
}
catch (e) {
arangoHelper.arangoError("Query error", "Could not parse bind parameters.");
return false;
}
}
return JSON.stringify(data);
@ -859,42 +869,47 @@
var self = this;
var outputEditor = ace.edit("queryOutput");
var queryData = this.readQueryData();
$('.queryExecutionTime').text('');
window.progressView.show(
"Explain is operating..."
);
this.execPending = false;
$.ajax({
type: "POST",
url: "/_admin/aardvark/query/explain/",
data: this.readQueryData(),
contentType: "application/json",
processData: false,
success: function (data) {
outputEditor.setValue(data.msg);
self.switchTab("result-switch");
window.progressView.hide();
self.deselect(outputEditor);
$('#downloadQueryResult').hide();
if (typeof callback === "function") {
callback();
}
},
error: function (data) {
try {
var temp = JSON.parse(data.responseText);
arangoHelper.arangoError("Explain error", temp.errorNum);
}
catch (e) {
arangoHelper.arangoError("Explain error", "ERROR");
}
window.progressView.hide();
if (typeof callback === "function") {
callback();
}
}
});
if (queryData) {
window.progressView.show(
"Explain is operating..."
);
$.ajax({
type: "POST",
url: "/_admin/aardvark/query/explain/",
data: queryData,
contentType: "application/json",
processData: false,
success: function (data) {
outputEditor.setValue(data.msg);
self.switchTab("result-switch");
window.progressView.hide();
self.deselect(outputEditor);
$('#downloadQueryResult').hide();
if (typeof callback === "function") {
callback();
}
},
error: function (data) {
window.progressView.hide();
try {
var temp = JSON.parse(data.responseText);
arangoHelper.arangoError("Explain error", temp.errorNum);
}
catch (e) {
arangoHelper.arangoError("Explain error", "ERROR");
}
window.progressView.hide();
if (typeof callback === "function") {
callback();
}
}
});
}
/*
var self = this;
$("svg#explainOutput").html();
@ -952,67 +967,70 @@
// clear result
outputEditor.setValue('');
window.progressView.show(
"Query is operating..."
);
var queryData = this.readQueryData();
if (queryData) {
$('.queryExecutionTime').text('');
self.timer.start();
window.progressView.show(
"Query is operating..."
);
this.execPending = false;
$.ajax({
type: "POST",
url: "/_api/cursor",
data: this.readQueryData(),
contentType: "application/json",
processData: false,
success: function (data) {
$('.queryExecutionTime').text('');
self.timer.start();
var time = "Execution time: " + self.timer.getTimeAndReset()/1000 + " s";
$('.queryExecutionTime').text(time);
this.execPending = false;
$.ajax({
type: "POST",
url: "/_api/cursor",
data: queryData,
contentType: "application/json",
processData: false,
success: function (data) {
var warnings = "";
if (data.extra && data.extra.warnings && data.extra.warnings.length > 0) {
warnings += "Warnings:" + "\r\n\r\n";
data.extra.warnings.forEach(function(w) {
warnings += "[" + w.code + "], '" + w.message + "'\r\n";
});
var time = "Execution time: " + self.timer.getTimeAndReset()/1000 + " s";
$('.queryExecutionTime').text(time);
var warnings = "";
if (data.extra && data.extra.warnings && data.extra.warnings.length > 0) {
warnings += "Warnings:" + "\r\n\r\n";
data.extra.warnings.forEach(function(w) {
warnings += "[" + w.code + "], '" + w.message + "'\r\n";
});
}
if (warnings !== "") {
warnings += "\r\n" + "Result:" + "\r\n\r\n";
}
outputEditor.setValue(warnings + JSON.stringify(data.result, undefined, 2));
self.switchTab("result-switch");
window.progressView.hide();
self.deselect(outputEditor);
$('#downloadQueryResult').show();
if (typeof callback === "function") {
callback();
}
},
error: function (data) {
self.switchTab("result-switch");
$('#downloadQueryResult').hide();
try {
var temp = JSON.parse(data.responseText);
outputEditor.setValue('[' + temp.errorNum + '] ' + temp.errorMessage);
//arangoHelper.arangoError("Query error", temp.errorMessage);
}
catch (e) {
outputEditor.setValue('ERROR');
arangoHelper.arangoError("Query error", "ERROR");
}
window.progressView.hide();
if (typeof callback === "function") {
callback();
}
}
if (warnings !== "") {
warnings += "\r\n" + "Result:" + "\r\n\r\n";
}
outputEditor.setValue(warnings + JSON.stringify(data.result, undefined, 2));
self.switchTab("result-switch");
window.progressView.hide();
self.deselect(outputEditor);
$('#downloadQueryResult').show();
if (typeof callback === "function") {
callback();
}
},
error: function (data) {
self.switchTab("result-switch");
$('#downloadQueryResult').hide();
try {
var temp = JSON.parse(data.responseText);
outputEditor.setValue('[' + temp.errorNum + '] ' + temp.errorMessage);
//arangoHelper.arangoError("Query error", temp.errorMessage);
}
catch (e) {
outputEditor.setValue('ERROR');
arangoHelper.arangoError("Query error", "ERROR");
}
window.progressView.hide();
if (typeof callback === "function") {
callback();
}
}
});
});
}
},
submitQuery: function () {
var outputEditor = ace.edit("queryOutput");
// this.fillExplain();
this.fillResult(this.switchTab.bind(this, "result-switch"));
outputEditor.resize();
var inputEditor = ace.edit("aqlEditor");
@ -1021,14 +1039,7 @@
},
explainQuery: function() {
this.fillExplain();
/*
this.fillExplain(this.switchTab.bind(this, "explain-switch"));
this.execPending = true;
var inputEditor = ace.edit("aqlEditor");
this.deselect(inputEditor);
*/
},
// This function changes the focus onto the tab that has been clicked