aho135 commented on code in PR #19386:
URL: https://github.com/apache/druid/pull/19386#discussion_r3229647389


##########
processing/src/test/java/org/apache/druid/math/expr/ExprTest.java:
##########
@@ -221,6 +221,27 @@ public void testEqualsContractForNullDoubleExpr()
                   .verify();
   }
 
+  /**
+   * now() depends on wall-clock time, so its cache key must not be stable 
across calls — otherwise queries containing
+   * now() can hit a stale cached result. NowExpression overrides {@link 
Expr#decorateCacheKeyBuilder} to mix in
+   * nanoTime, which makes any containing Expr produce a fresh key on every 
{@link Expr#getCacheKey()} call.
+   */
+  @Test
+  public void testNowExprCacheKeyIsNotStable()
+  {
+    Expr now = Parser.parse("now()", ExprMacroTable.nil());
+    byte[] k1 = now.getCacheKey();
+    byte[] k2 = now.getCacheKey();
+    Assertions.assertFalse(java.util.Arrays.equals(k1, k2), "bare now() cache 
key must change across calls");
+
+    // Verify the same instability propagates when now() is nested in a parent 
expression.
+    Expr nested = Parser.parse("now() > 0", ExprMacroTable.nil());
+    Assertions.assertFalse(
+        java.util.Arrays.equals(nested.getCacheKey(), nested.getCacheKey()),

Review Comment:
   ```suggestion
           Arrays.equals(nested.getCacheKey(), nested.getCacheKey()),
   ```
   Can be imported



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