Commit eabda5e7 authored by Boris Kocherov's avatar Boris Kocherov

add CUBEMEMBER, CUBEVALUE

CUBEMEMBER and CUBEVALUE functions has been implemented, using xmla
library.

For this purpose the support of lazy calculations in parserFormula has
been added. Now, during the implementantion of a function a method for
lazy calculations  (CalculateLazy) can be defined. CalculateLazy returns
not a value, as it did Calculation, but RSVP.Queue. And now it is the
returned queue that is to return the value which is the result of the
calculations. During the calculation of CUBEVALUE the calculation
process waits until all the calculations of all the arguments are
finished. It is made to send an EXECUTE request to olap. This request
guarantees the consistency of the returned values. In case of success
CUBEMEMBER.CalculateLazy assigns mdx-expression to cube_value to form
the request and calculate its result. Functions are marked as those
which are calculated every time the document is being opened (.ca=true).
changeOffsetElem, which return the element of the olap-tree, adjacent to
the current one on the same level, have been implemented. It helps to
fill the table.
TODO:
Make the editor of connections to OLAP-servers. In the current
implementation connection parameters are hardcoded. The current
parameters describe a connection to SAIKU olap demoserver, which
supports XMLA-requests.
Use PivotCache as an intermediate structure to store the requests'
results. It will allow to use PivotTable to display the results.

In Russian:
Реализованы CUBEMEMBER, CUBEVALUE функции используя xmla библиотеку.

