46
46
from graph_notebook .magics .streams import StreamViewer
47
47
from graph_notebook .neptune .client import ClientBuilder , Client , PARALLELISM_OPTIONS , PARALLELISM_HIGH , \
48
48
LOAD_JOB_MODES , MODE_AUTO , FINAL_LOAD_STATUSES , SPARQL_ACTION , FORMAT_CSV , FORMAT_OPENCYPHER , FORMAT_NTRIPLE , \
49
- DB_LOAD_TYPES , ANALYTICS_LOAD_TYPES , VALID_BULK_FORMATS , VALID_INCREMENTAL_FORMATS , \
49
+ DB_LOAD_TYPES , ANALYTICS_LOAD_TYPES , VALID_BULK_FORMATS , VALID_INCREMENTAL_FORMATS , \
50
50
FORMAT_NQUADS , FORMAT_RDFXML , FORMAT_TURTLE , STREAM_RDF , STREAM_PG , STREAM_ENDPOINTS , \
51
51
NEPTUNE_CONFIG_HOST_IDENTIFIERS , is_allowed_neptune_host , \
52
52
STATISTICS_LANGUAGE_INPUTS , STATISTICS_LANGUAGE_INPUTS_SPARQL , STATISTICS_MODES , SUMMARY_MODES , \
180
180
MEDIA_TYPE_NTRIPLES_TEXT , MEDIA_TYPE_TURTLE , MEDIA_TYPE_N3 , MEDIA_TYPE_TRIX ,
181
181
MEDIA_TYPE_TRIG , MEDIA_TYPE_RDF4J_BINARY ]
182
182
183
- byte_units = {'B' : 1 , 'KB' : 1024 , 'MB' : 1024 ** 2 , 'GB' : 1024 ** 3 , 'TB' : 1024 ** 4 }
183
+ byte_units = {'B' : 1 , 'KB' : 1024 , 'MB' : 1024 ** 2 , 'GB' : 1024 ** 3 , 'TB' : 1024 ** 4 }
184
184
185
185
186
186
class QueryMode (Enum ):
@@ -521,11 +521,11 @@ def neptune_config_allowlist(self, line='', cell=''):
521
521
522
522
@line_magic
523
523
@neptune_db_only
524
- def stream_viewer (self ,line ):
524
+ def stream_viewer (self , line ):
525
525
parser = argparse .ArgumentParser ()
526
526
parser .add_argument ('language' , nargs = '?' , default = STREAM_PG ,
527
527
help = f'language (default={ STREAM_PG } ) [{ STREAM_PG } |{ STREAM_RDF } ]' ,
528
- choices = [STREAM_PG , STREAM_RDF ])
528
+ choices = [STREAM_PG , STREAM_RDF ])
529
529
530
530
parser .add_argument ('--limit' , type = int , default = 10 , help = 'Maximum number of rows to display at a time' )
531
531
@@ -534,7 +534,7 @@ def stream_viewer(self,line):
534
534
language = args .language
535
535
limit = args .limit
536
536
uri = self .client .get_uri_with_port ()
537
- viewer = StreamViewer (self .client ,uri ,language ,limit = limit )
537
+ viewer = StreamViewer (self .client , uri , language , limit = limit )
538
538
viewer .show ()
539
539
540
540
@line_magic
@@ -877,7 +877,8 @@ def sparql(self, line='', cell='', local_ns: dict = None):
877
877
if query_type == 'CONSTRUCT' or query_type == 'DESCRIBE' :
878
878
lines = []
879
879
for b in results ['results' ]['bindings' ]:
880
- lines .append (f'{ b ["subject" ]["value" ]} \t { b ["predicate" ]["value" ]} \t { b ["object" ]["value" ]} ' )
880
+ lines .append (
881
+ f'{ b ["subject" ]["value" ]} \t { b ["predicate" ]["value" ]} \t { b ["object" ]["value" ]} ' )
881
882
raw_output = widgets .Output (layout = sparql_layout )
882
883
with raw_output :
883
884
html = sparql_construct_template .render (lines = lines )
@@ -1168,7 +1169,8 @@ def gremlin(self, line, cell, local_ns: dict = None):
1168
1169
query_start = time .time () * 1000 # time.time() returns time in seconds w/high precision; x1000 to get in ms
1169
1170
if self .graph_notebook_config .proxy_host != '' and self .client .is_neptune_domain ():
1170
1171
using_http = True
1171
- query_res_http = self .client .gremlin_http_query (cell , headers = {'Accept' : 'application/vnd.gremlin-v1.0+json;types=false' })
1172
+ query_res_http = self .client .gremlin_http_query (cell , headers = {
1173
+ 'Accept' : 'application/vnd.gremlin-v1.0+json;types=false' })
1172
1174
query_res_http .raise_for_status ()
1173
1175
query_res_http_json = query_res_http .json ()
1174
1176
query_res = query_res_http_json ['result' ]['data' ]
@@ -1603,7 +1605,7 @@ def on_button_delete_clicked(b):
1603
1605
with output :
1604
1606
job_status_output .clear_output ()
1605
1607
interval_output .close ()
1606
- total_status_wait = max_status_retries * poll_interval
1608
+ total_status_wait = max_status_retries * poll_interval
1607
1609
print (result )
1608
1610
if interval_check_response .get ("status" ) != 'healthy' :
1609
1611
print (f"Could not retrieve the status of the reset operation within the allotted time of "
@@ -1849,7 +1851,7 @@ def load(self, line='', local_ns: dict = None):
1849
1851
value = str (args .concurrency ),
1850
1852
placeholder = 1 ,
1851
1853
min = 1 ,
1852
- max = 2 ** 16 ,
1854
+ max = 2 ** 16 ,
1853
1855
disabled = False ,
1854
1856
layout = widgets .Layout (display = concurrency_hbox_visibility ,
1855
1857
width = widget_width )
@@ -2057,8 +2059,8 @@ def on_button_clicked(b):
2057
2059
named_graph_uri_hbox .children = (named_graph_uri_hbox_label , named_graph_uri ,)
2058
2060
base_uri_hbox .children = (base_uri_hbox_label , base_uri ,)
2059
2061
dep_hbox .children = (dep_hbox_label , dependencies ,)
2060
- concurrency_hbox .children = (concurrency_hbox_label , concurrency , )
2061
- periodic_commit_hbox .children = (periodic_commit_hbox_label , periodic_commit , )
2062
+ concurrency_hbox .children = (concurrency_hbox_label , concurrency ,)
2063
+ periodic_commit_hbox .children = (periodic_commit_hbox_label , periodic_commit ,)
2062
2064
2063
2065
validated = True
2064
2066
validation_label_style = DescriptionStyle (color = 'red' )
@@ -2210,8 +2212,9 @@ def on_button_clicked(b):
2210
2212
2211
2213
if poll_status .value == 'FALSE' :
2212
2214
start_msg_label = widgets .Label (f'Load started successfully!' )
2213
- polling_msg_label = widgets .Label (f'You can run "%load_status { load_result ["payload" ]["loadId" ]} " '
2214
- f'in another cell to check the current status of your bulk load.' )
2215
+ polling_msg_label = widgets .Label (
2216
+ f'You can run "%load_status { load_result ["payload" ]["loadId" ]} " '
2217
+ f'in another cell to check the current status of your bulk load.' )
2215
2218
start_msg_hbox = widgets .HBox ([start_msg_label ])
2216
2219
polling_msg_hbox = widgets .HBox ([polling_msg_label ])
2217
2220
vbox = widgets .VBox ([start_msg_hbox , polling_msg_hbox ])
@@ -2254,11 +2257,13 @@ def on_button_clicked(b):
2254
2257
with job_status_output :
2255
2258
# parse status & execution_time differently for Analytics and NeptuneDB
2256
2259
overall_status = \
2257
- interval_check_response ["payload" ]["status" ] if self .client .is_analytics_domain () \
2258
- else interval_check_response ["payload" ]["overallStatus" ]["status" ]
2260
+ interval_check_response ["payload" ][
2261
+ "status" ] if self .client .is_analytics_domain () \
2262
+ else interval_check_response ["payload" ]["overallStatus" ]["status" ]
2259
2263
total_time_spent = \
2260
- interval_check_response ["payload" ]["timeElapsedSeconds" ] if self .client .is_analytics_domain () \
2261
- else interval_check_response ["payload" ]["overallStatus" ]["totalTimeSpent" ]
2264
+ interval_check_response ["payload" ][
2265
+ "timeElapsedSeconds" ] if self .client .is_analytics_domain () \
2266
+ else interval_check_response ["payload" ]["overallStatus" ]["totalTimeSpent" ]
2262
2267
print (f'Overall Status: { overall_status } ' )
2263
2268
if overall_status in FINAL_LOAD_STATUSES :
2264
2269
execution_time = total_time_spent
@@ -3179,7 +3184,7 @@ def handle_opencypher_query(self, line, cell, local_ns):
3179
3184
"""
3180
3185
parser = argparse .ArgumentParser ()
3181
3186
parser .add_argument ('-pc' , '--plan-cache' , type = str .lower , default = 'auto' ,
3182
- help = f'Neptune Analytics only. Specifies the plan cache mode to use. '
3187
+ help = f'Specifies the plan cache mode to use. '
3183
3188
f'Accepted values: { OPENCYPHER_PLAN_CACHE_MODES } ' )
3184
3189
parser .add_argument ('-qt' , '--query-timeout' , type = int , default = None ,
3185
3190
help = f'Neptune Analytics only. Specifies the maximum query timeout in milliseconds.' )
@@ -3286,17 +3291,23 @@ def handle_opencypher_query(self, line, cell, local_ns):
3286
3291
first_tab_html = opencypher_explain_template .render (table = explain ,
3287
3292
link = f"data:text/html;base64,{ base64_str } " )
3288
3293
elif args .mode == 'query' :
3289
- if not self .client .is_analytics_domain ():
3290
- if args .plan_cache != 'auto' :
3291
- print ("planCache is not supported for Neptune DB, ignoring." )
3292
- if args .query_timeout is not None :
3293
- print ("queryTimeoutMilliseconds is not supported for Neptune DB, ignoring." )
3294
+ if not self .client .is_analytics_domain () and args .query_timeout is not None :
3295
+ print ("queryTimeoutMilliseconds is not supported for Neptune DB, ignoring." )
3294
3296
3295
3297
query_start = time .time () * 1000 # time.time() returns time in seconds w/high precision; x1000 to get in ms
3296
3298
oc_http = self .client .opencypher_http (cell , query_params = query_params ,
3297
3299
plan_cache = args .plan_cache ,
3298
3300
query_timeout = args .query_timeout )
3299
3301
query_time = time .time () * 1000 - query_start
3302
+ if oc_http .status_code == 400 and not self .client .is_analytics_domain () and args .plan_cache != "auto" :
3303
+ try :
3304
+ oc_http_ex = json .loads (oc_http .content .decode ('utf-8' ))
3305
+ if (oc_http_ex ["code" ] == "MalformedQueryException"
3306
+ and oc_http_ex ["detailedMessage" ].startswith ("Invalid input" )):
3307
+ print ("Please ensure that you are on NeptuneDB 1.3.2.0 or later when attempting to use "
3308
+ "--plan-cache." )
3309
+ except :
3310
+ pass
3300
3311
oc_http .raise_for_status ()
3301
3312
3302
3313
try :
0 commit comments