|
31 | 31 | )
|
32 | 32 | from arcticdb import QueryBuilder
|
33 | 33 | from arcticdb.flattener import Flattener
|
| 34 | +from arcticdb.util.utils import generate_random_numpy_array, generate_random_series |
34 | 35 | from arcticdb.version_store import NativeVersionStore
|
35 | 36 | from arcticdb.version_store._store import VersionedItem
|
36 | 37 | from arcticdb_ext.exceptions import _ArcticLegacyCompatibilityException, StorageException
|
@@ -1144,6 +1145,37 @@ def test_update_times(basic_store):
|
1144 | 1145 | assert update_times_versioned[0] < update_times_versioned[1] < update_times_versioned[2]
|
1145 | 1146 |
|
1146 | 1147 |
|
| 1148 | +@pytest.mark.storage |
| 1149 | +def test_update_time(basic_store): |
| 1150 | + lib: NativeVersionStore = basic_store |
| 1151 | + |
| 1152 | + nparr = generate_random_numpy_array(50, np.float32, seed=None) |
| 1153 | + series = generate_random_series(np.uint64, 50, "numbers") |
| 1154 | + df = pd.DataFrame(data={"col1": np.arange(10)}, index=pd.date_range(pd.Timestamp(0), periods=10)) |
| 1155 | + lib.write("sym1", nparr) |
| 1156 | + lib.write("sym1", series) |
| 1157 | + lib.snapshot("snap") |
| 1158 | + lib.write("sym1", df) |
| 1159 | + |
| 1160 | + # Negative number for as_of works as expected (dataframes) |
| 1161 | + assert lib.update_time("sym1") == lib.update_time("sym1", -1) == lib.update_time("sym1", 2) |
| 1162 | + # Snapshots are accepted (series) |
| 1163 | + assert lib.update_time("sym1", 1) == lib.update_time("sym1", -2) == lib.update_time("sym1", "snap") |
| 1164 | + # and now check for np array |
| 1165 | + assert lib.update_time("sym1", 0) == lib.update_time("sym1", -3) |
| 1166 | + |
| 1167 | + # Times are ordered |
| 1168 | + assert lib.update_time("sym1") > lib.update_time("sym1", 1) > lib.update_time("sym1", 0) |
| 1169 | + |
| 1170 | + # Correct exception thrown if symbol does not exist |
| 1171 | + with pytest.raises(NoDataFoundException): |
| 1172 | + lib.update_time("sym12") |
| 1173 | + |
| 1174 | + # Correct exception thrown if version does not exist |
| 1175 | + with pytest.raises(NoDataFoundException): |
| 1176 | + lib.update_time("sym1", 11) |
| 1177 | + |
| 1178 | + |
1147 | 1179 | @pytest.mark.storage
|
1148 | 1180 | @pytest.mark.parametrize(
|
1149 | 1181 | "index_names",
|
@@ -2540,6 +2572,7 @@ def test_batch_restore_version_mixed_as_ofs(lmdb_version_store):
|
2540 | 2572 | second_ts = pd.Timestamp(2000)
|
2541 | 2573 | ManualClockVersionStore.time = second_ts.value
|
2542 | 2574 | lib.batch_write(syms, second_data, second_metadata)
|
| 2575 | + lib.snapshot("snap") |
2543 | 2576 |
|
2544 | 2577 | third_ts = pd.Timestamp(3000)
|
2545 | 2578 | ManualClockVersionStore.time = third_ts.value
|
@@ -2571,6 +2604,32 @@ def test_batch_restore_version_mixed_as_ofs(lmdb_version_store):
|
2571 | 2604 | assert latest["s2"].metadata == "s2-2"
|
2572 | 2605 | assert latest["s3"].metadata == "s3-1"
|
2573 | 2606 |
|
| 2607 | + # check restore from snapshot and negative ver number |
| 2608 | + res = lib.batch_restore_version(syms, [-3, "snap", -1]) |
| 2609 | + |
| 2610 | + # check returned data |
| 2611 | + assert res[0].symbol == "s1" |
| 2612 | + assert res[1].symbol == "s2" |
| 2613 | + assert res[2].symbol == "s3" |
| 2614 | + assert res[0].version == 3 |
| 2615 | + assert res[1].version == 4 |
| 2616 | + assert res[2].version == 3 # We restored last version (-1 is last) |
| 2617 | + assert res[0].metadata == "s1-1" |
| 2618 | + assert res[1].metadata == "s2-2" |
| 2619 | + assert res[2].metadata == "s3-1" |
| 2620 | + |
| 2621 | + # check latest version of symbols from the read |
| 2622 | + latest = lib.batch_read(syms) |
| 2623 | + assert latest["s1"].version == 3 |
| 2624 | + assert latest["s2"].version == 4 |
| 2625 | + assert latest["s3"].version == 3 |
| 2626 | + assert_equal(latest["s1"].data, first_data[0]) |
| 2627 | + assert_equal(latest["s2"].data, second_data[1]) |
| 2628 | + assert_equal(latest["s3"].data, first_data[2]) |
| 2629 | + assert latest["s1"].metadata == "s1-1" |
| 2630 | + assert latest["s2"].metadata == "s2-2" |
| 2631 | + assert latest["s3"].metadata == "s3-1" |
| 2632 | + |
2574 | 2633 |
|
2575 | 2634 | @pytest.mark.parametrize("bad_thing", ("symbol", "as_of", "duplicate"))
|
2576 | 2635 | def test_batch_restore_version_bad_input_noop(lmdb_version_store, bad_thing):
|
@@ -2709,6 +2768,15 @@ def test_batch_restore_version(basic_store_tombstone):
|
2709 | 2768 | assert_equal(read_df, dfs[d])
|
2710 | 2769 |
|
2711 | 2770 |
|
| 2771 | +@pytest.mark.storage |
| 2772 | +def test_name_method(basic_store_factory): |
| 2773 | + |
| 2774 | + for lib_name in ["my name", "1243"]: |
| 2775 | + lib: NativeVersionStore = basic_store_factory(name=lib_name) |
| 2776 | + assert lib_name == lib.name() |
| 2777 | + lib.version_store.clear() |
| 2778 | + |
| 2779 | + |
2712 | 2780 | @pytest.mark.storage
|
2713 | 2781 | def test_batch_append(basic_store_tombstone, three_col_df):
|
2714 | 2782 | lmdb_version_store = basic_store_tombstone
|
|
0 commit comments