Для этого добавлена поддержка ленивых вычислений в parserFormula.При
реализации функции теперь можно опредилить метод для ленивых вычислений
CalculateLazy.  CalculateLazy возвращает очередь (RSVP.Queue), а не
значение, как при обычных вычислениях. И уже возвращаемая очередь должна
вернуть значение, которое является результатом вычисления. При
вычислении CUBEVALUE происходит ожидание вычисления всех аргументов всех
CUBEVALUE. Это сделано, для того чтобы посылать один запрос EXECUTE к
olap, что гарантирует согласованность значений, полученых в результате.
CUBEMEMBER.CalculateLazy в случае успеха присваивает cube_value mdx-
выражение которое использовано для вычисления
CUBEMEMBER в свою очередь CUBEVALUE использует cube_value для
формирования запроса и вычисления своего результата. Функции
промаркированы как вычисляемые при каждом открытии документа
(.ca=true). Реализованы changeOffsetElem, которые возвращают элемент
olap-дерева, соседний по отношению к текущему на том же уровне, что
позволяет быстро заполнять таблицу.
TODO:
Сделать редактор подключений к OLAP серверам. В текущей реализации
параметры соединений прописаны прямо в коде. Текущие параметры описывают
соединение с SAIKU olap demoserver, который поддерживает XMLA.
Использовать PivotCache как промежуточную структуру для хранения
результатов запросов, что позволит использовать PivotTable для
отображения результатов.
parent 1c9c5b08
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
"../cell/model/FormulaObjects/_xlfnFunctions.js", "../cell/model/FormulaObjects/_xlfnFunctions.js",
"../cell/model/FormulaObjects/dateandtimeFunctions.js", "../cell/model/FormulaObjects/dateandtimeFunctions.js",
"../cell/model/FormulaObjects/engineeringFunctions.js", "../cell/model/FormulaObjects/engineeringFunctions.js",
"../cell/model/FormulaObjects/cubeFunctions.js", "../cell/model/FormulaObjects/cubeFunctions.xmla.js",
"../cell/model/FormulaObjects/databaseFunctions.js", "../cell/model/FormulaObjects/databaseFunctions.js",
"../cell/model/FormulaObjects/textanddataFunctions.js", "../cell/model/FormulaObjects/textanddataFunctions.js",
"../cell/model/FormulaObjects/statisticalFunctions.js", "../cell/model/FormulaObjects/statisticalFunctions.js",
...@@ -276,6 +276,8 @@ ...@@ -276,6 +276,8 @@
"../common/externs/jquery-3.2.js", "../common/externs/jquery-3.2.js",
"../common/externs/xregexp-3.0.0.js", "../common/externs/xregexp-3.0.0.js",
"../common/externs/sockjs.js", "../common/externs/sockjs.js",
"../common/externs/Xmla.js",
"../common/externs/rsvp-2.0.4.js",
"../common/externs/jszip.min.js", "../common/externs/jszip.min.js",
"../common/externs/jszip-utils.js" "../common/externs/jszip-utils.js"
], ],
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
<link rel="stylesheet" href="qunit/qunit-1.11.0.css" type="text/css" media="screen" /> <link rel="stylesheet" href="qunit/qunit-1.11.0.css" type="text/css" media="screen" />
<script type="text/javascript" src="qunit/qunit-1.11.0.js"></script> <script type="text/javascript" src="qunit/qunit-1.11.0.js"></script>
<script type="text/javascript" src="../../../web-apps/vendor/xregexp/xregexp-all-min.js"></script> <script type="text/javascript" src="../../../web-apps/vendor/xregexp/xregexp-all-min.js"></script>
<script type="text/javascript" src="../../../web-apps/vendor/rsvp/rsvp.min.js"></script>
<script type="text/javascript" src="../../../web-apps/vendor/xmla4js/Xmla-compiled.js"></script>
<script type="text/javascript" src="../../../web-apps/apps/spreadsheeteditor/sdk_dev_scripts.js"></script> <script type="text/javascript" src="../../../web-apps/apps/spreadsheeteditor/sdk_dev_scripts.js"></script>
<script> <script>
......
This diff is collapsed.
...@@ -659,6 +659,10 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara ...@@ -659,6 +659,10 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
this.value = val; this.value = val;
} }
cBaseType.prototype.clone = function () {
return new this.constructor(this.value);
};
cBaseType.prototype.cloneTo = function (oRes) { cBaseType.prototype.cloneTo = function (oRes) {
oRes.numFormat = this.numFormat; oRes.numFormat = this.numFormat;
oRes.value = this.value; oRes.value = this.value;
...@@ -672,6 +676,110 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara ...@@ -672,6 +676,110 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseType.prototype.toLocaleString = function () { cBaseType.prototype.toLocaleString = function () {
return this.toString(); return this.toString();
}; };
cBaseType.prototype.CalculatePromise = function (arg, opt_bbox, isDefName, ws, bIsSpecialFunction) {
// depromise args
var t = this,
lazy_formulas = [],
lazy_found;
function check_args_promise() {
var promise_flag = false,
element,
length,
i;
function cellForge(cell) {
if (cell && cell.formulaParsed &&
(cell.formulaParsed.lazy_value || cell.formulaParsed.queue)) {
promise_flag = true;
lazy_formulas.push(cell.formulaParsed);
}
}
for (i = 0, length = arg.length; i < length; ++i) {
element = arg[i];
if (typeof element === "function") {
promise_flag = true;
}
if (element instanceof cArea || element instanceof cArea3D ||
element instanceof cRef || element instanceof cRef3D) {
element.getRange()._foreach(cellForge);
}
}
return promise_flag;
}
lazy_found = check_args_promise();
if (t.CalculateLazy) {
return function () {
var queue = new RSVP.Queue();
if (lazy_formulas.length > 0) {
lazy_formulas.forEach(function (formula) {
var lazy = formula.lazy_value;
if (lazy) {
// if value lazy run it
lazy();
}
if (formula.queue) {
// add dependence from already
// running but not computed lazy
queue.push(function () {
return formula.queue;
});
}
});
}
queue
.push(function () {
return RSVP.all(arg.map(function (z) {
if (typeof z === "function") {
return z();
} else {
return z;
}
}));
});
return t.CalculateLazy(queue, opt_bbox, isDefName, ws, bIsSpecialFunction);
};
} else {
if (lazy_found) {
return function () {
var queue = new RSVP.Queue();
if (lazy_formulas.length > 0) {
lazy_formulas.forEach(function (formula) {
var lazy = formula.lazy_value;
if (lazy) {
// if value lazy add it dependence list
lazy();
}
if (formula.queue) {
// add dependence from already
// running but not computed lazy
queue.push(function () {
return formula.queue;
});
}
});
}
return queue
.push(function () {
return RSVP.all(arg.map(function (z) {
if (typeof z === "function") {
return z();
} else {
return z;
}
}));
})
.push(function (arg) {
return t.Calculate(arg, opt_bbox, isDefName, ws, bIsSpecialFunction);
});
};
} else {
return t.Calculate(arg, opt_bbox, isDefName, ws, bIsSpecialFunction);
}
}
};
/*Basic types of an elements used into formulas*/ /*Basic types of an elements used into formulas*/
/** /**
...@@ -2415,6 +2523,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara ...@@ -2415,6 +2523,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseOperator.prototype.Calculate = function () { cBaseOperator.prototype.Calculate = function () {
return null; return null;
}; };
cBaseOperator.prototype.CalculatePromise = cBaseType.prototype.CalculatePromise;
cBaseOperator.prototype.Assemble2 = function (arg, start, count) { cBaseOperator.prototype.Assemble2 = function (arg, start, count) {
var str = ""; var str = "";
if (this.argumentsCurrent === 2) { if (this.argumentsCurrent === 2) {
...@@ -2463,6 +2572,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara ...@@ -2463,6 +2572,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cBaseFunction.prototype.Calculate = function () { cBaseFunction.prototype.Calculate = function () {
return new cError(cErrorType.wrong_name); return new cError(cErrorType.wrong_name);
}; };
cBaseFunction.prototype.CalculatePromise = cBaseOperator.prototype.CalculatePromise;
cBaseFunction.prototype.Assemble2 = function (arg, start, count) { cBaseFunction.prototype.Assemble2 = function (arg, start, count) {
var str = "", c = start + count - 1; var str = "", c = start + count - 1;
...@@ -5314,6 +5424,8 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -5314,6 +5424,8 @@ parserFormula.prototype.setFormula = function(formula) {
}; };
parserFormula.prototype.calculate = function (opt_defName, opt_bbox, opt_offset) { parserFormula.prototype.calculate = function (opt_defName, opt_bbox, opt_offset) {
var value,
formula = this;
if (this.isCalculate && (!this.calculateDefName || this.calculateDefName[opt_bbox ? opt_bbox.getName() : if (this.isCalculate && (!this.calculateDefName || this.calculateDefName[opt_bbox ? opt_bbox.getName() :
opt_bbox])) { opt_bbox])) {
//cycle //cycle
...@@ -5372,7 +5484,7 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -5372,7 +5484,7 @@ parserFormula.prototype.setFormula = function(formula) {
} }
arg.unshift(elemArr.pop()); arg.unshift(elemArr.pop());
} }
_tmp = currentElement.Calculate(arg, opt_bbox, opt_defName, this.ws, bIsSpecialFunction); _tmp = currentElement.CalculatePromise(arg, opt_bbox, opt_defName, this.ws, bIsSpecialFunction);
if (cNumFormatNull !== _tmp.numFormat) { if (cNumFormatNull !== _tmp.numFormat) {
numFormat = _tmp.numFormat; numFormat = _tmp.numFormat;
} else if (0 > numFormat || cNumFormatNone === currentElement.numFormat) { } else if (0 > numFormat || cNumFormatNone === currentElement.numFormat) {
...@@ -5390,8 +5502,31 @@ parserFormula.prototype.setFormula = function(formula) { ...@@ -5390,8 +5502,31 @@ parserFormula.prototype.setFormula = function(formula) {
elemArr.push(currentElement); elemArr.push(currentElement);
} }
} }
this.value = elemArr.pop(); value = elemArr.pop();
this.value.numFormat = numFormat; if (typeof value === "function") {
this.value = new cError(cErrorType.getting_data);
this.queue = true;
this.lazy_value = function () {
formula.lazy_value = null;
formula.queue = value()
.push(function (ret) {
formula.value = ret;
formula.value.numFormat = numFormat;
formula._endCalculate();
// updateOnScreen cell
formula.ws.workbook.handlers.trigger("cleanCellCache",
formula.ws.getId(), {0: opt_bbox},
AscCommonExcel.c_oAscCanChangeColWidth.none);
formula.queue = false;
// formula.lazy_value = null;
return formula.value;
});
return formula.queue
}
} else {
this.value = value;
this.value.numFormat = numFormat;
}
this._endCalculate(); this._endCalculate();
return this.value; return this.value;
......
...@@ -927,6 +927,11 @@ ...@@ -927,6 +927,11 @@
this.buildDefName = {}; this.buildDefName = {};
}, },
calcTree: function() { calcTree: function() {
var dependency_graph = this,
formula,
i,
tasks = [],
lazy_value;
if (this.lockCounter > 0) { if (this.lockCounter > 0) {
return; return;
} }
...@@ -944,26 +949,44 @@ ...@@ -944,26 +949,44 @@
this._broadcastCells(notifyData, calcTrack); this._broadcastCells(notifyData, calcTrack);
} }
this._broadcastCellsEnd(); this._broadcastCellsEnd();
for (var i = 0; i < noCalcTrack.length; ++i) { for (i = 0; i < noCalcTrack.length; ++i) {
var formula = noCalcTrack[i]; formula = noCalcTrack[i];
//defName recalc when calc formula containing it. no need calc it //defName recalc when calc formula containing it. no need calc it
formula.setIsDirty(false); formula.setIsDirty(false);
} }
for (var i = 0; i < calcTrack.length; ++i) {
var formula = calcTrack[i]; for (i = 0; i < calcTrack.length; ++i) {
formula = calcTrack[i];
if (formula.getIsDirty()) { if (formula.getIsDirty()) {
formula.calculate(); formula.calculate();
} }
} }
//copy cleanCellCache to prevent recursion in trigger("cleanCellCache") for (i = calcTrack.length-1; i >= 0; --i) {
var tmpCellCache = this.cleanCellCache; lazy_value = calcTrack[i].lazy_value;
this.cleanCellCache = {}; if (lazy_value) {
for (var i in tmpCellCache) { tasks.push(lazy_value());
this.wb.handlers.trigger("cleanCellCache", i, {0: tmpCellCache[i]}, }
AscCommonExcel.c_oAscCanChangeColWidth.none); }
function end () {
//copy cleanCellCache to prevent recursion in trigger("cleanCellCache")
var tmpCellCache = dependency_graph.cleanCellCache;
dependency_graph.cleanCellCache = {};
for (var i in tmpCellCache) {
dependency_graph.wb.handlers.trigger("cleanCellCache", i, {0: tmpCellCache[i]},
AscCommonExcel.c_oAscCanChangeColWidth.none);
}
AscCommonExcel.g_oVLOOKUPCache.clean();
AscCommonExcel.g_oHLOOKUPCache.clean();
}
if (tasks.length > 0) {
new RSVP.Queue()
.push(function () {
return RSVP.all(tasks);
})
.push(end);
} else {
end();
} }
AscCommonExcel.g_oVLOOKUPCache.clean();
AscCommonExcel.g_oHLOOKUPCache.clean();
}, },
initOpen: function() { initOpen: function() {
this._foreachDefName(function(defName) { this._foreachDefName(function(defName) {
...@@ -6418,7 +6441,7 @@ ...@@ -6418,7 +6441,7 @@
this.setValue(""); this.setValue("");
}; };
Cell.prototype._checkDirty = function(){ Cell.prototype._checkDirty = function(){
if(this.formulaParsed && this.formulaParsed.getIsDirty()) { if(this.formulaParsed && this.formulaParsed.getIsDirty() && !this.formulaParsed.queue) {
this.formulaParsed.calculate(); this.formulaParsed.calculate();
} }
}; };
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment