Skip to content

Commit 83c362e

Browse files
authored
Merge pull request #186 from poissoncorp/RDBC-697
RDBC-697 Time series session API
2 parents a6f5d99 + 73ebd58 commit 83c362e

File tree

26 files changed

+2770
-320
lines changed

26 files changed

+2770
-320
lines changed

ravendb/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import sys
2+
13
int_max = 0x7FFFFFF
4+
min_normal = sys.float_info.min
25
json_serialize_method_name = "to_json"
6+
nan_value = float("nan")
37

48

59
class Documents:

ravendb/data/timeseries.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

ravendb/documents/commands/batches.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
DocumentCountersOperation,
1414
CounterOperationType,
1515
)
16+
from ravendb.documents.operations.time_series import TimeSeriesOperation
1617
from ravendb.documents.session.misc import TransactionMode, ForceRevisionStrategy
18+
from ravendb.documents.time_series import TimeSeriesOperations
1719
from ravendb.http.raven_command import RavenCommand
1820
from ravendb.http.server_node import ServerNode
1921
from ravendb.json.result import BatchCommandResult
@@ -236,13 +238,11 @@ def __init__(
236238
name: str = None,
237239
change_vector: str = None,
238240
command_type: CommandType = None,
239-
on_before_save_changes: Callable = None,
240241
):
241242
self._key = key
242243
self._name = name
243244
self._change_vector = change_vector
244245
self._command_type = command_type
245-
self._on_before_save_changes = on_before_save_changes
246246

247247
@property
248248
def key(self) -> str:
@@ -260,11 +260,8 @@ def change_vector(self) -> str:
260260
def command_type(self) -> CommandType:
261261
return self._command_type
262262

263-
@property
264-
def on_before_save_changes(
265-
self,
266-
) -> Callable[[InMemoryDocumentSessionOperations], None]:
267-
return self._on_before_save_changes
263+
def on_before_save_changes(self, session: InMemoryDocumentSessionOperations) -> None:
264+
pass
268265

269266
@abstractmethod
270267
def serialize(self, conventions: DocumentConventions) -> dict:
@@ -635,6 +632,37 @@ def serialize(self, conventions: DocumentConventions) -> dict:
635632
return {"Id": self._key, "Name": self.name, "ChangeVector": self.change_vector, "Type": self.command_type}
636633

637634

635+
class TimeSeriesBatchCommandData(CommandData):
636+
def __init__(
637+
self,
638+
document_id: str,
639+
name: str,
640+
appends: Optional[List[TimeSeriesOperation.AppendOperation]],
641+
deletes: Optional[List[TimeSeriesOperation.DeleteOperation]],
642+
):
643+
if not document_id:
644+
raise ValueError("Document id cannot be None")
645+
if not name:
646+
raise ValueError("Name cannot be None")
647+
648+
super(TimeSeriesBatchCommandData, self).__init__(document_id, name, None, CommandType.TIME_SERIES)
649+
self.time_series = TimeSeriesOperation()
650+
self.time_series.name = name
651+
652+
if appends:
653+
for append_operation in appends:
654+
self.time_series.append(append_operation)
655+
if deletes:
656+
for delete_operation in deletes:
657+
self.time_series.delete(delete_operation)
658+
659+
def serialize(self, conventions: DocumentConventions) -> dict:
660+
return {"Id": self.key, "TimeSeries": self.time_series.to_json(), "Type": "TimeSeries"}
661+
662+
def on_before_save_changes(self, session: InMemoryDocumentSessionOperations) -> None:
663+
pass
664+
665+
638666
# ------------ OPTIONS ------------
639667

640668

ravendb/documents/conventions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424

2525
class DocumentConventions(object):
26+
@classmethod
27+
def default_conventions(cls):
28+
return cls()
29+
2630
__cached_default_type_collection_names: Dict[type, str] = {}
2731

2832
def __init__(self):

ravendb/documents/operations/batch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def get_command_type(obj_node: dict) -> CommandType:
126126
pass
127127
elif command_type == CommandType.COUNTERS:
128128
self.__handle_counters(batch_result)
129+
elif command_type == CommandType.TIME_SERIES:
130+
break # todo: RavenDB-13474 add to time series cache
129131
elif command_type == CommandType.TIME_SERIES_COPY or command_type == CommandType.BATCH_PATCH:
130132
break
131133
else:

0 commit comments

Comments
 (0)