Skip to content

Commit

Permalink
Issue 233 (#311)
Browse files Browse the repository at this point in the history
* Initial work to add the commit timestamp to the stream viewer

* Add UTC human readable timestamp

* Put the human readable date in parens #233

* Initial support for isLastOp in stream viewer #233

* Center the operation column text #233

* Improve hover help text #233

* Update changelog - still need to add PR info later. #233

* Add link to pR in the changelog

Co-authored-by: Michael Chin <[email protected]>
  • Loading branch information
krlawrence and michaelnchin authored Jun 21, 2022
1 parent 3728b8c commit 467414c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
Starting with v1.31.6, this file will contain a record of major features and updates made in each release of graph-notebook.

## Upcoming
- Improved the `%stream_viewer` magic to show the commit timestamp and `isLastOp` information,
if available. Also added additional hover (help) text to the stream viewer. ([Link to PR](https://github.com/aws/graph-notebook/pull/311))
- Added `--max-content-length` option to `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/305))


## Release 3.4.1 (June 7, 2022)
- Identity Graph - ETL notebook ([Link to PR](https://github.com/aws/graph-notebook/pull/288))
- Path: 03-Identity-Graphs>03-Jumpstart-Identity-Graphs-Using-Canonical-Model-and-ETL
Expand Down
42 changes: 31 additions & 11 deletions src/graph_notebook/magics/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import json
import ipywidgets as widgets
import queue
from datetime import datetime
from IPython.display import display, HTML
from graph_notebook.neptune.client import STREAM_AT, STREAM_AFTER, STREAM_TRIM, STREAM_EXCEPTION_NOT_FOUND,\
STREAM_EXCEPTION_NOT_ENABLED, STREAM_PG, STREAM_RDF, STREAM_ENDPOINTS
STREAM_EXCEPTION_NOT_ENABLED, STREAM_PG, STREAM_RDF, STREAM_ENDPOINTS,\
STREAM_COMMIT_TIMESTAMP, STREAM_IS_LASTOP


class EventId:
Expand Down Expand Up @@ -176,30 +178,48 @@ def show_records(self, records):
html = '''<html><body><table style="border: 1px solid black">'''

html += '''<tr>
<th style="text-align: center" >Tx/Op#</th>
<th style="text-align: center">Operation</th>
<th style="text-align: center">Data</th>
<th style="text-align: center" title="The transaction or op number within a transaction">Tx/Op#</th>
<th style="text-align: center" title="The type of operation such as ADD or REMOVE">Operation</th>
<th style="text-align: center" title="Indicates if this is the final Op of a transaction. This feature requires a Neptune engine version of 1.1.1.0 or higher.">LastOp</th>
<th style="text-align: center;">Data</th>
</tr>'''

commit_num = None

for record in records:
current_commit_num = record['eventId']['commitNum']

timestamp = None
lastop = False
lastop_text = ''
if STREAM_COMMIT_TIMESTAMP in record:
timestamp = record[STREAM_COMMIT_TIMESTAMP]
utc_text = datetime.utcfromtimestamp(timestamp/1000)

data = json.dumps(record['data']).replace('&', '&amp;').replace('<', '&lt;')

if commit_num is None or current_commit_num != commit_num:
commit_num = current_commit_num
html += '<tr title="The commit number for this transaction" style="border: 1px solid black; background-color: gainsboro ; font-weight: bold;">'
html += '<td style="border: 1px solid black; vertical-align: top; text-align: left;" colspan="3">{}</td>'.format(commit_num)
html += '<tr style="border: 1px solid black; background-color: gainsboro ; font-weight: bold;">'
html += '<td title="The commit number for this transaction" style="border: 1px solid black; vertical-align: top; text-align: left;" colspan="4">{}'.format(commit_num)
if timestamp != None:
html += '&nbsp;&nbsp;&nbsp;Timestamp = {}'.format(timestamp)
html += '&nbsp;&nbsp;&nbsp;( {} UTC )'.format(utc_text)
html += '</td>'
html += '</tr><tr style="border: 1px solid black;">'

html += '<tr title="The operation number within this transaction" style="border: 1px solid black; background-color: white;">'
html += '''<td style="border: 1px solid black; vertical-align: top;">{}</td>
<td style="border: 1px solid black; vertical-align: top;">{}</td>
<td style="border: 1px solid black; vertical-align: top; text-align: left;">{}</td></tr>'''.format(
if STREAM_IS_LASTOP in record:
lastop = record[STREAM_IS_LASTOP]
if lastop:
lastop_text = 'Y'

html += '<tr style="border: 1px solid black; background-color: white;">'
html += '''<td title="The operation number within this transaction" style="border: 1px solid black; vertical-align: top;">{}</td>
<td title="The operation performed"style="border: 1px solid black; vertical-align: top;text-align: center;">{}</td>
<td title="A Y indicates the final Op for a transaction. Earlier Neptune versions do not support this option." style="border: 1px solid black; vertical-align: top;text-align: center;">{}</td>
<td title="Details of the change made by this operation" style="border: 1px solid black; vertical-align: top; text-align: left;">{}</td></tr>'''.format(
record['eventId']['opNum'],
record['op'],
lastop_text,
data)

html += '</table></body></html>'
Expand Down
2 changes: 2 additions & 0 deletions src/graph_notebook/neptune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
STREAM_AFTER = 'AFTER_SEQUENCE_NUMBER'
STREAM_TRIM = 'TRIM_HORIZON'
STREAM_LATEST = 'LATEST'
STREAM_COMMIT_TIMESTAMP = 'commitTimestamp'
STREAM_IS_LASTOP = 'isLastOp'
STREAM_EXCEPTION_NOT_FOUND = 'StreamRecordsNotFoundException'
STREAM_EXCEPTION_NOT_ENABLED = 'UnsupportedOperationException'

Expand Down

0 comments on commit 467414c

Please sign in to comment.