[ 
https://issues.apache.org/jira/browse/QPID-8581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17532797#comment-17532797
 ] 

ASF GitHub Bot commented on QPID-8581:
--------------------------------------

dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r866737862


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/parsing/converter/NumberConverter.java:
##########
@@ -0,0 +1,250 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.query.engine.parsing.converter;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Map;
+import java.util.function.Function;
+
+import com.google.common.collect.ImmutableMap;
+
+import org.apache.qpid.server.query.engine.evaluator.EvaluationContext;
+import org.apache.qpid.server.query.engine.evaluator.EvaluationContextHolder;
+import org.apache.qpid.server.query.engine.evaluator.settings.QuerySettings;
+import org.apache.qpid.server.query.engine.exception.Errors;
+import org.apache.qpid.server.query.engine.exception.QueryParsingException;
+import org.apache.qpid.server.query.engine.parsing.utils.StringUtils;
+
+/**
+ * Utility class for numeric conversions
+ */
+public final class NumberConverter
+{
+    /**
+     * Conversion rules
+     */
+    private static final Map<Class<?>, Map<Class<?>, Function<Object, ?>>> 
CONVERSIONS = ImmutableMap.<Class<?>, Map<Class<?>, Function<Object, 
?>>>builder()
+        .put(Double.class, ImmutableMap.<Class<?>, Function<Object, 
?>>builder()
+            .put(BigDecimal.class, arg -> ((BigDecimal) arg).doubleValue())
+            .put(Byte.class, arg -> ((Byte) arg).doubleValue())
+            .put(Double.class, arg -> arg)
+            .put(Float.class, arg -> ((Float) arg).doubleValue())
+            .put(Integer.class, arg -> ((Integer) arg).doubleValue())
+            .put(Long.class, arg -> ((Long) arg).doubleValue())
+            .put(Number.class, arg -> ((Number) arg).doubleValue())
+            .put(Short.class, arg -> ((Short) arg).doubleValue())
+            .put(String.class, arg -> Double.parseDouble((String)arg))
+            .build()
+        )
+        .put(Long.class, ImmutableMap.<Class<?>, Function<Object, ?>>builder()
+            .put(BigDecimal.class, arg -> ((BigDecimal) arg).longValue())
+            .put(Byte.class, arg -> ((Byte) arg).longValue())
+            .put(Double.class, arg -> ((Double) arg).longValue())
+            .put(Float.class, arg -> ((Float) arg).longValue())
+            .put(Integer.class, arg -> ((Integer) arg).longValue())
+            .put(Long.class, arg -> arg)
+            .put(Number.class, arg -> ((Number) arg).longValue())
+            .put(Short.class, arg -> ((Short) arg).longValue())
+            .put(String.class, arg -> Long.parseLong((String)arg))

Review Comment:
   Changed as suggested





> [Broker-J] Broker-J Query REST API improvements
> -----------------------------------------------
>
>                 Key: QPID-8581
>                 URL: https://issues.apache.org/jira/browse/QPID-8581
>             Project: Qpid
>          Issue Type: Improvement
>          Components: Broker-J
>    Affects Versions: qpid-java-broker-8.0.6
>            Reporter: Daniil Kirilyuk
>            Priority: Minor
>
> Existing broker REST API (including broker query API) doesn’t support such 
> functions as aggregation, grouping and using nested logical operators, which 
> could be useful for gathering broker statistics and reporting.
> We suggest to add a new POST method for the endpoint /api/latest/querybroker 
> and supply search criteria using JSON body. (Existing GET method 
> implementation should stay without changes for keeping backwards 
> compatibility and because of difficulties of parsing complicated search 
> conditions from URI parameters when using GET request method).
> The new functionality should add
>  * logical OR operator (absent in current API)
>  * aggregation operators AVG, CNT, MAX, MIN, SUM
>  * grouping aggregation
>  * new numeric / datetime / string functions



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to