Skip to content

Commit

Permalink
Merge pull request #186 from poissoncorp/RDBC-697
Browse files Browse the repository at this point in the history
RDBC-697 Time series session API
  • Loading branch information
poissoncorp authored Nov 7, 2023
2 parents a6f5d99 + 73ebd58 commit 83c362e
Show file tree
Hide file tree
Showing 26 changed files with 2,770 additions and 320 deletions.
4 changes: 4 additions & 0 deletions ravendb/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import sys

int_max = 0x7FFFFFF
min_normal = sys.float_info.min
json_serialize_method_name = "to_json"
nan_value = float("nan")


class Documents:
Expand Down
87 changes: 0 additions & 87 deletions ravendb/data/timeseries.py

This file was deleted.

42 changes: 35 additions & 7 deletions ravendb/documents/commands/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
DocumentCountersOperation,
CounterOperationType,
)
from ravendb.documents.operations.time_series import TimeSeriesOperation
from ravendb.documents.session.misc import TransactionMode, ForceRevisionStrategy
from ravendb.documents.time_series import TimeSeriesOperations
from ravendb.http.raven_command import RavenCommand
from ravendb.http.server_node import ServerNode
from ravendb.json.result import BatchCommandResult
Expand Down Expand Up @@ -236,13 +238,11 @@ def __init__(
name: str = None,
change_vector: str = None,
command_type: CommandType = None,
on_before_save_changes: Callable = None,
):
self._key = key
self._name = name
self._change_vector = change_vector
self._command_type = command_type
self._on_before_save_changes = on_before_save_changes

@property
def key(self) -> str:
Expand All @@ -260,11 +260,8 @@ def change_vector(self) -> str:
def command_type(self) -> CommandType:
return self._command_type

@property
def on_before_save_changes(
self,
) -> Callable[[InMemoryDocumentSessionOperations], None]:
return self._on_before_save_changes
def on_before_save_changes(self, session: InMemoryDocumentSessionOperations) -> None:
pass

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


class TimeSeriesBatchCommandData(CommandData):
def __init__(
self,
document_id: str,
name: str,
appends: Optional[List[TimeSeriesOperation.AppendOperation]],
deletes: Optional[List[TimeSeriesOperation.DeleteOperation]],
):
if not document_id:
raise ValueError("Document id cannot be None")
if not name:
raise ValueError("Name cannot be None")

super(TimeSeriesBatchCommandData, self).__init__(document_id, name, None, CommandType.TIME_SERIES)
self.time_series = TimeSeriesOperation()
self.time_series.name = name

if appends:
for append_operation in appends:
self.time_series.append(append_operation)
if deletes:
for delete_operation in deletes:
self.time_series.delete(delete_operation)

def serialize(self, conventions: DocumentConventions) -> dict:
return {"Id": self.key, "TimeSeries": self.time_series.to_json(), "Type": "TimeSeries"}

def on_before_save_changes(self, session: InMemoryDocumentSessionOperations) -> None:
pass


# ------------ OPTIONS ------------


Expand Down
4 changes: 4 additions & 0 deletions ravendb/documents/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@


class DocumentConventions(object):
@classmethod
def default_conventions(cls):
return cls()

__cached_default_type_collection_names: Dict[type, str] = {}

def __init__(self):
Expand Down
2 changes: 2 additions & 0 deletions ravendb/documents/operations/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def get_command_type(obj_node: dict) -> CommandType:
pass
elif command_type == CommandType.COUNTERS:
self.__handle_counters(batch_result)
elif command_type == CommandType.TIME_SERIES:
break # todo: RavenDB-13474 add to time series cache
elif command_type == CommandType.TIME_SERIES_COPY or command_type == CommandType.BATCH_PATCH:
break
else:
Expand Down
Loading

0 comments on commit 83c362e

Please sign in to comment.