yezhizi commented on code in PR #3246:
URL: https://github.com/apache/kvrocks/pull/3246#discussion_r2488916823


##########
tests/gocase/unit/type/timeseries/timeseries_test.go:
##########
@@ -1003,4 +1003,20 @@ func testTimeSeries(t *testing.T, configs 
util.KvrocksServerConfigs) {
                _, err = rdb.Do(ctx, "ts.del", srcKey, "-", "+").Result()
                require.ErrorContains(t, err, "When a series has compactions, 
deleting samples or compaction buckets beyond the series retention period is 
not possible")
        })
+
+       t.Run("TS.QUERYINDEX", func(t *testing.T) {
+               // Create test based on example in Redis documentation
+               require.NoError(t, rdb.Do(ctx, "ts.create", 
"telemetry:study:temperature", "LABELS", "room", "study", "type", 
"temperature").Err())
+               require.NoError(t, rdb.Do(ctx, "ts.create", 
"telemetry:study:humidity", "LABELS", "room", "study", "type", 
"humidity").Err())
+               require.NoError(t, rdb.Do(ctx, "ts.create", 
"telemetry:kitchen:temperature", "LABELS", "room", "kitchen", "type", 
"temperature").Err())
+               require.NoError(t, rdb.Do(ctx, "ts.create", 
"telemetry:kitchen:humidity", "LABELS", "room", "kitchen", "type", 
"humidity").Err())
+
+               res, err := rdb.Do(ctx, "ts.queryindex", 
"room=kitchen").Result()
+               require.NoError(t, err)
+               assert.Equal(t, []interface{}{"telemetry:kitchen:humidity", 
"telemetry:kitchen:temperature"}, res)
+
+               res, err = rdb.Do(ctx, "ts.queryindex", 
"type=tempereature").Result()

Review Comment:
   typos: `tempereature` should be `temperature`
   



##########
src/types/redis_timeseries.h:
##########
@@ -243,6 +243,10 @@ struct TSMRangeResult : TSMGetResult {
   std::vector<std::string> source_keys;
 };
 
+struct TSQueryIndexResult {
+  std::string name;  // name of the source key or the group
+};

Review Comment:
   
   I think we can directly use `std::string`instead of adding a seemingly 
redundant struct.



##########
src/types/redis_timeseries.cc:
##########
@@ -2295,4 +2295,21 @@ rocksdb::Status TimeSeries::IsTSSubKeyExpired(const 
TimeSeriesMetadata &metadata
   return rocksdb::Status::OK();
 }
 
+rocksdb::Status TimeSeries::QueryIndex(engine::Context &ctx, const 
TSMGetOption::FilterOption &filter_option,
+                                       std::vector<TSQueryIndexResult> *res) {
+  std::vector<std::string> user_keys;
+  std::vector<LabelKVList> labels_vec;
+  std::vector<TimeSeriesMetadata> metas;
+
+  auto s = getTSKeyByFilter(ctx, filter_option, &user_keys, &labels_vec, 
&metas);
+  if (!s.ok()) return s;

Review Comment:
   ```suggestion
   
     auto s = getTSKeyByFilter(ctx, filter_option, &user_keys);
     if (!s.ok()) return s;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to