[英]Creating Test data for ArangoDB
Hi I would like to insert random test data into an edge collection called Transaction with the fields _id, Amount and TransferType with random data.您好,我想将随机测试数据插入到名为 Transaction 的边缘集合中,其中包含带有随机数据的字段 _id、Amount 和 TransferType。 I have written the following code below, but it is showing a syntax error.我在下面编写了以下代码,但显示语法错误。
FOR i IN 1..30000
INSERT {
_id: CONCAT('Transaction/', i),
Amount:RAND(),
Time:Rand(DATE_TIMESTAMP),
i > 1000 || u.Type_of_Transfer == "NEFT" ? u.Type_of_Transfer == "IMPS"
} INTO Transaction OPTIONS { ignoreErrors: true }
Your code has multiple issues:您的代码有多个问题:
_key
key and Arango will create one for you, or you specify one as a string to be used.当您创建一个新文档时,您可以不指定_key
键,Arango 将为您创建一个,或者您指定一个作为要使用的字符串。 _id
as a key will be ignored. _id
作为键将被忽略。RAND()
produces a random number between 0 and 1, so it needs to be multiplied in order to make it into the range you want you might need to round it, if you need integer values. RAND()
产生一个介于 0 和 1 之间的随机数,因此需要将其相乘才能使其进入您想要的范围,如果您需要 integer 个值,则可能需要对其进行舍入。DATE_TIMESTAMP
is a function and you have given it as a parameter to the RAND() function which needs no parameter. DATE_TIMESTAMP
是一个 function 并且您已将其作为参数提供给不需要参数的 RAND() function。 But because it generates a numerical timestamp (milliseconds since 1970-01-01 00:00 UTC), actually it's not needed.但是因为它生成了一个数字时间戳(自 1970-01-01 00:00 UTC 以来的毫秒数),实际上不需要它。 The only thing you need is the random number generation shifted to a range that makes sense (ie: not in the 1970s)您唯一需要的是将随机数生成转移到一个有意义的范围内(即:不是在 1970 年代)i > 1000...
line is something I could only guess what it wanted to be. i > 1000...
行是我只能猜测它想要的东西。 Here the key for the JSON object is missing.这里缺少 JSON object 的密钥。 You are referencing a u
variable that is not defined anywhere.您正在引用未在任何地方定义的u
变量。 I see the first two parts of a ternary operator expression ( cond? true_value: false_value
) but the :
is missing.我看到了三元运算符表达式 ( cond? true_value: false_value
) 的前两部分,但是:
丢失了。 My best guess is that you wanted to create a Type_of_transfer
key with value of "NEFT" when i>1000
and "IMPS" when i<=1000
我最好的猜测是您想创建一个Type_of_transfer
键,当i>1000
时值为“NEFT”,当i<=1000
时值为“IMPS”So, I rewrote your AQL and tested it所以,我重写了你的 AQL 并测试了它
FOR i IN 1..30000
INSERT {
_key: TO_STRING(i),
Amount: RAND()*1000,
Time: ROUND(RAND()*100000000+1603031645000),
Type_of_Transfer: i > 1000 ? "NEFT" : "IMPS"
} INTO Transaction OPTIONS { ignoreErrors: true }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.