Comments on: AQL Functions Enhancements: Boosting ArangoDB Query Capabilities https://arangodb.com/2015/04/aql-functions-improvements/ The database for graph and beyond Wed, 26 Jun 2024 08:04:55 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: coltbg https://arangodb.com/2015/04/aql-functions-improvements/#comment-609 Tue, 26 May 2015 20:13:00 +0000 http://www.arangodb.com/?p=7438#comment-609 In reply to jsteemann.

Thanks a lot. I really appreciate your help …

]]>
By: jsteemann https://arangodb.com/2015/04/aql-functions-improvements/#comment-608 Tue, 26 May 2015 18:22:00 +0000 http://www.arangodb.com/?p=7438#comment-608 In reply to coltbg.

Yes, the skiplist index works fine with numeric values. Without an index there is no choice but to scan the entire collection and run the FILTER statement on all documents in it. With the index, this is avoided: the scan will start at the first document in the target range and end at the last document of the target range. That’s the minimum work the server can do.

]]>
By: coltbg https://arangodb.com/2015/04/aql-functions-improvements/#comment-607 Tue, 26 May 2015 17:10:00 +0000 http://www.arangodb.com/?p=7438#comment-607 In reply to jsteemann.

I’m using the this approach with numeric date values (UNIX), but as I read in this case without index this will analize all docs to get docs in range. Is that mean that skiplist work with numeric values?

]]>
By: jsteemann https://arangodb.com/2015/04/aql-functions-improvements/#comment-606 Tue, 26 May 2015 17:04:00 +0000 http://www.arangodb.com/?p=7438#comment-606 In reply to coltbg.

To get all documents in a given date range, you can probably usie something like the following AQL query:

FOR doc IN collection
FILTER doc.dt >= minDate && doc.dt <= maxDate
RETURN doc

provided your collection is named `collection` and your date attribute is named `dt`. You have to insert the date range bounds for `minDate` and `maxDate` of course. Numeric date values (e.g. UNIX timestamps) are normally faster and less space-consuming than when using string date values (e.g. "2015-05-26 19:03:00").

If the query will return many documents or the documents are quite big, it might be sensible to restrict the return value to just the attributes actually needed (about the same as avoiding `SELECT *` in SQL).

Note additionally that if you run that query often, it may be sensible to put a (sorted) skiplist index on the `dt` attribute. The query will then use the index and avoid a full collection scan.

]]>
By: coltbg https://arangodb.com/2015/04/aql-functions-improvements/#comment-605 Tue, 26 May 2015 16:47:00 +0000 http://www.arangodb.com/?p=7438#comment-605 In reply to jsteemann.

Thanks a lot for your help!
What is the fastest way to get range of documents between 2 dates? Im tryng to convert all dates to integer vales, but Im not sure that this is fastest way to do.

]]>
By: jsteemann https://arangodb.com/2015/04/aql-functions-improvements/#comment-604 Tue, 26 May 2015 09:05:00 +0000 http://www.arangodb.com/?p=7438#comment-604 In reply to coltbg.

Sorry for the delay. For some reasons the “new comments” notifications did not seem to work properly.

Regarding your question:
There is no AQL function that would create a diff of two documents, however, it can be done by combining several AQL expressions. I am not clear about how the result should look like, but one possible solution would be:

/* input document 1*/
LET doc1 = { foo: ‘bar’, a: 1, b: 2 }

/* input document 2 */
LET doc2 = { foo: ‘baz’, a: 2, c: 3 }

/* collect all attributes present in doc1, but missing in doc2 */
LET missing = (
FOR key IN ATTRIBUTES(doc1)
FILTER ! HAS(doc2, key)
RETURN {
[ key ]: doc1[key]
}
)

/* collect all attributes present in both docs, but with different values */
LET changed = (
FOR key IN ATTRIBUTES(doc1)
FILTER HAS(doc2, key) && doc1[key] != doc2[key]
RETURN {
[ key ] : {
old: doc1[key],
new: doc2[key]
}
}
)

/* collect all attributes present in doc2, but missing in doc1 */
LET added = (
FOR key IN ATTRIBUTES(doc2)
FILTER ! HAS(doc1, key)
RETURN {
[ key ] : doc2[key]
}
)

/* return final result */
RETURN {
missing: missing,
changed: changed,
added: added
}

]]>
By: coltbg https://arangodb.com/2015/04/aql-functions-improvements/#comment-603 Wed, 13 May 2015 12:32:00 +0000 http://www.arangodb.com/?p=7438#comment-603 Hi, I’m new in ArangoDB, and lookig for way to make diff between to docs. like MERGE RECURSIVE work but to get only diffs. How can be done that. Thanks in advance

]]>