home shape

ArangoDB 2.8: Enhanced Explain and arangoimp Improvements

Explain Improvements

Explaining AQL queries becomes even easier in ArangoDB 2.8. While previous versions required writing a hard-to-memorize command like

require("org/arangodb/aql/explainer").explain(query);

to explain an AQL query from the ArangoShell, 2.8 reduces this task to a mere

db._explain(query);

Apart from that, explain in 2.8 is smarter when confronted with very lengthy query strings, and with queries that contain huge hard-coded string, array, or object values.

For example, when creating an array bind variable with 1,000 values and using them in an explained query, 2.7 would print the entire 1,000 array values in the explain output:

var keys = []; 
for (var i = 0; i < 1000; ++i) { 
  keys.push("test" + i); 
}

var query = "FOR i IN @keys RETURN i"; 
require("org/arangodb/aql/explainer").explain({ 
  query: query, 
  bindVars: { 
    keys: keys 
  } 
});

explain 27

2.8 will instead truncate longer arrays and objects in the explain output for much more improved readability:

explain 28

Automatic value truncation will occur for array and object values with more than 20 elements or for string values longer than 1,024 characters. The truncation for explain will occur if these values are hard-coded into the query or are passed via bind parameters.

Truncation only happens inside the explain results processing and thus cannot affect the actual query results.


POW

ArangoDB 2.8 now provides a dedicated AQL function for exponentiation. This will save users a lot of trouble in case exponentiation is needed inside an AQL query, which up to 2.7 required writing and registering an AQL user-defined function.

With 2.8 it becomes as simple as RETURN POW(2, 16) to raise 2 to the power of 16 from inside AQL.


Collection type for Arangoimp

When trying to import data into ArangoDB from a JSON or CSV file using the arangoimp binary, there is always the chance that the target collection does not yet exist.

In order to create a missing target collection arangoimp has provided the option
--create-collection true:

arangoimp                       
  --file users.json             
  --collection users            
  --create-collection true

However there hasn’t been a way of specifying the type for the target collection, so the new collection was always created as document collection.

To import data into an edge collection, the target collection needed to be created by another means, e.g. by using the ArangoShell. It would have been more handy if arangoimp were able to create edge collections too.

2.8 finally adds that feature, and it’s simple to use: to create an edge collection if the target collection does not exist, append the --create-collection-type edge option when invoking arangoimp:

arangoimp                       
  --file users.json             
  --collection users            
  --create-collection true      
  --create-collection-type edge

Julie Ferrario

Leave a Comment





Get the latest tutorials, blog posts and news: