mirror of https://gitee.com/bigwinds/arangodb
issue #1593: add POW() AQL function
This commit is contained in:
parent
460b51734e
commit
61a8e4c686
|
@ -1,6 +1,8 @@
|
||||||
v2.8.0 (XXXX-XX-XX)
|
v2.8.0 (XXXX-XX-XX)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
* issue #1593: added AQL `POW` function for exponentation
|
||||||
|
|
||||||
* added cluster execution site info in explain output for AQL queries
|
* added cluster execution site info in explain output for AQL queries
|
||||||
|
|
||||||
* replication improvements:
|
* replication improvements:
|
||||||
|
|
|
@ -149,6 +149,7 @@ std::unordered_map<std::string, Function const> const Executor::FunctionNames{
|
||||||
{ "ABS", Function("ABS", "AQL_ABS", "n", true, true, false, true, true, &Functions::Abs) },
|
{ "ABS", Function("ABS", "AQL_ABS", "n", true, true, false, true, true, &Functions::Abs) },
|
||||||
{ "RAND", Function("RAND", "AQL_RAND", "", false, false, false, true, true, &Functions::Rand) },
|
{ "RAND", Function("RAND", "AQL_RAND", "", false, false, false, true, true, &Functions::Rand) },
|
||||||
{ "SQRT", Function("SQRT", "AQL_SQRT", "n", true, true, false, true, true, &Functions::Sqrt) },
|
{ "SQRT", Function("SQRT", "AQL_SQRT", "n", true, true, false, true, true, &Functions::Sqrt) },
|
||||||
|
{ "POW", Function("POW", "AQL_POW", "n,n", true, true, false, true, true, &Functions::Pow) },
|
||||||
|
|
||||||
// list functions
|
// list functions
|
||||||
{ "RANGE", Function("RANGE", "AQL_RANGE", "n,n|n", true, true, false, true, true, &Functions::Range) },
|
{ "RANGE", Function("RANGE", "AQL_RANGE", "n,n|n", true, true, false, true, true, &Functions::Range) },
|
||||||
|
|
|
@ -3486,9 +3486,38 @@ AqlValue Functions::Sqrt (triagens::aql::Query* query,
|
||||||
bool unused = false;
|
bool unused = false;
|
||||||
double input = TRI_ToDoubleJson(inputJson.json(), unused);
|
double input = TRI_ToDoubleJson(inputJson.json(), unused);
|
||||||
input = sqrt(input);
|
input = sqrt(input);
|
||||||
|
if (std::isnan(input)) {
|
||||||
|
return AqlValue(new Json(Json::Null));
|
||||||
|
}
|
||||||
return AqlValue(new Json(input));
|
return AqlValue(new Json(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief function POW
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
AqlValue Functions::Pow (triagens::aql::Query* query,
|
||||||
|
triagens::arango::AqlTransaction* trx,
|
||||||
|
FunctionParameters const& parameters) {
|
||||||
|
size_t const n = parameters.size();
|
||||||
|
|
||||||
|
if (n != 2) {
|
||||||
|
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH, "POW", (int) 2, (int) 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Json baseJson = ExtractFunctionParameter(trx, parameters, 0, false);
|
||||||
|
Json expJson = ExtractFunctionParameter(trx, parameters, 1, false);
|
||||||
|
|
||||||
|
bool unused = false;
|
||||||
|
double base = TRI_ToDoubleJson(baseJson.json(), unused);
|
||||||
|
double exp = TRI_ToDoubleJson(expJson.json(), unused);
|
||||||
|
base = pow(base, exp);
|
||||||
|
if (std::isnan(base) || ! std::isfinite(base)) {
|
||||||
|
return AqlValue(new Json(Json::Null));
|
||||||
|
}
|
||||||
|
return AqlValue(new Json(base));
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief function RAND
|
/// @brief function RAND
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -129,6 +129,7 @@ namespace triagens {
|
||||||
static AqlValue Ceil (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue Ceil (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
static AqlValue Floor (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue Floor (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
static AqlValue Sqrt (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue Sqrt (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
|
static AqlValue Pow (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
static AqlValue Rand (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue Rand (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
static AqlValue FirstDocument (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue FirstDocument (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
static AqlValue FirstList (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
static AqlValue FirstList (triagens::aql::Query*, triagens::arango::AqlTransaction*, FunctionParameters const&);
|
||||||
|
|
|
@ -2767,6 +2767,16 @@ function AQL_SQRT (value) {
|
||||||
return NUMERIC_VALUE(Math.sqrt(AQL_TO_NUMBER(value)));
|
return NUMERIC_VALUE(Math.sqrt(AQL_TO_NUMBER(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief exponentation
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function AQL_POW (base, exp) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
return NUMERIC_VALUE(Math.pow(AQL_TO_NUMBER(base), AQL_TO_NUMBER(exp)));
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- list processing functions
|
// --SECTION-- list processing functions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -9154,6 +9164,7 @@ exports.AQL_ROUND = AQL_ROUND;
|
||||||
exports.AQL_ABS = AQL_ABS;
|
exports.AQL_ABS = AQL_ABS;
|
||||||
exports.AQL_RAND = AQL_RAND;
|
exports.AQL_RAND = AQL_RAND;
|
||||||
exports.AQL_SQRT = AQL_SQRT;
|
exports.AQL_SQRT = AQL_SQRT;
|
||||||
|
exports.AQL_POW = AQL_POW;
|
||||||
exports.AQL_LENGTH = AQL_LENGTH;
|
exports.AQL_LENGTH = AQL_LENGTH;
|
||||||
exports.AQL_FIRST = AQL_FIRST;
|
exports.AQL_FIRST = AQL_FIRST;
|
||||||
exports.AQL_LAST = AQL_LAST;
|
exports.AQL_LAST = AQL_LAST;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue