From 72425ca77ee50f9dd3517e7bb3522895f226da85 Mon Sep 17 00:00:00 2001 From: Alexey Bakharew Date: Tue, 6 Jun 2023 15:55:42 +0200 Subject: [PATCH 1/4] More detailed version output. Delete only service keys from views --- arango/database.py | 14 +++++++++----- arango/formatter.py | 47 ++++++++++----------------------------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/arango/database.py b/arango/database.py index 15204d43..da7ffc0a 100644 --- a/arango/database.py +++ b/arango/database.py @@ -300,21 +300,25 @@ def response_handler(resp: Response) -> Any: return self._execute(request, response_handler) - def version(self) -> Result[str]: + def version(self, details: bool = False) -> Result[Any]: """Return ArangoDB server version. - + :param details: Return more detailed version output + :type details: bool | None :return: Server version. :rtype: str :raise arango.exceptions.ServerVersionError: If retrieval fails. """ request = Request( - method="get", endpoint="/_api/version", params={"details": False} + method="get", endpoint="/_api/version", params={"details": details} ) - def response_handler(resp: Response) -> str: + def response_handler(resp: Response) -> Any: if not resp.is_success: raise ServerVersionError(resp, request) - return str(resp.body["version"]) + if not details: + return str(resp.body["version"]) + else: + return resp.body return self._execute(request, response_handler) diff --git a/arango/formatter.py b/arango/formatter.py index 27f5c172..a91fb721 100644 --- a/arango/formatter.py +++ b/arango/formatter.py @@ -854,44 +854,17 @@ def format_view(body: Json) -> Json: :return: Formatted body. :rtype: dict """ - result: Json = {} + # Remove only unnecessary keys + if "error" in body: + body.pop("error") + if "code" in body: + body.pop("code") if "globallyUniqueId" in body: - result["global_id"] = body["globallyUniqueId"] - if "id" in body: - result["id"] = body["id"] - if "name" in body: - result["name"] = body["name"] - if "type" in body: - result["type"] = body["type"] - if "cleanupIntervalStep" in body: - result["cleanup_interval_step"] = body["cleanupIntervalStep"] - if "commitIntervalMsec" in body: - result["commit_interval_msec"] = body["commitIntervalMsec"] - if "consolidationIntervalMsec" in body: - result["consolidation_interval_msec"] = body["consolidationIntervalMsec"] - if "consolidationPolicy" in body: - result["consolidation_policy"] = format_view_consolidation_policy( - body["consolidationPolicy"] - ) - if "primarySort" in body: - result["primary_sort"] = body["primarySort"] - if "primarySortCompression" in body: - result["primary_sort_compression"] = body["primarySortCompression"] - if "storedValues" in body: - result["stored_values"] = body["storedValues"] - if "writebufferIdle" in body: - result["writebuffer_idle"] = body["writebufferIdle"] - if "writebufferActive" in body: - result["writebuffer_active"] = body["writebufferActive"] - if "writebufferSizeMax" in body: - result["writebuffer_max_size"] = body["writebufferSizeMax"] - if "links" in body: - result["links"] = body["links"] - if "indexes" in body: - result["indexes"] = body["indexes"] - - return verify_format(body, result) - + global_id = body["globallyUniqueId"] + body.pop("globallyUniqueId") + body["global_id"] = global_id + + return body def format_vertex(body: Json) -> Json: """Format vertex data. From ffa02bad9af9073970ec8cd67a1818304b1b8f55 Mon Sep 17 00:00:00 2001 From: Alexey Bakharew Date: Wed, 7 Jun 2023 11:41:12 +0200 Subject: [PATCH 2/4] add support for 'optimizeTopK' --- arango/formatter.py | 48 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/arango/formatter.py b/arango/formatter.py index a91fb721..fdbf8c50 100644 --- a/arango/formatter.py +++ b/arango/formatter.py @@ -854,17 +854,45 @@ def format_view(body: Json) -> Json: :return: Formatted body. :rtype: dict """ - # Remove only unnecessary keys - if "error" in body: - body.pop("error") - if "code" in body: - body.pop("code") + result: Json = {} if "globallyUniqueId" in body: - global_id = body["globallyUniqueId"] - body.pop("globallyUniqueId") - body["global_id"] = global_id - - return body + result["global_id"] = body["globallyUniqueId"] + if "id" in body: + result["id"] = body["id"] + if "name" in body: + result["name"] = body["name"] + if "type" in body: + result["type"] = body["type"] + if "cleanupIntervalStep" in body: + result["cleanup_interval_step"] = body["cleanupIntervalStep"] + if "commitIntervalMsec" in body: + result["commit_interval_msec"] = body["commitIntervalMsec"] + if "consolidationIntervalMsec" in body: + result["consolidation_interval_msec"] = body["consolidationIntervalMsec"] + if "consolidationPolicy" in body: + result["consolidation_policy"] = format_view_consolidation_policy( + body["consolidationPolicy"] + ) + if "primarySort" in body: + result["primary_sort"] = body["primarySort"] + if "primarySortCompression" in body: + result["primary_sort_compression"] = body["primarySortCompression"] + if "storedValues" in body: + result["stored_values"] = body["storedValues"] + if "writebufferIdle" in body: + result["writebuffer_idle"] = body["writebufferIdle"] + if "writebufferActive" in body: + result["writebuffer_active"] = body["writebufferActive"] + if "writebufferSizeMax" in body: + result["writebuffer_max_size"] = body["writebufferSizeMax"] + if "links" in body: + result["links"] = body["links"] + if "indexes" in body: + result["indexes"] = body["indexes"] + if "optimizeTopK" in body: + result["optimizeTopK"] = body["optimizeTopK"] + + return verify_format(body, result) def format_vertex(body: Json) -> Json: """Format vertex data. From 3c988d975e611515e112abf28c90d3150e308266 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Wed, 7 Jun 2023 13:16:48 +0300 Subject: [PATCH 3/4] Adjusting db.version test --- tests/test_database.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_database.py b/tests/test_database.py index f56122c0..70d5af5b 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -68,6 +68,7 @@ def test_database_misc_methods(sys_db, db, bad_db): # Test get server version assert isinstance(db.version(), str) + assert isinstance(db.version(details=True), dict) # Test get server version with bad database with assert_raises(ServerVersionError) as err: From 733882bf77d97c7cd96e4a9b8db30364b40cc428 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Wed, 7 Jun 2023 13:17:37 +0300 Subject: [PATCH 4/4] Adding CHANGELOG entry and "introduced in" comment --- CHANGELOG.md | 5 ++++- arango/formatter.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4883b69..c589a712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ main ---- -* Adding peak_memory_usage as a new property of AQL queries, available since ArangoDB 3.11. +* The db.version() now has a new optional parameter "details" that can be used to return additional information about + the server version. The default is still false, so the old behavior is preserved. + +* Added peak_memory_usage as a new property of AQL queries, available since ArangoDB 3.11. * The explain method of AQL queries includes the "stats" field in the returned object. Note that the REST API returns it separately from the "plan" field, but for now we have to merge them together to ensure backward compatibility. diff --git a/arango/formatter.py b/arango/formatter.py index 05ed89eb..09801026 100644 --- a/arango/formatter.py +++ b/arango/formatter.py @@ -901,11 +901,14 @@ def format_view(body: Json) -> Json: result["links"] = body["links"] if "indexes" in body: result["indexes"] = body["indexes"] + + # Introduced in 3.12 EE if "optimizeTopK" in body: result["optimizeTopK"] = body["optimizeTopK"] return verify_format(body, result) + def format_vertex(body: Json) -> Json: """Format vertex data.