mirror of https://gitee.com/bigwinds/arangodb
use AqlValues
This commit is contained in:
parent
236aa3ab5f
commit
3c3a4fb0d2
|
@ -1691,11 +1691,11 @@ AqlValue Functions::Values(arangodb::aql::Query* query,
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AqlValue Functions::Min(arangodb::aql::Query* query,
|
AqlValue Functions::Min(arangodb::aql::Query* query,
|
||||||
arangodb::AqlTransaction* trx,
|
arangodb::AqlTransaction* trx,
|
||||||
VPackFunctionParameters const& parameters,
|
VPackFunctionParameters const& parameters,
|
||||||
bool& mustDestroy) {
|
bool& mustDestroy) {
|
||||||
mustDestroy = true;
|
mustDestroy = true;
|
||||||
auto value = ExtractFunctionParameter(trx, parameters, 0);
|
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
|
|
||||||
if (!value.isArray()) {
|
if (!value.isArray()) {
|
||||||
// not an array
|
// not an array
|
||||||
|
@ -1703,8 +1703,11 @@ AqlValue Functions::Min(arangodb::aql::Query* query,
|
||||||
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackSlice slice = materializer.slice(value);
|
||||||
|
|
||||||
VPackSlice minValue;
|
VPackSlice minValue;
|
||||||
for (auto const& it : VPackArrayIterator(value)) {
|
for (auto const& it : VPackArrayIterator(slice)) {
|
||||||
if (it.isNull()) {
|
if (it.isNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1723,19 +1726,22 @@ AqlValue Functions::Min(arangodb::aql::Query* query,
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AqlValue Functions::Max(arangodb::aql::Query* query,
|
AqlValue Functions::Max(arangodb::aql::Query* query,
|
||||||
arangodb::AqlTransaction* trx,
|
arangodb::AqlTransaction* trx,
|
||||||
VPackFunctionParameters const& parameters,
|
VPackFunctionParameters const& parameters,
|
||||||
bool& mustDestroy) {
|
bool& mustDestroy) {
|
||||||
mustDestroy = true;
|
mustDestroy = true;
|
||||||
auto value = ExtractFunctionParameter(trx, parameters, 0);
|
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
|
|
||||||
if (!value.isArray()) {
|
if (!value.isArray()) {
|
||||||
// not an array
|
// not an array
|
||||||
RegisterWarning(query, "MAX", TRI_ERROR_QUERY_ARRAY_EXPECTED);
|
RegisterWarning(query, "MAX", TRI_ERROR_QUERY_ARRAY_EXPECTED);
|
||||||
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackSlice slice = materializer.slice(value);
|
||||||
VPackSlice maxValue;
|
VPackSlice maxValue;
|
||||||
for (auto const& it : VPackArrayIterator(value)) {
|
for (auto const& it : VPackArrayIterator(slice)) {
|
||||||
if (maxValue.isNone() || arangodb::basics::VelocyPackHelper::compare(it, maxValue, true) > 0) {
|
if (maxValue.isNone() || arangodb::basics::VelocyPackHelper::compare(it, maxValue, true) > 0) {
|
||||||
maxValue = it;
|
maxValue = it;
|
||||||
}
|
}
|
||||||
|
@ -1751,11 +1757,11 @@ AqlValue Functions::Max(arangodb::aql::Query* query,
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AqlValue Functions::Sum(arangodb::aql::Query* query,
|
AqlValue Functions::Sum(arangodb::aql::Query* query,
|
||||||
arangodb::AqlTransaction* trx,
|
arangodb::AqlTransaction* trx,
|
||||||
VPackFunctionParameters const& parameters,
|
VPackFunctionParameters const& parameters,
|
||||||
bool& mustDestroy) {
|
bool& mustDestroy) {
|
||||||
mustDestroy = true;
|
mustDestroy = true;
|
||||||
auto value = ExtractFunctionParameter(trx, parameters, 0);
|
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
|
|
||||||
if (!value.isArray()) {
|
if (!value.isArray()) {
|
||||||
// not an array
|
// not an array
|
||||||
|
@ -1763,8 +1769,10 @@ AqlValue Functions::Sum(arangodb::aql::Query* query,
|
||||||
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackSlice slice = materializer.slice(value);
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
for (auto const& it : VPackArrayIterator(value)) {
|
for (auto const& it : VPackArrayIterator(slice)) {
|
||||||
if (it.isNull()) {
|
if (it.isNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1777,13 +1785,14 @@ AqlValue Functions::Sum(arangodb::aql::Query* query,
|
||||||
sum += number;
|
sum += number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<VPackBuilder> b = query->getSharedBuilder();
|
|
||||||
if (!std::isnan(sum) && sum != HUGE_VAL && sum != -HUGE_VAL) {
|
if (!std::isnan(sum) && sum != HUGE_VAL && sum != -HUGE_VAL) {
|
||||||
b->add(VPackValue(sum));
|
TransactionBuilderLeaser builder(trx);
|
||||||
} else {
|
builder->add(VPackValue(sum));
|
||||||
b->add(VPackValue(VPackValueType::Null));
|
return AqlValue(builder.get());
|
||||||
}
|
}
|
||||||
return AqlValue(b.get());
|
|
||||||
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1795,17 +1804,20 @@ AqlValue Functions::Average(arangodb::aql::Query* query,
|
||||||
VPackFunctionParameters const& parameters,
|
VPackFunctionParameters const& parameters,
|
||||||
bool& mustDestroy) {
|
bool& mustDestroy) {
|
||||||
mustDestroy = true;
|
mustDestroy = true;
|
||||||
auto value = ExtractFunctionParameter(trx, parameters, 0);
|
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
|
|
||||||
if (!value.isArray()) {
|
if (!value.isArray()) {
|
||||||
// not an array
|
// not an array
|
||||||
RegisterWarning(query, "AVERAGE", TRI_ERROR_QUERY_ARRAY_EXPECTED);
|
RegisterWarning(query, "AVERAGE", TRI_ERROR_QUERY_ARRAY_EXPECTED);
|
||||||
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackSlice slice = materializer.slice(value);
|
||||||
|
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (auto const& v : VPackArrayIterator(value)) {
|
for (auto const& v : VPackArrayIterator(slice)) {
|
||||||
if (v.isNull()) {
|
if (v.isNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1823,13 +1835,13 @@ AqlValue Functions::Average(arangodb::aql::Query* query,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VPackBuilder> b = query->getSharedBuilder();
|
|
||||||
if (count > 0 && !std::isnan(sum) && sum != HUGE_VAL && sum != -HUGE_VAL) {
|
if (count > 0 && !std::isnan(sum) && sum != HUGE_VAL && sum != -HUGE_VAL) {
|
||||||
b->add(VPackValue(sum / static_cast<size_t>(count)));
|
TransactionBuilderLeaser builder(trx);
|
||||||
} else {
|
builder->add(VPackValue(sum / static_cast<size_t>(count)));
|
||||||
b->add(VPackValue(VPackValueType::Null));
|
return AqlValue(builder.get());
|
||||||
}
|
}
|
||||||
return AqlValue(b.get());
|
|
||||||
|
return AqlValue(arangodb::basics::VelocyPackHelper::NullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1841,11 +1853,11 @@ AqlValue Functions::Md5(arangodb::aql::Query* query,
|
||||||
VPackFunctionParameters const& parameters,
|
VPackFunctionParameters const& parameters,
|
||||||
bool& mustDestroy) {
|
bool& mustDestroy) {
|
||||||
mustDestroy = true;
|
mustDestroy = true;
|
||||||
auto value = ExtractFunctionParameter(trx, parameters, 0);
|
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE);
|
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE);
|
||||||
arangodb::basics::VPackStringBufferAdapter adapter(buffer.stringBuffer());
|
arangodb::basics::VPackStringBufferAdapter adapter(buffer.stringBuffer());
|
||||||
|
|
||||||
AppendAsString(adapter, value);
|
AppendAsString(trx, adapter, value);
|
||||||
|
|
||||||
// create md5
|
// create md5
|
||||||
char hash[17];
|
char hash[17];
|
||||||
|
@ -1861,9 +1873,9 @@ AqlValue Functions::Md5(arangodb::aql::Query* query,
|
||||||
|
|
||||||
arangodb::rest::SslInterface::sslHEX(hash, 16, p, length);
|
arangodb::rest::SslInterface::sslHEX(hash, 16, p, length);
|
||||||
|
|
||||||
std::shared_ptr<VPackBuilder> b = query->getSharedBuilder();
|
TransactionBuilderLeaser builder(trx);
|
||||||
b->add(VPackValue(std::string(hex, 32)));
|
builder->add(VPackValue(std::string(hex, 32)));
|
||||||
return AqlValue(b.get());
|
return AqlValue(builder.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue