Skip to content

Commit

Permalink
Initial support for isLastOp in stream viewer #233
Browse files Browse the repository at this point in the history
  • Loading branch information
krlawrence committed Jun 20, 2022
1 parent bd2b07c commit d6cbe8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/graph_notebook/magics/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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_COMMIT_TIMESTAMP
STREAM_COMMIT_TIMESTAMP, STREAM_IS_LASTOP


class EventId:
Expand Down Expand Up @@ -180,14 +180,17 @@ def show_records(self, records):
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">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)
Expand All @@ -197,19 +200,26 @@ def show_records(self, records):
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">{}'.format(commit_num)
html += '<td 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;">'

if STREAM_IS_LASTOP in record:
lastop = record[STREAM_IS_LASTOP]
if lastop:
lastop_text = 'Y'

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: center;">{}</td>
<td 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
1 change: 1 addition & 0 deletions src/graph_notebook/neptune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
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 d6cbe8d

Please sign in to comment.