|
28 | 28 | #include "common_types.h" |
29 | 29 |
|
30 | 30 | #include <atomic> |
| 31 | +#include <map> |
31 | 32 | #include <stdexcept> |
32 | 33 | #include <thread> |
33 | 34 |
|
@@ -844,6 +845,52 @@ TEST_CASE("Test executeLastDataQuery ", "[testExecuteLastDataQuery]") { |
844 | 845 | REQUIRE(sessionDataSet->hasNext() == false); |
845 | 846 | } |
846 | 847 |
|
| 848 | +TEST_CASE("Fast Last Query returns all series under a tree prefix", "[fastLastQuery]") { |
| 849 | + const vector<string> paths = {"root.test.fast_last_cpp.d1.s1", "root.test.fast_last_cpp.d1.s2", |
| 850 | + "root.test.fast_last_cpp.d2.s1"}; |
| 851 | + for (const auto& path : paths) { |
| 852 | + if (session->checkTimeseriesExists(path)) { |
| 853 | + session->deleteTimeseries(path); |
| 854 | + } |
| 855 | + session->createTimeseries(path, TSDataType::INT64, TSEncoding::RLE, |
| 856 | + CompressionType::SNAPPY); |
| 857 | + } |
| 858 | + session->insertRecord("root.test.fast_last_cpp.d1", 20, {"s1", "s2"}, {"1", "2"}); |
| 859 | + session->insertRecord("root.test.fast_last_cpp.d1", 30, {"s1"}, {"3"}); |
| 860 | + session->insertRecord("root.test.fast_last_cpp.d2", 40, {"s1"}, {"4"}); |
| 861 | + |
| 862 | + const map<string, string> expected = {{paths[0], "30,3,INT64"}, |
| 863 | + {paths[1], "20,2,INT64"}, |
| 864 | + {paths[2], "40,4,INT64"}}; |
| 865 | + const vector<string> prefix = {"root", "test", "fast_last_cpp"}; |
| 866 | + for (int query = 0; query < 2; ++query) { |
| 867 | + auto dataSet = session->executeFastLastDataQueryForOnePrefixPath(prefix); |
| 868 | + map<string, string> actual; |
| 869 | + while (dataSet->hasNext()) { |
| 870 | + auto row = dataSet->next(); |
| 871 | + REQUIRE(row->fields.size() == 3); |
| 872 | + const auto& fields = row->fields; |
| 873 | + auto inserted = actual.emplace(fields[0].stringV.value(), |
| 874 | + to_string(row->timestamp) + "," + |
| 875 | + fields[1].stringV.value() + "," + fields[2].stringV.value()); |
| 876 | + REQUIRE(inserted.second); |
| 877 | + } |
| 878 | + dataSet->closeOperationHandle(); |
| 879 | + REQUIRE(actual == expected); |
| 880 | + } |
| 881 | + |
| 882 | + auto empty = session->executeFastLastDataQueryForOnePrefixPath( |
| 883 | + {"root", "test", "fast_last_cpp", "missing"}); |
| 884 | + REQUIRE_FALSE(empty->hasNext()); |
| 885 | + empty->closeOperationHandle(); |
| 886 | + REQUIRE_THROWS_AS(session->executeFastLastDataQueryForOnePrefixPath({"root", "test", "*"}), |
| 887 | + std::invalid_argument); |
| 888 | + |
| 889 | + for (const auto& path : paths) { |
| 890 | + session->deleteTimeseries(path); |
| 891 | + } |
| 892 | +} |
| 893 | + |
847 | 894 | // Helper function for comparing TEndPoint with detailed error message |
848 | 895 | void assertTEndPointEqual(const TEndPoint& actual, const std::string& expectedIp, int expectedPort, |
849 | 896 | const char* file, int line) { |
|
0 commit comments