简体   繁体   中英

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. 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:

  • When you are creating a new document you can either not specify the _key key and Arango will create one for you, or you specify one as a string to be used. _id as a key will be ignored.
  • 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.
  • DATE_TIMESTAMP is a function and you have given it as a parameter to the RAND() function which needs no parameter. But because it generates a numerical timestamp (milliseconds since 1970-01-01 00:00 UTC), actually it's not needed. The only thing you need is the random number generation shifted to a range that makes sense (ie: not in the 1970s)
  • The i > 1000... line is something I could only guess what it wanted to be. Here the key for the JSON object is missing. You are referencing a u variable that is not defined anywhere. I see the first two parts of a ternary operator expression ( cond? true_value: false_value ) but the : is missing. 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

So, I rewrote your AQL and tested it

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 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM