Skip to content

Commit 5389547

Browse files
Impl and tests
1 parent b3b0273 commit 5389547

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

python/arcticdb/version_store/library.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1281,17 +1281,17 @@ def delete_staged_data(self, symbol: str):
12811281
def finalize_staged_data(
12821282
self,
12831283
symbol: str,
1284-
mode: Optional[StagedDataFinalizeMethod] = StagedDataFinalizeMethod.WRITE,
1284+
mode: Optional[Union[StagedDataFinalizeMethod, str]] = StagedDataFinalizeMethod.WRITE,
12851285
prune_previous_versions: bool = False,
12861286
metadata: Any = None,
12871287
validate_index = True,
12881288
delete_staged_data_on_failure: bool = False
12891289
) -> VersionedItem:
12901290
"""
12911291
Finalizes staged data, making it available for reads. All staged segments must be ordered and non-overlapping.
1292-
``finalize_staged_data`` is less time consuming than ``sort_and_finalize_staged_data``.
1292+
``finalize_staged_data`` is less time-consuming than ``sort_and_finalize_staged_data``.
12931293
1294-
If ``mode`` is ``StagedDataFinalizeMethod.APPEND`` the index of the first row of the new segment must be equal to or greater
1294+
If ``mode`` is ``StagedDataFinalizeMethod.APPEND`` or ``APPEND`` the index of the first row of the new segment must be equal to or greater
12951295
than the index of the last row in the existing data.
12961296
12971297
If ``Static Schema`` is used all staged block must have matching schema (same column names, same dtype, same column ordering)
@@ -1310,9 +1310,9 @@ def finalize_staged_data(
13101310
symbol : `str`
13111311
Symbol to finalize data for.
13121312
1313-
mode : `StagedDataFinalizeMethod`, default=StagedDataFinalizeMethod.WRITE
1314-
Finalize mode. Valid options are WRITE or APPEND. Write collects the staged data and writes them to a
1315-
new version. Append collects the staged data and appends them to the latest version.
1313+
mode : Union[`StagedDataFinalizeMethod`, str], default=StagedDataFinalizeMethod.WRITE
1314+
Finalize mode. Valid options are StagedDataFinalizeMethod.WRITE or StagedDataFinalizeMethod.APPEND. Write collects the staged data and writes them to a
1315+
new version. Append collects the staged data and appends them to the latest version. Also accepts "WRITE" and "APPEND".
13161316
prune_previous_versions: bool, default=False
13171317
Removes previous (non-snapshotted) versions from the database.
13181318
metadata : Any, default=None
@@ -1383,9 +1383,12 @@ def finalize_staged_data(
13831383
2024-01-03 3
13841384
2024-01-04 4
13851385
"""
1386+
if not (mode is None or isinstance(mode, StagedDataFinalizeMethod) or mode == "WRITE" or mode == "APPEND"):
1387+
raise ArcticInvalidApiUsageException("mode must be a StagedDataFinalizeMethod enum or 'WRITE'/'APPEND'")
1388+
13861389
return self._nvs.compact_incomplete(
13871390
symbol,
1388-
append=mode == StagedDataFinalizeMethod.APPEND,
1391+
append=mode == StagedDataFinalizeMethod.APPEND or mode == "APPEND",
13891392
convert_int_to_float=False,
13901393
metadata=metadata,
13911394
prune_previous_version=prune_previous_versions,

python/tests/unit/arcticdb/version_store/test_api.py

+37
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import time
99

1010
from pandas import Timestamp
11+
from unittest.mock import MagicMock
1112
import pytest
1213

1314
from arcticdb.exceptions import NoSuchVersionException, NoDataFoundException
1415
from arcticdb.util.test import distinct_timestamps
16+
from arcticdb.version_store.library import StagedDataFinalizeMethod, ArcticInvalidApiUsageException
1517

1618

1719
def test_read_descriptor(lmdb_version_store, one_col_df):
@@ -89,3 +91,38 @@ def test_get_num_rows_pickled(lmdb_version_store):
8991
symbol = "test_get_num_rows_pickled"
9092
lmdb_version_store.write(symbol, 1)
9193
assert lmdb_version_store.get_num_rows(symbol) is None
94+
95+
96+
@pytest.mark.parametrize(
97+
"input_mode, expected_append",
98+
[
99+
("WRITE", False),
100+
("APPEND", True),
101+
(None, False),
102+
(StagedDataFinalizeMethod.APPEND, True),
103+
(StagedDataFinalizeMethod.WRITE, False),
104+
([], None),
105+
{"write", None},
106+
],
107+
)
108+
def test_finalize_staged_data(arctic_library_lmdb, input_mode, expected_append):
109+
symbol = "sym"
110+
arctic_library_lmdb._nvs = MagicMock()
111+
112+
if expected_append is None:
113+
with pytest.raises(ArcticInvalidApiUsageException):
114+
arctic_library_lmdb.finalize_staged_data(symbol, input_mode)
115+
return
116+
117+
arctic_library_lmdb.finalize_staged_data(symbol, input_mode)
118+
119+
default_args = {
120+
"convert_int_to_float": False,
121+
"metadata": None,
122+
"prune_previous_version": False,
123+
"validate_index": True,
124+
"delete_staged_data_on_failure": False,
125+
}
126+
127+
arctic_library_lmdb._nvs.compact_incomplete.assert_called_once_with(symbol, append=expected_append, **default_args)
128+

0 commit comments

Comments
 (0)