You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2022/04/05 13:09:32 UTC

[GitHub] [qpid-broker-j] dakirily opened a new pull request, #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

dakirily opened a new pull request, #121:
URL: https://github.com/apache/qpid-broker-j/pull/121

   This PR addresses JIRA [QPID-8581](https://issues.apache.org/jira/browse/QPID-8581), adding new functionality to the broker Query API.


-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] vavrtom commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
vavrtom commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r893482694


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -112,6 +111,10 @@ public void setMaxBigDecimalValue(final BigDecimal maxBigDecimalValue)
         _maxBigDecimalValue = maxBigDecimalValue;
     }
 
+    public void setMaxQueryCacheSize(final int maxQueryCacheSize) {

Review Comment:
   The curly bracket should be on new line.



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -63,12 +62,12 @@
     /**
      * Maximal amount of queries allowed caching
      */
-    private int _maxQueryCacheSize = HttpPort.DEFAULT_QUERY_ENGINE_CACHE_SIZE;
+    private int _maxQueryCacheSize = 1000;

Review Comment:
   The default value constant could be defined in this class (or in some other class in query engine plugin) and reused in HttpManagementConfiguration to avoid duplication of default values.



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -63,12 +62,12 @@
     /**
      * Maximal amount of queries allowed caching
      */
-    private int _maxQueryCacheSize = HttpPort.DEFAULT_QUERY_ENGINE_CACHE_SIZE;
+    private int _maxQueryCacheSize = 1000;
 
     /**
      * Maximal amount of query tree nodes allowed
      */
-    private int _maxQueryDepth = HttpPort.DEFAULT_QUERY_ENGINE_MAX_QUERY_DEPTH;
+    private int _maxQueryDepth = 4096;

Review Comment:
   The default value constant could be defined in this class (or in some other class in query engine plugin) and reused in HttpManagementConfiguration to avoid duplication of default values.



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -78,7 +77,7 @@
     /**
      * ZoneId used in date/time representation
      */
-    private ZoneId _zoneId = ZoneId.of(HttpPort.DEFAULT_QUERY_ENGINE_ZONE_ID);
+    private ZoneId _zoneId = ZoneId.of("UTC");

Review Comment:
   The default value constant could be defined in this class (or in some other class in query engine plugin) and reused in HttpManagementConfiguration to avoid duplication of default values.



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r866737318


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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;
+
+import java.math.BigDecimal;
+import java.time.ZoneId;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.port.HttpPort;
+import org.apache.qpid.server.query.engine.cache.MaxSizeHashMap;
+import org.apache.qpid.server.query.engine.evaluator.QueryEvaluator;
+import org.apache.qpid.server.query.engine.evaluator.settings.QuerySettings;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Bridge class between broker configuration and query evaluator
+ */
+// sonar complains about underscores in variable names
+@SuppressWarnings("java:S116")
+public class QueryEngine
+{
+    /**
+     * Broker instance
+     */
+    private final Broker<?> _broker;
+
+    /**
+     * Cache holding queries
+     */
+    private final Map<String, QueryExpression<?, ?>> _queryCache;
+
+    /**
+     * Maximal allowed BigDecimal value.
+     * Is needed to prevent heap memory consumption when calculating very large numbers.
+     */
+    private BigDecimal _maxBigDecimalValue = BigDecimal.valueOf(Double.MAX_VALUE).pow(4);
+
+    /**
+     * Maximal amount of queries allowed caching
+     */
+    private final int _maxQueryCacheSize;
+
+    /**
+     * Maximal amount of query tree nodes allowed
+     */
+    private int _maxQueryDepth;
+
+    /**
+     * Zone id
+     */
+    private ZoneId _zoneId;
+
+    /**
+     * Constructor injects broker and retrieves default configuration values
+     *
+     * @param broker Broker instance
+     */
+    // mutable broker instance is stored intentionally
+    @SuppressWarnings("findbugs:EI_EXPOSE_REP2")
+    public QueryEngine(final Broker<?> broker)
+    {
+        Objects.requireNonNull(broker, "Broker instance not provided for querying");
+        _broker = broker;
+        final HttpPort<?> httpPort = broker.getPorts().stream()
+            .filter(port -> Objects.equals("HTTP", port.getType()))
+            .map(port -> (HttpPort<?>)port)
+            .findFirst()
+            .orElseThrow(() -> new IllegalArgumentException("HTTP port not found"));

Review Comment:
   As the configuration was moved to http management, code fragment with iteration over ports and exception throwing was removed



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
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



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r866737563


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/EvaluationContext.java:
##########
@@ -0,0 +1,154 @@
+/*
+ *
+ * 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.evaluator;
+
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.qpid.server.query.engine.parsing.expression.Expression;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Holds temporary values needed during query evaluation
+ */
+@SuppressWarnings({"java:S116", "unchecked"})
+public class EvaluationContext
+{
+    public static final String BROKER = "broker";
+
+    public static final String STATISTICS = "statistics";
+
+    public static final String QUERY_AGGREGATED_RESULT = "query.aggregated.result";
+
+    public static final String QUERY_ALIASES = "query.aliases";
+
+    public static final String QUERY_DATETIME_PATTERN_OVERRIDEN = "query.datetime.pattern.overriden";
+
+    public static final String QUERY_DEPTH = "query.depth";
+
+    public static final String QUERY_ORDERING = "query.ordering";
+
+    public static final String QUERY_ITEMS_FOR_REMOVAL = "query.items.for.removal";
+
+    public static final String QUERY_ORDER_ITEMS_FOR_REMOVAL = "query.order.items.for.removal";
+
+    public static final String QUERY_SETTINGS = "query.settings";
+
+    public static final String COMPARATORS = "comparators";
+
+    private final Map<Object, Object> _values = new HashMap<>();

Review Comment:
   HashMap was replaced with ConcurrentHashMap



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r893578143


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -63,12 +62,12 @@
     /**
      * Maximal amount of queries allowed caching
      */
-    private int _maxQueryCacheSize = HttpPort.DEFAULT_QUERY_ENGINE_CACHE_SIZE;
+    private int _maxQueryCacheSize = 1000;

Review Comment:
   Default query settings values were moved to the separate class DefaultQuerySettings



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -63,12 +62,12 @@
     /**
      * Maximal amount of queries allowed caching
      */
-    private int _maxQueryCacheSize = HttpPort.DEFAULT_QUERY_ENGINE_CACHE_SIZE;
+    private int _maxQueryCacheSize = 1000;
 
     /**
      * Maximal amount of query tree nodes allowed
      */
-    private int _maxQueryDepth = HttpPort.DEFAULT_QUERY_ENGINE_MAX_QUERY_DEPTH;
+    private int _maxQueryDepth = 4096;

Review Comment:
   Default query settings values were moved to the separate class DefaultQuerySettings



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/settings/QuerySettings.java:
##########
@@ -78,7 +77,7 @@
     /**
      * ZoneId used in date/time representation
      */
-    private ZoneId _zoneId = ZoneId.of(HttpPort.DEFAULT_QUERY_ENGINE_ZONE_ID);
+    private ZoneId _zoneId = ZoneId.of("UTC");

Review Comment:
   Default query settings values were moved to the separate class DefaultQuerySettings



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] alex-rufous commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
alex-rufous commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r865411418


##########
broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java:
##########
@@ -72,6 +72,21 @@
     @ManagedContextDefault(name = TLS_SESSION_CACHE_SIZE, description = "TLS session cache size for HTTP ports.")
     int DEFAULT_TLS_SESSION_CACHE_SIZE = 1000;
 
+    String QUERY_ENGINE_CACHE_SIZE = "qpid.port.http.query.engine.cacheSize";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_CACHE_SIZE, description = "Broker query engine cache size.")
+    int DEFAULT_QUERY_ENGINE_CACHE_SIZE = 1000;
+
+    String QUERY_ENGINE_MAX_QUERY_DEPTH = "qpid.port.http.query.engine.maxQueryDepth";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_MAX_QUERY_DEPTH, description = "Broker query engine max query depth.")
+    int DEFAULT_QUERY_ENGINE_MAX_QUERY_DEPTH = 4096;
+
+    String QUERY_ENGINE_ZONE_ID = "qpid.port.http.query.engine.zoneId";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_ZONE_ID, description = "Broker query engine zone id.")

Review Comment:
   A word 'time' is missed before word 'zone'.  IMHO, it should be 'Broker query engine time zone id.'



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/evaluator/EvaluationContext.java:
##########
@@ -0,0 +1,154 @@
+/*
+ *
+ * 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.evaluator;
+
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.qpid.server.query.engine.parsing.expression.Expression;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Holds temporary values needed during query evaluation
+ */
+@SuppressWarnings({"java:S116", "unchecked"})
+public class EvaluationContext
+{
+    public static final String BROKER = "broker";
+
+    public static final String STATISTICS = "statistics";
+
+    public static final String QUERY_AGGREGATED_RESULT = "query.aggregated.result";
+
+    public static final String QUERY_ALIASES = "query.aliases";
+
+    public static final String QUERY_DATETIME_PATTERN_OVERRIDEN = "query.datetime.pattern.overriden";
+
+    public static final String QUERY_DEPTH = "query.depth";
+
+    public static final String QUERY_ORDERING = "query.ordering";
+
+    public static final String QUERY_ITEMS_FOR_REMOVAL = "query.items.for.removal";
+
+    public static final String QUERY_ORDER_ITEMS_FOR_REMOVAL = "query.order.items.for.removal";
+
+    public static final String QUERY_SETTINGS = "query.settings";
+
+    public static final String COMPARATORS = "comparators";
+
+    private final Map<Object, Object> _values = new HashMap<>();

Review Comment:
   HashMap is not thread safe. Would it be better to use ConcurrentHashMap? I am not sure whether thread safety is need for this class



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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;
+
+import java.math.BigDecimal;
+import java.time.ZoneId;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.port.HttpPort;
+import org.apache.qpid.server.query.engine.cache.MaxSizeHashMap;
+import org.apache.qpid.server.query.engine.evaluator.QueryEvaluator;
+import org.apache.qpid.server.query.engine.evaluator.settings.QuerySettings;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Bridge class between broker configuration and query evaluator
+ */
+// sonar complains about underscores in variable names
+@SuppressWarnings("java:S116")
+public class QueryEngine
+{
+    /**
+     * Broker instance
+     */
+    private final Broker<?> _broker;
+
+    /**
+     * Cache holding queries
+     */
+    private final Map<String, QueryExpression<?, ?>> _queryCache;
+
+    /**
+     * Maximal allowed BigDecimal value.
+     * Is needed to prevent heap memory consumption when calculating very large numbers.
+     */
+    private BigDecimal _maxBigDecimalValue = BigDecimal.valueOf(Double.MAX_VALUE).pow(4);
+
+    /**
+     * Maximal amount of queries allowed caching
+     */
+    private final int _maxQueryCacheSize;
+
+    /**
+     * Maximal amount of query tree nodes allowed
+     */
+    private int _maxQueryDepth;
+
+    /**
+     * Zone id
+     */
+    private ZoneId _zoneId;
+
+    /**
+     * Constructor injects broker and retrieves default configuration values
+     *
+     * @param broker Broker instance
+     */
+    // mutable broker instance is stored intentionally
+    @SuppressWarnings("findbugs:EI_EXPOSE_REP2")
+    public QueryEngine(final Broker<?> broker)
+    {
+        Objects.requireNonNull(broker, "Broker instance not provided for querying");
+        _broker = broker;
+        final HttpPort<?> httpPort = broker.getPorts().stream()

Review Comment:
   In case when multiple http ports with different query context variables are declared, with the current implementation the caching settings can be taken from the first port. IMHO, either the cache instance should be  created per port or  you can move the cache settings into http management or broker. Are you planning to create a cache instance per port?



##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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;
+
+import java.math.BigDecimal;
+import java.time.ZoneId;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.port.HttpPort;
+import org.apache.qpid.server.query.engine.cache.MaxSizeHashMap;
+import org.apache.qpid.server.query.engine.evaluator.QueryEvaluator;
+import org.apache.qpid.server.query.engine.evaluator.settings.QuerySettings;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Bridge class between broker configuration and query evaluator
+ */
+// sonar complains about underscores in variable names
+@SuppressWarnings("java:S116")
+public class QueryEngine
+{
+    /**
+     * Broker instance
+     */
+    private final Broker<?> _broker;
+
+    /**
+     * Cache holding queries
+     */
+    private final Map<String, QueryExpression<?, ?>> _queryCache;
+
+    /**
+     * Maximal allowed BigDecimal value.
+     * Is needed to prevent heap memory consumption when calculating very large numbers.
+     */
+    private BigDecimal _maxBigDecimalValue = BigDecimal.valueOf(Double.MAX_VALUE).pow(4);
+
+    /**
+     * Maximal amount of queries allowed caching
+     */
+    private final int _maxQueryCacheSize;
+
+    /**
+     * Maximal amount of query tree nodes allowed
+     */
+    private int _maxQueryDepth;
+
+    /**
+     * Zone id
+     */
+    private ZoneId _zoneId;
+
+    /**
+     * Constructor injects broker and retrieves default configuration values
+     *
+     * @param broker Broker instance
+     */
+    // mutable broker instance is stored intentionally
+    @SuppressWarnings("findbugs:EI_EXPOSE_REP2")
+    public QueryEngine(final Broker<?> broker)
+    {
+        Objects.requireNonNull(broker, "Broker instance not provided for querying");
+        _broker = broker;
+        final HttpPort<?> httpPort = broker.getPorts().stream()
+            .filter(port -> Objects.equals("HTTP", port.getType()))
+            .map(port -> (HttpPort<?>)port)
+            .findFirst()
+            .orElseThrow(() -> new IllegalArgumentException("HTTP port not found"));

Review Comment:
   Theoretically, the Broker can be ran without HTTP port. If exception is thrown, it might crash the Broker. IMHO, the cache should not be created in such case.



##########
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:
   why not `Double.parseDouble((String)arg).longValue()`?



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r866736034


##########
broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java:
##########
@@ -72,6 +72,21 @@
     @ManagedContextDefault(name = TLS_SESSION_CACHE_SIZE, description = "TLS session cache size for HTTP ports.")
     int DEFAULT_TLS_SESSION_CACHE_SIZE = 1000;
 
+    String QUERY_ENGINE_CACHE_SIZE = "qpid.port.http.query.engine.cacheSize";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_CACHE_SIZE, description = "Broker query engine cache size.")
+    int DEFAULT_QUERY_ENGINE_CACHE_SIZE = 1000;
+
+    String QUERY_ENGINE_MAX_QUERY_DEPTH = "qpid.port.http.query.engine.maxQueryDepth";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_MAX_QUERY_DEPTH, description = "Broker query engine max query depth.")
+    int DEFAULT_QUERY_ENGINE_MAX_QUERY_DEPTH = 4096;
+
+    String QUERY_ENGINE_ZONE_ID = "qpid.port.http.query.engine.zoneId";
+    @SuppressWarnings("unused")
+    @ManagedContextDefault(name = QUERY_ENGINE_ZONE_ID, description = "Broker query engine zone id.")

Review Comment:
   Changed variable name as well as the description to include the word "time"



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] vavrtom merged pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
vavrtom merged PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121


-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r893576901


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -112,6 +111,10 @@ public void setMaxBigDecimalValue(final BigDecimal maxBigDecimalValue)
         _maxBigDecimalValue = maxBigDecimalValue;
     }
 
+    public void setMaxQueryCacheSize(final int maxQueryCacheSize) {

Review Comment:
   Fixed



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [qpid-broker-j] dakirily commented on a diff in pull request #121: QPID-8581: [Broker-J] Broker-J Query REST API improvements

Posted by GitBox <gi...@apache.org>.
dakirily commented on code in PR #121:
URL: https://github.com/apache/qpid-broker-j/pull/121#discussion_r866736577


##########
broker-plugins/broker-query-engine/src/main/java/org/apache/qpid/server/query/engine/QueryEngine.java:
##########
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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;
+
+import java.math.BigDecimal;
+import java.time.ZoneId;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.port.HttpPort;
+import org.apache.qpid.server.query.engine.cache.MaxSizeHashMap;
+import org.apache.qpid.server.query.engine.evaluator.QueryEvaluator;
+import org.apache.qpid.server.query.engine.evaluator.settings.QuerySettings;
+import org.apache.qpid.server.query.engine.parsing.query.QueryExpression;
+
+/**
+ * Bridge class between broker configuration and query evaluator
+ */
+// sonar complains about underscores in variable names
+@SuppressWarnings("java:S116")
+public class QueryEngine
+{
+    /**
+     * Broker instance
+     */
+    private final Broker<?> _broker;
+
+    /**
+     * Cache holding queries
+     */
+    private final Map<String, QueryExpression<?, ?>> _queryCache;
+
+    /**
+     * Maximal allowed BigDecimal value.
+     * Is needed to prevent heap memory consumption when calculating very large numbers.
+     */
+    private BigDecimal _maxBigDecimalValue = BigDecimal.valueOf(Double.MAX_VALUE).pow(4);
+
+    /**
+     * Maximal amount of queries allowed caching
+     */
+    private final int _maxQueryCacheSize;
+
+    /**
+     * Maximal amount of query tree nodes allowed
+     */
+    private int _maxQueryDepth;
+
+    /**
+     * Zone id
+     */
+    private ZoneId _zoneId;
+
+    /**
+     * Constructor injects broker and retrieves default configuration values
+     *
+     * @param broker Broker instance
+     */
+    // mutable broker instance is stored intentionally
+    @SuppressWarnings("findbugs:EI_EXPOSE_REP2")
+    public QueryEngine(final Broker<?> broker)
+    {
+        Objects.requireNonNull(broker, "Broker instance not provided for querying");
+        _broker = broker;
+        final HttpPort<?> httpPort = broker.getPorts().stream()

Review Comment:
   Configuration was moved to http management



-- 
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: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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