Skip to content

Commit 6c0633c

Browse files
authored
Add %get_graph line magic, enable %status for Neptune Analytics (#611)
* Add %status support for Neptune Analytics * update changelog
1 parent f6acdd7 commit 6c0633c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
44

55
## Upcoming
66
- Added `%reset_graph` line magic ([Link to PR](https://github.com/aws/graph-notebook/pull/610))
7+
- Added `%get_graph` line magic and enabled `%status` for Neptune Analytics ([Link to PR](https://github.com/aws/graph-notebook/pull/611))
78

89
## Release 4.3.1 (June 3, 2024)
910

src/graph_notebook/magics/graph_magic.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,11 @@ def opencypher_status(self, line='', local_ns: dict = None):
14111411
@line_magic
14121412
@needs_local_scope
14131413
@display_exceptions
1414-
@neptune_db_only
14151414
def status(self, line='', local_ns: dict = None):
1415+
if self.client.is_analytics_domain():
1416+
logger.info(f'Redirected %status call to %get_graph.')
1417+
self.get_graph(line, local_ns)
1418+
return
14161419
logger.info(f'calling for status on endpoint {self.graph_notebook_config.host}')
14171420
parser = argparse.ArgumentParser()
14181421
parser.add_argument('--silent', action='store_true', default=False, help="Display no output.")
@@ -1439,6 +1442,33 @@ def status(self, line='', local_ns: dict = None):
14391442
print()
14401443
return status_res
14411444

1445+
@line_magic
1446+
@needs_local_scope
1447+
@display_exceptions
1448+
@neptune_graph_only
1449+
def get_graph(self, line='', local_ns: dict = None):
1450+
logger.info(f'calling for status on endpoint {self.graph_notebook_config.host}')
1451+
parser = argparse.ArgumentParser()
1452+
parser.add_argument('--include-metadata', action='store_true', default=False,
1453+
help="Display the response metadata if it is available.")
1454+
parser.add_argument('--silent', action='store_true', default=False, help="Display no output.")
1455+
parser.add_argument('--store-to', type=str, default='', help='store query result to this variable')
1456+
args = parser.parse_args(line.split())
1457+
1458+
try:
1459+
graph_id = self.client.get_graph_id()
1460+
res = self.client.get_graph(graph_id=graph_id)
1461+
if not args.include_metadata:
1462+
res.pop('ResponseMetadata', None)
1463+
if not args.silent:
1464+
print(json.dumps(res, indent=2, default=str))
1465+
store_to_ns(args.store_to, res, local_ns)
1466+
except Exception as e:
1467+
if not args.silent:
1468+
print("Encountered an error when attempting to retrieve graph status:\n")
1469+
print(e)
1470+
store_to_ns(args.store_to, e, local_ns)
1471+
14421472
@line_magic
14431473
@needs_local_scope
14441474
@display_exceptions

src/graph_notebook/neptune/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,16 @@ def reset_graph(self, graph_id: str = '', no_skip_snapshot: bool = False) -> dic
589589
logger.debug(f"Reset Graph call failed with service exception: {e}")
590590
raise e
591591

592+
def get_graph(self, graph_id: str = '') -> dict:
593+
try:
594+
res = self.neptune_graph_client.get_graph(
595+
graphIdentifier=graph_id
596+
)
597+
return res
598+
except ClientError as e:
599+
logger.debug(f"GetGraph call failed with service exception: {e}")
600+
raise e
601+
592602
def dataprocessing_start(self, s3_input_uri: str, s3_output_uri: str, **kwargs) -> requests.Response:
593603
data = {
594604
'inputDataS3Location': s3_input_uri,

0 commit comments

Comments
 (0)