[
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15727654#comment-15727654
]
ASF GitHub Bot commented on METRON-364:
---------------------------------------
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/390#discussion_r91225030
--- Diff:
metron-platform/metron-common/src/main/java/org/apache/metron/common/stellar/evaluators/ArithmeticEvaluator.java
---
@@ -0,0 +1,81 @@
+/*
+ * 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.metron.common.stellar.evaluators;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.metron.common.dsl.Token;
+
+import java.util.function.BiFunction;
+
+public class ArithmeticEvaluator {
+
+ public Token<? extends Number> evaluate(BiFunction<Number, Number,
Token<? extends Number>> function,
+ Pair<Token<? extends Number>,
Token<? extends Number>> p) {
+ if (p == null || p.getKey() == null || p.getValue() == null) {
+ throw new IllegalArgumentException();
+ }
+
+ final Number l = p.getKey().getValue();
+ final Number r = p.getValue().getValue();
+
+ return function.apply(l == null ? 0 : l, r == null ? 0 : r);
+ }
+
+ public interface ArithmeticEvaluatorFunctions {
+ static BiFunction<Number, Number, Token<? extends Number>> addition() {
+ return (Number l, Number r) -> {
+ if (l instanceof Double || r instanceof Double) {
--- End diff --
What about if l or r is Float?
> Stellar - Adding Two Integers Does Not Equal an Integer
> -------------------------------------------------------
>
> Key: METRON-364
> URL: https://issues.apache.org/jira/browse/METRON-364
> Project: Metron
> Issue Type: Bug
> Reporter: Nick Allen
> Labels: stellar
>
> A test showing the problem which would be part of
> org.apache.metron.common.stellar.StellarTest
> ```java
> @Test
> public void testAddIntegers() throws Exception {
> String query = "1 + 1";
> Assert.assertEquals(2, run(query, new HashMap<>()));
> // java.lang.AssertionError:
> // Expected :2
> // Actual :2.0
> }
> ```
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)