From c87b68d2a4240e8864e4d010f035ede7e609303b Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Tue, 20 Aug 2019 19:05:49 -0700 Subject: [PATCH] use Number instead of long for response context (#8342) * use Number instead of long for response context to be forgiving of json serde to int or long * test that encounters issue without fix * now with more test * is ints --- .../apache/druid/query/context/ResponseContext.java | 4 ++-- .../druid/query/context/ResponseContextTest.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java b/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java index 269a1e56477..f94b1d24354 100644 --- a/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java +++ b/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java @@ -150,7 +150,7 @@ public abstract class ResponseContext */ NUM_SCANNED_ROWS( "count", - (oldValue, newValue) -> (long) oldValue + (long) newValue + (oldValue, newValue) -> ((Number) oldValue).longValue() + ((Number) newValue).longValue() ), /** * The total CPU time for threads related to Sequence processing of the query. @@ -159,7 +159,7 @@ public abstract class ResponseContext */ CPU_CONSUMED_NANOS( "cpuConsumed", - (oldValue, newValue) -> (long) oldValue + (long) newValue + (oldValue, newValue) -> ((Number) oldValue).longValue() + ((Number) newValue).longValue() ), /** * Indicates if a {@link ResponseContext} was truncated during serialization. diff --git a/processing/src/test/java/org/apache/druid/query/context/ResponseContextTest.java b/processing/src/test/java/org/apache/druid/query/context/ResponseContextTest.java index f1354c3ea6b..92bf2efee85 100644 --- a/processing/src/test/java/org/apache/druid/query/context/ResponseContextTest.java +++ b/processing/src/test/java/org/apache/druid/query/context/ResponseContextTest.java @@ -280,11 +280,22 @@ public class ResponseContextTest { final DefaultObjectMapper mapper = new DefaultObjectMapper(); final ResponseContext ctx = ResponseContext.deserialize( - mapper.writeValueAsString(ImmutableMap.of("ETag", "string-value", "count", 100)), + mapper.writeValueAsString( + ImmutableMap.of( + "ETag", "string-value", + "count", 100L, + "cpuConsumed", 100000L + ) + ), mapper ); Assert.assertEquals("string-value", ctx.get(ResponseContext.Key.ETAG)); Assert.assertEquals(100, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS)); + Assert.assertEquals(100000, ctx.get(ResponseContext.Key.CPU_CONSUMED_NANOS)); + ctx.add(ResponseContext.Key.NUM_SCANNED_ROWS, 10L); + Assert.assertEquals(110L, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS)); + ctx.add(ResponseContext.Key.CPU_CONSUMED_NANOS, 100); + Assert.assertEquals(100100L, ctx.get(ResponseContext.Key.CPU_CONSUMED_NANOS)); } @Test(expected = IllegalStateException.class)