Allow start==end in stream_insert_context, if no data was provided.
This commit is contained in:
parent
ea838d05ae
commit
49d04db1d6
|
@ -449,7 +449,7 @@ class StreamInserter(object):
|
|||
self._interval_start = end_ts
|
||||
|
||||
# Double check endpoints
|
||||
if start_ts is None or end_ts is None:
|
||||
if (start_ts is None or end_ts is None) or (start_ts == end_ts):
|
||||
# If the block has no non-comment lines, it's OK
|
||||
try:
|
||||
self._get_first_noncomment(block)
|
||||
|
|
|
@ -134,16 +134,8 @@ class StreamInserterNumpy(nilmdb.client.client.StreamInserter):
|
|||
contiguous interval and may be None. 'dtype' is the Numpy
|
||||
dtype for this stream.
|
||||
"""
|
||||
self.last_response = None
|
||||
|
||||
super(StreamInserterNumpy, self).__init__(client, path, start, end)
|
||||
self._dtype = dtype
|
||||
self._client = client
|
||||
self._path = path
|
||||
|
||||
# Start and end for the overall contiguous interval we're
|
||||
# filling
|
||||
self._interval_start = start
|
||||
self._interval_end = end
|
||||
|
||||
# Max rows to send at once
|
||||
self._max_rows = self._max_data // self._dtype.itemsize
|
||||
|
@ -251,9 +243,12 @@ class StreamInserterNumpy(nilmdb.client.client.StreamInserter):
|
|||
# Next block continues where this one ended
|
||||
self._interval_start = end_ts
|
||||
|
||||
# If we have no endpoints, it's because we had no data to send.
|
||||
if start_ts is None or end_ts is None:
|
||||
return
|
||||
# If we have no endpoints, or equal endpoints, it's OK as long
|
||||
# as there's no data to send
|
||||
if (start_ts is None or end_ts is None) or (start_ts == end_ts):
|
||||
if len(array) == 0:
|
||||
return
|
||||
raise ClientError("have data to send, but invalid start/end times")
|
||||
|
||||
# Send it
|
||||
data = array.tostring()
|
||||
|
|
|
@ -620,6 +620,10 @@ class TestClient(object):
|
|||
with client.stream_insert_context("/empty/test", end = 950):
|
||||
pass
|
||||
|
||||
# Equal start and end is OK as long as there's no data
|
||||
with client.stream_insert_context("/empty/test", start=9, end=9):
|
||||
pass
|
||||
|
||||
# Try various things that might cause problems
|
||||
with client.stream_insert_context("/empty/test", 1000, 1050) as ctx:
|
||||
ctx.finalize() # inserts [1000, 1050]
|
||||
|
|
|
@ -309,6 +309,22 @@ class TestNumpyClient(object):
|
|||
with client.stream_insert_numpy_context("/empty/test", end = 950):
|
||||
pass
|
||||
|
||||
# Equal start and end is OK as long as there's no data
|
||||
with assert_raises(ClientError) as e:
|
||||
with client.stream_insert_numpy_context("/empty/test",
|
||||
start=9, end=9) as ctx:
|
||||
ctx.insert([[9, 9]])
|
||||
ctx.finalize()
|
||||
in_("have data to send, but invalid start/end times", str(e.exception))
|
||||
|
||||
with client.stream_insert_numpy_context("/empty/test",
|
||||
start=9, end=9) as ctx:
|
||||
pass
|
||||
|
||||
# reusing a context object is bad
|
||||
with assert_raises(Exception) as e:
|
||||
ctx.insert([[9, 9]])
|
||||
|
||||
# Try various things that might cause problems
|
||||
with client.stream_insert_numpy_context("/empty/test",
|
||||
1000, 1050) as ctx:
|
||||
|
|
Loading…
Reference in New Issue
Block a user