@@ -241,6 +241,24 @@ def get_load_ids(neptune_client):
241241 return ids , res
242242
243243
244+ def process_statistics_400 (is_summary : bool , response ):
245+ bad_request_res = json .loads (response .text )
246+ res_code = bad_request_res ['code' ]
247+ if res_code == 'StatisticsNotAvailableException' :
248+ print ("No statistics found. Please ensure that auto-generation of DFE statistics is enabled by running "
249+ "'%statistics' and checking if 'autoCompute' if set to True. Alternately, you can manually "
250+ "trigger statistics generation by running: '%statistics --mode refresh'." )
251+ elif res_code == "BadRequestException" :
252+ print ("Unable to query the statistics endpoint. Please check that your Neptune instance is of size r5.large or "
253+ "greater in order to have DFE statistics enabled." )
254+ if is_summary and "Statistics is disabled" not in bad_request_res ["detailedMessage" ]:
255+ print ("\n Please also note that the Graph Summary API is only available in Neptune engine version 1.2.1.0 "
256+ "and later." )
257+ else :
258+ print ("Query encountered 400 error, please see below." )
259+ print (f"\n Full response: { bad_request_res } " )
260+
261+
244262# TODO: refactor large magic commands into their own modules like what we do with %neptune_ml
245263# noinspection PyTypeChecker
246264@magics_class
@@ -424,6 +442,12 @@ def statistics(self, line, local_ns: dict = None):
424442 return
425443
426444 statistics_res = self .client .statistics (args .language , args .summary , mode )
445+ if statistics_res .status_code == 400 :
446+ if args .summary :
447+ process_statistics_400 (True , statistics_res )
448+ else :
449+ process_statistics_400 (False , statistics_res )
450+ return
427451 statistics_res .raise_for_status ()
428452 statistics_res_json = statistics_res .json ()
429453 if not args .silent :
@@ -452,6 +476,9 @@ def summary(self, line, local_ns: dict = None):
452476 mode = "basic"
453477
454478 summary_res = self .client .statistics (args .language , True , mode )
479+ if summary_res .status_code == 400 :
480+ process_statistics_400 (True , summary_res )
481+ return
455482 summary_res .raise_for_status ()
456483 summary_res_json = summary_res .json ()
457484 if not args .silent :
0 commit comments