Skip to content

Commit e5b44ea

Browse files
authored
Normalize stream endpoint names (#261)
* Normalize stream endpoint names * Update ChangeLog.md * Make the dropdown slightly wider
1 parent f61b69b commit e5b44ea

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Starting with v1.31.6, this file will contain a record of major features and updates made in each release of graph-notebook.
44

55
## Upcoming
6+
- Changed the `%stream_viewer` magic to use `PropertyGraph` and `RDF` as the stream types. This better aligns with Gremlin and openCypher sharing the `PropertyGraph` stream. ([Link to PR](https://github.com/aws/graph-notebook/pull/261))
67
- Updated the airports property graph seed files to the latest level and suffixed all doubles with 'd'. ([Link to PR](https://github.com/aws/graph-notebook/pull/257))
78
- Added grouping by depth for Gremlin and openCypher queries ([PR #1](https://github.com/aws/graph-notebook/pull/241))([PR #2](https://github.com/aws/graph-notebook/pull/251))
89
- Added grouping by raw node results ([Link to PR](https://github.com/aws/graph-notebook/pull/253))

src/graph_notebook/magics/graph_magic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from graph_notebook.magics.streams import StreamViewer
3535
from graph_notebook.neptune.client import ClientBuilder, Client, VALID_FORMATS, PARALLELISM_OPTIONS, PARALLELISM_HIGH, \
3636
LOAD_JOB_MODES, MODE_AUTO, FINAL_LOAD_STATUSES, SPARQL_ACTION, FORMAT_CSV, FORMAT_OPENCYPHER, FORMAT_NTRIPLE, \
37-
FORMAT_NQUADS, FORMAT_RDFXML, FORMAT_TURTLE
37+
FORMAT_NQUADS, FORMAT_RDFXML, FORMAT_TURTLE, STREAM_RDF, STREAM_PG, STREAM_ENDPOINTS
3838
from graph_notebook.network import SPARQLNetwork
3939
from graph_notebook.network.gremlin.GremlinNetwork import parse_pattern_list_str, GremlinNetwork
4040
from graph_notebook.visualization.rows_and_columns import sparql_get_rows_and_columns, opencypher_get_rows_and_columns
@@ -230,9 +230,9 @@ def graph_notebook_config(self, line='', cell=''):
230230
@line_magic
231231
def stream_viewer(self,line):
232232
parser = argparse.ArgumentParser()
233-
parser.add_argument('language', type=str.lower, nargs='?', default='gremlin',
234-
help='language (default=gremlin) [gremlin|sparql]',
235-
choices = ['gremlin','sparql'])
233+
parser.add_argument('language', nargs='?', default=STREAM_PG,
234+
help=f'language (default={STREAM_PG}) [{STREAM_PG}|{STREAM_RDF}]',
235+
choices = [STREAM_PG, STREAM_RDF])
236236

237237
parser.add_argument('--limit', type=int, default=10, help='Maximum number of rows to display at a time')
238238

src/graph_notebook/magics/streams.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import ipywidgets as widgets
44
import queue
55
from IPython.display import display, HTML
6-
from graph_notebook.neptune.client import STREAM_AT, STREAM_AFTER, STREAM_TRIM, STREAM_EXCEPTION_NOT_FOUND,STREAM_EXCEPTION_NOT_ENABLED
6+
from graph_notebook.neptune.client import STREAM_AT, STREAM_AFTER, STREAM_TRIM, STREAM_EXCEPTION_NOT_FOUND,\
7+
STREAM_EXCEPTION_NOT_ENABLED, STREAM_PG, STREAM_RDF, STREAM_ENDPOINTS
78

89

910
class EventId:
@@ -99,8 +100,8 @@ def __init__(self, wb_client, uri_with_port, language, limit=10):
99100
self.back_button = widgets.Button(description='Back', tooltip='Back', disabled=True)
100101
self.back_button.layout.width = '10%'
101102
self.back_button.on_click(self.on_back)
102-
self.dropdown = widgets.Dropdown(options=['gremlin', 'sparql'], value=language, disabled=False)
103-
self.dropdown.layout.width = '10%'
103+
self.dropdown = widgets.Dropdown(options=[STREAM_PG, STREAM_RDF], value=language, disabled=False)
104+
self.dropdown.layout.width = '15%'
104105
self.dropdown.observe(self.on_dropdown_changed)
105106
self.out = widgets.Output()
106107
self.ui = widgets.HBox([self.slider, self.back_button, self.next_button, self.dropdown])
@@ -159,6 +160,8 @@ def on_back(self, _):
159160
self.last_displayed_event_id.update(last_event)
160161

161162
def init_display(self, language):
163+
# Map the selected stream type to the actual endpoint name
164+
language = STREAM_ENDPOINTS[language]
162165
self.history = queue.LifoQueue(100)
163166
self.back_button.disabled = True
164167
self.update_slider_min_max_values(language)

src/graph_notebook/neptune/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@
7272
EXTRA_HEADERS = {'content-type': 'application/json'}
7373
SPARQL_ACTION = 'sparql'
7474

75+
# Constants used by the Stream Viewer.
7576
STREAM_AT = 'AT_SEQUENCE_NUMBER'
7677
STREAM_AFTER = 'AFTER_SEQUENCE_NUMBER'
7778
STREAM_TRIM = 'TRIM_HORIZON'
79+
STREAM_LATEST = 'LATEST'
7880
STREAM_EXCEPTION_NOT_FOUND = 'StreamRecordsNotFoundException'
7981
STREAM_EXCEPTION_NOT_ENABLED = 'UnsupportedOperationException'
8082

83+
# A mapping from the name in the stream_viewer widget dropdown, to the actual Neptune
84+
# Streams endpoint (API) name. We do not map 'PropertyGraph' to 'pg' to maintain
85+
# compatability with older engine releases that did not have a 'pg' endpoint.
86+
87+
STREAM_PG = 'PropertyGraph'
88+
STREAM_RDF = 'RDF'
89+
STREAM_ENDPOINTS = {STREAM_PG: 'gremlin', STREAM_RDF: 'sparql'}
90+
8191

8292
class Client(object):
8393
def __init__(self, host: str, port: int = DEFAULT_PORT, ssl: bool = True, region: str = DEFAULT_REGION,

0 commit comments

Comments
 (0)