From 46f5e68ca48643337783f4932830b104b8c9a1f1 Mon Sep 17 00:00:00 2001 From: Michael Chin Date: Tue, 1 Oct 2024 02:13:16 -0700 Subject: [PATCH] Use /queries endpoint for openCypher (#705) * Use /queries endpoint for %%oc * update changelog --- ChangeLog.md | 1 + src/graph_notebook/neptune/client.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 082eb03a..43933f34 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd ## Upcoming +- Updated `%%oc` to use the `/queries` endpoint for Neptune Analytics ([Link to PR](https://github.com/aws/graph-notebook/pull/705)) - Added experimental TinkerPop 4.0 support ([Link to PR](https://github.com/aws/graph-notebook/pull/704)) - Added documentation for group keys in `%%graph_notebook_vis_options` ([Link to PR](https://github.com/aws/graph-notebook/pull/703)) - Enabled `--query-timeout` on `%%oc explain` for Neptune Analytics ([Link to PR](https://github.com/aws/graph-notebook/pull/701)) diff --git a/src/graph_notebook/neptune/client.py b/src/graph_notebook/neptune/client.py index 75cf0200..84d6754d 100644 --- a/src/graph_notebook/neptune/client.py +++ b/src/graph_notebook/neptune/client.py @@ -541,23 +541,31 @@ def opencypher_http(self, query: str, headers: dict = None, explain: str = None, if headers is None: headers = {} - url = f'{self._http_protocol}://{self.host}:{self.port}/' + url = f'{self._http_protocol}://{self.host}' if self.is_neptune_domain(): - if 'content-type' not in headers: - headers['content-type'] = 'application/x-www-form-urlencoded' - url += 'openCypher' data = {} + if self.is_analytics_domain(): + url += f'/queries' + data['language'] = 'opencypher' + else: + if 'content-type' not in headers: + headers['content-type'] = 'application/x-www-form-urlencoded' + url += f':{self.port}/openCypher' if plan_cache: if plan_cache not in OPENCYPHER_PLAN_CACHE_MODES: print('Invalid --plan-cache mode specified, defaulting to auto.') else: - if self.is_analytics_domain(): - data['planCache'] = plan_cache - elif plan_cache != 'auto': - query = set_plan_cache_hint(query, plan_cache) + if plan_cache != 'auto': + if self.is_analytics_domain(): + data['planCache'] = plan_cache + else: + query = set_plan_cache_hint(query, plan_cache) data['query'] = query if explain: + if self.is_analytics_domain(): + data['explain.mode'] = explain + data['explain-mode'] = explain data['explain'] = explain headers['Accept'] = "text/html" if query_params: