From 42931064b3616dd8e197bc5976fa2a3115d15bf1 Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Mon, 19 Aug 2019 16:26:56 -0700 Subject: [PATCH 1/4] use Number instead of long for response context to be forgiving of json serde to int or long --- .../java/org/apache/druid/query/context/ResponseContext.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 269a1e564776..f94b1d243546 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 enum Key implements BaseKey */ 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 enum Key implements BaseKey */ 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. From 76bcc39725576464058dfe81e491c6104a63120e Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Mon, 19 Aug 2019 18:15:03 -0700 Subject: [PATCH 2/4] test that encounters issue without fix --- .../org/apache/druid/query/context/ResponseContextTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 f1354c3ea6b3..ce3bd62b48e8 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 @@ -285,6 +285,8 @@ public void deserializeTest() throws IOException ); Assert.assertEquals("string-value", ctx.get(ResponseContext.Key.ETAG)); Assert.assertEquals(100, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS)); + ctx.add(ResponseContext.Key.NUM_SCANNED_ROWS, 10L); + Assert.assertEquals(110L, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS)); } @Test(expected = IllegalStateException.class) From 932d72ed28437948b162d8f4160fdaf81be3d89a Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Mon, 19 Aug 2019 18:37:49 -0700 Subject: [PATCH 3/4] now with more test --- .../druid/query/context/ResponseContextTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 ce3bd62b48e8..29c3af8d603c 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,13 +280,21 @@ public void deserializeTest() throws IOException { 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)); 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) From bf616cd1323e90b4917fb8f5f2f4af326f6b0947 Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Mon, 19 Aug 2019 18:39:43 -0700 Subject: [PATCH 4/4] is ints --- .../java/org/apache/druid/query/context/ResponseContextTest.java | 1 + 1 file changed, 1 insertion(+) 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 29c3af8d603c..92bf2efee856 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 @@ -291,6 +291,7 @@ public void deserializeTest() throws IOException ); 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);