mirror of https://gitee.com/bigwinds/arangodb
Feature/translate translate function now in c++ (#4102)
This commit is contained in:
parent
c1b40337a0
commit
5ff201bea7
|
@ -6,6 +6,8 @@ devel
|
||||||
|
|
||||||
* added C++ implementation for AQL function `SHA512()`
|
* added C++ implementation for AQL function `SHA512()`
|
||||||
|
|
||||||
|
* Added C++ implementation for the AQL TRANSLATE function
|
||||||
|
|
||||||
* renamed arangoimp to arangoimport for consistency
|
* renamed arangoimp to arangoimport for consistency
|
||||||
Release packages will still install arangoimp as a symlink so user scripts
|
Release packages will still install arangoimp as a symlink so user scripts
|
||||||
invoking arangoimp do not need to be changed
|
invoking arangoimp do not need to be changed
|
||||||
|
|
|
@ -401,7 +401,7 @@ void AqlFunctionFeature::addDocumentFunctions() {
|
||||||
true, true, &Functions::UnsetRecursive});
|
true, true, &Functions::UnsetRecursive});
|
||||||
add({"KEEP", ".,.|+", true, false, true, true,
|
add({"KEEP", ".,.|+", true, false, true, true,
|
||||||
&Functions::Keep});
|
&Functions::Keep});
|
||||||
add({"TRANSLATE", ".,.|.", true, false, true, true});
|
add({"TRANSLATE", ".,.|.", true, false, true, true, &Functions::Translate});
|
||||||
add({"ZIP", ".,.", true, false, true, true,
|
add({"ZIP", ".,.", true, false, true, true,
|
||||||
&Functions::Zip});
|
&Functions::Zip});
|
||||||
add({"JSON_STRINGIFY", ".", true, false, true,
|
add({"JSON_STRINGIFY", ".", true, false, true,
|
||||||
|
|
|
@ -1450,6 +1450,46 @@ AqlValue Functions::Keep(arangodb::aql::Query* query,
|
||||||
return AqlValue(builder.get());
|
return AqlValue(builder.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief function TRANSLATE
|
||||||
|
AqlValue Functions::Translate(arangodb::aql::Query* query,
|
||||||
|
transaction::Methods* trx,
|
||||||
|
VPackFunctionParameters const& parameters) {
|
||||||
|
ValidateParameters(parameters, "TRANSLATE", 2, 3);
|
||||||
|
AqlValue key = ExtractFunctionParameterValue(trx, parameters, 0);
|
||||||
|
AqlValue lookupDocument = ExtractFunctionParameterValue(trx, parameters, 1);
|
||||||
|
|
||||||
|
if (!lookupDocument.isObject()) {
|
||||||
|
RegisterInvalidArgumentWarning(query, "TRANSLATE");
|
||||||
|
return AqlValue(AqlValueHintNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
AqlValueMaterializer materializer(trx);
|
||||||
|
VPackSlice slice = materializer.slice(lookupDocument, true);
|
||||||
|
TRI_ASSERT(slice.isObject());
|
||||||
|
|
||||||
|
VPackSlice result;
|
||||||
|
if (key.isString()) {
|
||||||
|
result = slice.get(key.slice().copyString());
|
||||||
|
} else {
|
||||||
|
transaction::StringBufferLeaser buffer(trx);
|
||||||
|
arangodb::basics::VPackStringBufferAdapter adapter(buffer->stringBuffer());
|
||||||
|
Functions::Stringify(trx, adapter, key.slice());
|
||||||
|
result = slice.get(buffer->toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.isNone()) {
|
||||||
|
return AqlValue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// attribute not found, now return the default value
|
||||||
|
// we must create copy of it however
|
||||||
|
AqlValue defaultValue = ExtractFunctionParameterValue(trx, parameters, 2);
|
||||||
|
if (defaultValue.isNone()) {
|
||||||
|
return key.clone();
|
||||||
|
}
|
||||||
|
return defaultValue.clone();
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief function MERGE
|
/// @brief function MERGE
|
||||||
AqlValue Functions::Merge(arangodb::aql::Query* query,
|
AqlValue Functions::Merge(arangodb::aql::Query* query,
|
||||||
transaction::Methods* trx,
|
transaction::Methods* trx,
|
||||||
|
|
|
@ -170,6 +170,8 @@ struct Functions {
|
||||||
VPackFunctionParameters const&);
|
VPackFunctionParameters const&);
|
||||||
static AqlValue Keep(arangodb::aql::Query*, transaction::Methods*,
|
static AqlValue Keep(arangodb::aql::Query*, transaction::Methods*,
|
||||||
VPackFunctionParameters const&);
|
VPackFunctionParameters const&);
|
||||||
|
static AqlValue Translate(arangodb::aql::Query*, transaction::Methods*,
|
||||||
|
VPackFunctionParameters const&);
|
||||||
static AqlValue Merge(arangodb::aql::Query*, transaction::Methods*,
|
static AqlValue Merge(arangodb::aql::Query*, transaction::Methods*,
|
||||||
VPackFunctionParameters const&);
|
VPackFunctionParameters const&);
|
||||||
static AqlValue MergeRecursive(arangodb::aql::Query*, transaction::Methods*,
|
static AqlValue MergeRecursive(arangodb::aql::Query*, transaction::Methods*,
|
||||||
|
|
Loading…
Reference in New Issue