8000 allow using `RANDOM_TOKEN` AQL function with an argument value of `0`… · whitewum/arangodb@fd87abc · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit fd87abc

Browse files
authored
allow using RANDOM_TOKEN AQL function with an argument value of 0. (arangodb#10414)
1 parent 237a3fc commit fd87abc

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
devel
22
-----
33

4+
* Allow usage of AQL function `RANDOM_TOKEN` with an argument value of `0`. This
5+
now produces an empty string, whereas in older versions this threw an invalid
6+
value exception.
7+
48
* Add startup option `--rocksdb.exclusive-writes` to avoid write-write conflicts.
59

610
This options allows for an easier transition from MMFiles to the RocksDB storage

arangod/Aql/Functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,14 +4250,14 @@ AqlValue Functions::RandomToken(ExpressionContext*, transaction::Methods*,
42504250
AqlValue const& value = extractFunctionParameterValue(parameters, 0);
42514251

42524252
int64_t const length = value.toInt64();
4253-
if (length <= 0 || length > 65536) {
4253+
if (length < 0 || length > 65536) {
42544254
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH,
42554255
"RANDOM_TOKEN");
42564256
}
42574257

4258-
UniformCharacter JSNumGenerator(
4258+
UniformCharacter generator(
42594259
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
4260-
return AqlValue(JSNumGenerator.random(static_cast<size_t>(length)));
4260+
return AqlValue(generator.random(static_cast<size_t>(length)));
42614261
}
42624262

42634263
/// @brief function MD5

tests/js/server/aql/aql-functions-string.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,15 +2566,15 @@ function ahuacatlStringFunctionsTestSuite () {
25662566
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH.code, 'RETURN RANDOM_TOKEN(1, 2)');
25672567
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(-1)');
25682568
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(-10)');
2569-
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(0)');
25702569
assertQueryError(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, 'RETURN RANDOM_TOKEN(65537)');
25712570

2572-
var actual = getQueryResults('FOR i IN [ 1, 10, 100, 1000 ] RETURN RANDOM_TOKEN(i)');
2573-
assertEqual(4, actual.length);
2571+
var actual = getQueryResults('FOR i IN [ 1, 10, 100, 1000, 0 ] RETURN RANDOM_TOKEN(i)');
2572+
assertEqual(5, actual.length);
25742573
assertEqual(1, actual[0].length);
25752574
assertEqual(10, actual[1].length);
25762575
assertEqual(100, actual[2].length);
25772576
assertEqual(1000, actual[3].length);
2577+
assertEqual(0, actual[4].length);
25782578
}
25792579

25802580
};

0 commit comments

Comments
 (0)
0