From f58b56fdc2477ec8fc135fb18e3de3365b7372d2 Mon Sep 17 00:00:00 2001 From: dwivedi Date: Mon, 24 Jul 2017 13:16:04 -0700 Subject: [PATCH 1/4] Default implementation for getDouble(). --- .../src/main/java/io/druid/query/aggregation/Aggregator.java | 5 ++++- .../java/io/druid/query/aggregation/BufferAggregator.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java index 28421fa67f4c..550239da5b8d 100644 --- a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java @@ -41,7 +41,10 @@ public interface Aggregator extends Closeable Object get(); float getFloat(); long getLong(); - double getDouble(); + default double getDouble() + { + throw new UnsupportedOperationException("Not implemented"); + } @Override void close(); diff --git a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java index d67588fbe94c..c437511e52b6 100644 --- a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java @@ -127,7 +127,10 @@ public interface BufferAggregator extends HotLoopCallee * @param position offset within the byte buffer at which the aggregate value is stored * @return the double representation of the aggregate */ - double getDouble(ByteBuffer buf, int position); + default double getDouble(ByteBuffer buf, int position) + { + throw new UnsupportedOperationException("Not implemented"); + } /** * Release any resources used by the aggregator From 75d6b50f673f7116f4e96bddb842735b91ba17a0 Mon Sep 17 00:00:00 2001 From: Akash Dwivedi Date: Tue, 25 Jul 2017 11:35:56 -0700 Subject: [PATCH 2/4] use getFloat for default implementation. --- .../src/main/java/io/druid/query/aggregation/Aggregator.java | 3 ++- .../java/io/druid/query/aggregation/BufferAggregator.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java index 550239da5b8d..f549611ff1d4 100644 --- a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java @@ -41,9 +41,10 @@ public interface Aggregator extends Closeable Object get(); float getFloat(); long getLong(); + default double getDouble() { - throw new UnsupportedOperationException("Not implemented"); + return (double) getFloat(); } @Override diff --git a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java index c437511e52b6..1ef24fcb359d 100644 --- a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java @@ -123,13 +123,15 @@ public interface BufferAggregator extends HotLoopCallee * have an {@link AggregatorFactory#getTypeName()} of "double". * If unimplemented, throwing an {@link UnsupportedOperationException} is common and recommended. * + * The default implementation casts {@link BufferAggregator#getFloat(ByteBuffer, int)} to double. + * * @param buf byte buffer storing the byte array representation of the aggregate * @param position offset within the byte buffer at which the aggregate value is stored * @return the double representation of the aggregate */ default double getDouble(ByteBuffer buf, int position) { - throw new UnsupportedOperationException("Not implemented"); + return (double) getFloat(buf, position); } /** From e4736369fb52837cd431f2f6feaa44536f1a9380 Mon Sep 17 00:00:00 2001 From: dwivedi Date: Tue, 25 Jul 2017 13:49:50 -0700 Subject: [PATCH 3/4] addressed comment. --- .../main/java/io/druid/query/aggregation/Aggregator.java | 6 +++++- .../java/io/druid/query/aggregation/BufferAggregator.java | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java index f549611ff1d4..d6fa13e8e1d5 100644 --- a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java @@ -20,7 +20,6 @@ package io.druid.query.aggregation; import java.io.Closeable; - /** * An Aggregator is an object that can aggregate metrics. Its aggregation-related methods (namely, aggregate() and get()) * do not take any arguments as the assumption is that the Aggregator was given something in its constructor that @@ -42,6 +41,11 @@ public interface Aggregator extends Closeable float getFloat(); long getLong(); + /** + * The default implementation casts {@link Aggregator#getFloat()} to double. + * This default method is added to enable smooth backward compatibility, please re-implement it if your aggregators + * work with numeric double columns. + */ default double getDouble() { return (double) getFloat(); diff --git a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java index 1ef24fcb359d..9dc9acb32675 100644 --- a/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/BufferAggregator.java @@ -124,6 +124,8 @@ public interface BufferAggregator extends HotLoopCallee * If unimplemented, throwing an {@link UnsupportedOperationException} is common and recommended. * * The default implementation casts {@link BufferAggregator#getFloat(ByteBuffer, int)} to double. + * This default method is added to enable smooth backward compatibility, please re-implement it if your aggregators + * work with numeric double columns. * * @param buf byte buffer storing the byte array representation of the aggregate * @param position offset within the byte buffer at which the aggregate value is stored From d0f7d9afe6dc5ec1b4f47a3b00312244045db36a Mon Sep 17 00:00:00 2001 From: dwivedi Date: Tue, 25 Jul 2017 15:33:50 -0700 Subject: [PATCH 4/4] new line. --- .../src/main/java/io/druid/query/aggregation/Aggregator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java index d6fa13e8e1d5..fb4689fe009a 100644 --- a/processing/src/main/java/io/druid/query/aggregation/Aggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/Aggregator.java @@ -20,6 +20,7 @@ package io.druid.query.aggregation; import java.io.Closeable; + /** * An Aggregator is an object that can aggregate metrics. Its aggregation-related methods (namely, aggregate() and get()) * do not take any arguments as the assumption is that the Aggregator was given something in its constructor that