jtuglu1 commented on code in PR #18568:
URL: https://github.com/apache/druid/pull/18568#discussion_r2392445570


##########
processing/src/test/java/org/apache/druid/query/scan/ScanQueryQueryToolChestTest.java:
##########
@@ -441,4 +447,247 @@ private static Sequence<ScanResultValue> results3()
         )
     );
   }
+
+  @Test
+  public void testCacheStrategy()
+  {
+    ScanQuery query = Druids.newScanQueryBuilder()
+        .dataSource("foo")
+        .intervals(new 
MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))))
+        .columns("dim1", "dim2")
+        .resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)
+        .batchSize(4096)
+        .offset(10)
+        .limit(100)
+        .build();
+
+    CacheStrategy<ScanResultValue, ScanResultValue, ScanQuery> strategy = 
toolChest.getCacheStrategy(query, null);
+
+    Assert.assertNotNull(strategy);
+    Assert.assertTrue(strategy.isCacheable(query, true, false));
+    Assert.assertFalse(strategy.isCacheable(query, false, true));
+    Assert.assertTrue(strategy.isCacheable(query, true, true));
+
+    byte[] cacheKey = strategy.computeCacheKey(query);
+    Assert.assertNotNull(cacheKey);
+    Assert.assertTrue(cacheKey.length > 0);
+
+    byte[] resultLevelCacheKey = strategy.computeResultLevelCacheKey(query);
+    Assert.assertNotNull(resultLevelCacheKey);
+    Assert.assertTrue(resultLevelCacheKey.length > 0);
+    
+    // For ScanQuery, result-level and segment-level cache keys should be the 
same
+    Assert.assertArrayEquals(cacheKey, resultLevelCacheKey);
+
+    ScanResultValue testResult = new ScanResultValue(
+        "test_segment",
+        ImmutableList.of("dim1", "dim2"),
+        ImmutableList.of(
+            ImmutableMap.of("dim1", "value1", "dim2", "value2"),
+            ImmutableMap.of("dim1", "value3", "dim2", "value4")
+        )
+    );
+
+    ScanResultValue cachedValue = 
strategy.prepareForCache(false).apply(testResult);
+    ScanResultValue fromCache = 
strategy.pullFromCache(false).apply(cachedValue);
+
+    Assert.assertEquals(testResult, fromCache);
+  }
+
+  @Test
+  public void testCacheDisabledForBySegmentQueries()
+  {
+    ScanQuery query = Druids.newScanQueryBuilder()
+                            .dataSource("foo")
+                            .intervals(new 
MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))))
+                            .columns("dim1", "dim2")
+                            
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)
+                            .batchSize(4096)
+                            .offset(10)
+                            .limit(100)
+                            .context(ImmutableMap.of("bySegment", true))
+                            .build();
+
+    CacheStrategy<ScanResultValue, ScanResultValue, ScanQuery> strategy = 
toolChest.getCacheStrategy(query, null);
+
+    Assert.assertNotNull(strategy);
+    Assert.assertFalse(strategy.isCacheable(query, true, false));
+    Assert.assertFalse(strategy.isCacheable(query, false, true));
+  }
+
+  @Test
+  public void testCacheKeyDifferentQueries()
+  {
+    ScanQuery query1 = Druids.newScanQueryBuilder()
+        .dataSource("foo")
+        .intervals(new 
MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2025-01-01/2025-01-02"))))
+        .columns("dim1", "dim2")
+        .resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)
+        .build();
+
+    ScanQuery query2 = Druids.newScanQueryBuilder()
+        .dataSource("foo")
+        .intervals(new 
MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2025-01-01/2025-01-02"))))
+        .columns("dim1", "dim3")
+        .resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)
+        .build();
+
+    ScanQuery query3 = Druids.newScanQueryBuilder()

Review Comment:
   I'll add another test, but it's needed in the cache key.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to