AQL Improvements for ArangoDB 2.7: Enhanced Query Capabilities

With ArangoDB 2.6 being in beta already, it’s time to look at some features scheduled for 2.7. Today I’ll showcase a few AQL parser improvements that are present in the devel branch already, which will be the foundation for the 2.7 release.

Star operator

The already existing star operator ([*]) is much more flexible in 2.7 than in previous ArangoDB versions. It now allows filtering the values it iterates over, and optional projections.

These features will be demonstrated using the following example member data:

[
  { "name" : "sir alfred", "age" : 60, "likes" : [ "lettuce", "tortoises" ] },
  { "name" : "mozquito", "age" : 15, "likes" : [ "skateboards", "music" ] },
  { "name" : "murphy", "age" : 28, "likes" : [ "juice", "tarts", "cakes" ] },
  { "name" : "helga", "age" : 52, "likes" : [ "home", "garden", "tortoises", "cakes" ] }
]

(more…)

More info...

Diffing Two Documents in AQL: ArangoDB Data Comparison

I just stumbled upon a comment in the ArangoDB blog asking how to create a diff of two documents with AQL.

Though there is no built-in AQL function to diff two documents, it is easily possible to build your own like in the following query.

Read more on how to diff two documents in AQL.

More info...

Return Value Optimization for AQL: ArangoDB Query Efficiency

While in search for further AQL query optimizations last week, we found that intermediate AQL query results were copied one time too often in some cases.

Precisely, the data that a query’s ReturnNode will return to the caller was copied into the ReturnNode’s own register. With ReturnNode’s never modifying their input data, this demanded for something that is called return-value optimization in compilers.

2.6 will now optimize away these copies in many cases, and my blog post Return Value Optimization for AQL shows performance benefits of 10-25% that can be expected due to the optimization.

More info...

AQL Functions Enhancements: Boosting ArangoDB Query Capabilities

Waiting for a git pull to complete over an 8 KiB/s internet connection is boring. So I thought I’d rather use the idle time and quickly write about some performance improvements for certain AQL functions that were recently completed and that will become available with ArangoDB 2.6.

The improvements affect the following AQL functions:

  • UNSET(): remove specified attributes from an object/document
  • KEEP(): keep only specified attributes of an object/document
  • MERGE(): merge the attributes of multiple objects/documents

This blog post shows a few example queries that will benefit from 50 to more than 60 % reductions in query execution times due to the changes done to these functions.

(more…)

More info...

Efficient Data Collection with Hash Tables: ArangoDB Insights

ArangoDB 2.6 will feature an alternative hash implementation of the AQL COLLECT operation. The new implementation can speed up some AQL queries that can not exploit indexes on the COLLECT group criteria.

This blog post provides a preview of the feature and shows some nice performance improvements. It also explains the COLLECT-related optimizer parts and how the optimizer will decide whether to use the new or the traditional implementation.

(more…)

More info...

AQB Update: Write More Readable Queries with ArangoDB

The latest update to the AQL Query Builder for JavaScript addresses a major pain point: the “prefix notation” or LISP style syntax of AQL operator methods. Instead of calling the operator methods on the query builder object itself, you can now directly call them as methods on value objects.

Let’s say you want to write a query that takes all non-admin users with a power level over 9000 and returns their score rounded to the closest 100. In plain AQL this could be written like this:

FOR user IN users
FILTER user.isAdmin == false && user.powerLevel > 9000
RETURN ROUND(user.score / 100) * 100

(more…)

More info...

Enhancements for Data Modification Queries: ArangoDB Updates

Data-modification queries were enhanced in ArangoDB 2.4 to be able to also return the inserted, update or removed documents. For example, the following statement inserted a few documents and also returned them with all their attributes:

FOR i IN 1..10
  INSERT { value: i } IN test
  LET inserted = NEW
  RETURN inserted

The syntax for returning documents from data-modification queries only supported the exact above format. Using a LET clause was required, and the RETURN clause was limited to returning the variable introduced by the LET. These syntax restrictions have been lifted in the devel branch, which will become release 2.6 eventually.

The changes make returning values from data-modification statements easier and also more flexible.
(more…)

More info...

Upsert Operations in ArangoDB: Efficient Data Management

This week saw the completion of the AQL UPSERT command. This command will be very helpful in a lot of use cases, including the following:

  • ensure that a document exists
  • update a document if it exists, otherwise create it
  • replace a document if it exists, otherwise create it

The UPSERT command is executed on the server side and so delivers client applications from issuing a fetch command followed by a separate, conditional UPDATE or INSERT command.

The general format of an UPSERT statement is:

UPSERT search-document
INSERT insert-expression
UPDATE update-expression
IN collection-name

Jan collected a few example invocations of UPSERT in his blog.

More info...

Enhanced AQL in ArangoDB 2.5: Improved Query Capabilities

Contained in 2.5 are some small but useful AQL language improvements plus several AQL optimizer improvements.

We are working on further AQL improvements for 2.5, but work is still ongoing. This post summarizes the improvements that are already completed and will be shipped with the initial ArangoDB 2.5 release.

(more…)

More info...

Dynamic Attribute Names in AQL: ArangoDB Techniques

On our mailing list, there is quite often the question whether attribute names in objects returned from AQL queries can be made dynamic. Jan discusses in his blog how such dynamic attribute names could be expressed and shows the current implementation that comes with ArangoDB 2.5 – adapting an ES6 proposal that might bring robust dynamic variable names to JavaScript as well.

In ArangoDB 2.5 you will be able to use dynamic variable names as follows:

FOR doc IN collection
  LET type = doc.type;
  RETURN { [type] : doc.value }

Functions are allowed as well:

FOR i IN 1..3 
  RETURN { 
    [ CONCAT('test', i) ] : i
  }    

Read on here

More info...

Get the latest tutorials,
blog posts and news: