[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-08 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15732318#comment-15732318
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user asfgit closed the pull request at:

https://github.com/apache/incubator-metron/pull/390


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15730187#comment-15730187
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user cestella commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
Cool!  Dig the tests.  +1 by inspection


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15730182#comment-15730182
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user jjmeyer0 commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
I believe I have updated all tests and addressed each of the concerns. 
Thanks again for all the help!


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729963#comment-15729963
 ] 

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_r91391147
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -56,6 +56,37 @@
 public class StellarTest {
 
   @Test
+  public void addingLongsShouldYieldLong() throws Exception {
+final long timestamp = 145201335L;
+String query = "TO_EPOCH_TIMESTAMP('2016-01-05 17:02:30', '-MM-dd 
HH:mm:ss', 'UTC') + 2";
+Assert.assertEquals(timestamp + 2, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingIntegersShouldYieldAnInteger() throws Exception {
+String query = "1 + 2";
+Assert.assertEquals(3, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingDoublesShouldYieldADouble() throws Exception {
+String query = "1.0 + 2.0";
+Assert.assertEquals(3.0, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsDoubleShouldYieldADouble() throws Exception 
{
+String query = "2.1 + 1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsIntegerShouldYieldADouble() throws 
Exception {
+String query = "1 + 2.1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
--- End diff --

@ottobackwards Definitely; agreed.  We should have a 
`StellarArithmeticTest` where we have this.


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729957#comment-15729957
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/390#discussion_r91390855
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -56,6 +56,37 @@
 public class StellarTest {
 
   @Test
+  public void addingLongsShouldYieldLong() throws Exception {
+final long timestamp = 145201335L;
+String query = "TO_EPOCH_TIMESTAMP('2016-01-05 17:02:30', '-MM-dd 
HH:mm:ss', 'UTC') + 2";
+Assert.assertEquals(timestamp + 2, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingIntegersShouldYieldAnInteger() throws Exception {
+String query = "1 + 2";
+Assert.assertEquals(3, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingDoublesShouldYieldADouble() throws Exception {
+String query = "1.0 + 2.0";
+Assert.assertEquals(3.0, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsDoubleShouldYieldADouble() throws Exception 
{
+String query = "2.1 + 1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsIntegerShouldYieldADouble() throws 
Exception {
+String query = "1 + 2.1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
--- End diff --

Casey - just like with the stringfunctionstest - I'm not sure that all of 
this should be in stellartest.  How do you feel about breaking it out?


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729916#comment-15729916
 ] 

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_r91386719
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -56,6 +56,37 @@
 public class StellarTest {
 
   @Test
+  public void addingLongsShouldYieldLong() throws Exception {
+final long timestamp = 145201335L;
+String query = "TO_EPOCH_TIMESTAMP('2016-01-05 17:02:30', '-MM-dd 
HH:mm:ss', 'UTC') + 2";
+Assert.assertEquals(timestamp + 2, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingIntegersShouldYieldAnInteger() throws Exception {
+String query = "1 + 2";
+Assert.assertEquals(3, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingDoublesShouldYieldADouble() throws Exception {
+String query = "1.0 + 2.0";
+Assert.assertEquals(3.0, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsDoubleShouldYieldADouble() throws Exception 
{
+String query = "2.1 + 1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsIntegerShouldYieldADouble() throws 
Exception {
+String query = "1 + 2.1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
--- End diff --

Obviously, the same set for multiplication and division.  I'd parameterize 
that case ;)


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729913#comment-15729913
 ] 

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_r91386552
  
--- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/StellarTest.java
 ---
@@ -56,6 +56,37 @@
 public class StellarTest {
 
   @Test
+  public void addingLongsShouldYieldLong() throws Exception {
+final long timestamp = 145201335L;
+String query = "TO_EPOCH_TIMESTAMP('2016-01-05 17:02:30', '-MM-dd 
HH:mm:ss', 'UTC') + 2";
+Assert.assertEquals(timestamp + 2, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingIntegersShouldYieldAnInteger() throws Exception {
+String query = "1 + 2";
+Assert.assertEquals(3, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void addingDoublesShouldYieldADouble() throws Exception {
+String query = "1.0 + 2.0";
+Assert.assertEquals(3.0, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsDoubleShouldYieldADouble() throws Exception 
{
+String query = "2.1 + 1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
+
+  @Test
+  public void 
addingDoubleAndIntegerWhereSubjectIsIntegerShouldYieldADouble() throws 
Exception {
+String query = "1 + 2.1";
+Assert.assertEquals(3.1, run(query, new HashMap<>()));
+  }
--- End diff --

Could we ensure that we have the following test cases and they return the 
proper types:
* float + long returns a float
* long + float returns a float
* double + int returns a double
* int + double returns a double
* float + double returns  a double
* double + float returns a double
* long + double returns a double
* double + long returns a double
* long + int returns a long
* int + long returns a long
* int + int returns int
* float + float returns float
* double + double returns double
* long + long returns long


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729887#comment-15729887
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user ottobackwards commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
@cestella I see it now, but not when I made the comment.  Sorry for adding 
confusion.

+1 by inspection


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729881#comment-15729881
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user cestella commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
@ottobackwards Yeah, that was my concern too.  The suggestion I made was 
based around the Java spec 
(http://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.6.2 as 
@justinleet linked earlier).  This is intended to make it follow the rule of 
least surprise (I think ;).  In your example, Long + Float  should be Float by 
my suggestion.


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729868#comment-15729868
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user ottobackwards commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
[moving this to unbury it]
My only question here, and I may be out of my depth, is does this 
functionality match the behavior of java itself? Or other languages? Would the 
result of operations on mixed types be consistent (rule of least surprise)? For 
example:

 Float + Long = Float
Long + Float = Long

Hopefully this makes sense


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15729647#comment-15729647
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/incubator-metron/pull/390#discussion_r91364920
  
--- 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 evaluate(BiFunction function,
+  Pair 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 addition() {
+  return (Number l, Number r) -> {
+if (l instanceof Double || r instanceof Double) {
--- End diff --

My only question here, and I may be out of my depth, is does this 
functionality match the behavior of java itself?  Or other languages?  Would 
the result of operations on mixed types be consistent (rule of least surprise)? 
 For example ( and again I'm just imagining here ) Float + Long = Float.
Long + Float = Long.

Hopefully this makes sense


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15728704#comment-15728704
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user jjmeyer0 commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
The reason I neglected longs and floats is because I didn't see the Stellar 
dsl having the ability to represent them. For example, the test below fails 
with a parse exception:

`
  @Test
  public void testLongAddition() throws Exception {
String query = "2147483650 + 2";
Assert.assertEquals(2147483652L, run(query, new HashMap<>()));
  }
`

That being said it makes sense to still handle longs and floats, if Stellar 
will at some point. If not that, at the very least if this evaluator sees a 
long or float it should error out.

Should I add support for longs/floats and then create a Jira for Stellar to 
add them? Or am I mistaken and Stellar already has support?


Thanks for the feedback.


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15728639#comment-15728639
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user justinleet commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
I agree on operating Casey's rules, given that they match Java's rules for 
handling this.

http://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.6.2


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15727667#comment-15727667
 ] 

ASF GitHub Bot commented on METRON-364:
---

Github user cestella commented on the issue:

https://github.com/apache/incubator-metron/pull/390
  
Oops also we will want to preserve Longs.  Down converting to an int will 
lose precision and may end up being inaccurate.  I'd suggest we operate like so:
* If either are a double then operate as doubles
* else if either are float then operate as floats
* else if either are longs then operate as longs
* else operate as ints


> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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 evaluate(BiFunction function,
+  Pair 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 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15727568#comment-15727568
 ] 

ASF GitHub Bot commented on METRON-364:
---

GitHub user jjmeyer0 opened a pull request:

https://github.com/apache/incubator-metron/pull/390

METRON-364: Preserve Type for Arithmetic Expressions in Stellar

updated stellar arithmetic expressions to be evaluated in a manner that 
keeps type. For example, if two integers are added then an integer will be 
returned.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/jjmeyer0/incubator-metron METRON-364

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-metron/pull/390.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #390


commit b69dabe5a50e5c32b8e44f03db187894199fe5a4
Author: JJ 
Date:   2016-12-07T02:50:40Z

METRON-364: updated stellar arithmetic expressions to be evaluated in a 
manner that keeps type. For example, if two integers are added then an integer 
will be returned.

commit dce230124ec62473e0102dc144a7ae911de13ca6
Author: JJ 
Date:   2016-12-07T03:28:42Z

METRON-364: updated stellar arithmetic expressions to be evaluated in a 
manner that keeps type. For example, if two integers are added then an integer 
will be returned.

commit cdd69dc3a90f0e35a117248980588179c4e3ed5c
Author: JJ 
Date:   2016-12-07T03:34:35Z

Uncommenting tests that should still run.




> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-05 Thread Nick Allen (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15723021#comment-15723021
 ] 

Nick Allen commented on METRON-364:
---

It does seem to still be a problem.  I had a Stellar REPL running that I could 
check this on real quick.
```
[Stellar]>>> TO_INTEGER(2 + 2)
4
[Stellar]>>> 2 + 2
4.0
```

> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-05 Thread Nick Allen (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15723015#comment-15723015
 ] 

Nick Allen commented on METRON-364:
---

 [~jjmeyer0]  Feel free to tackle this.  I do not know of anyone working this.

This *might* already be addressed by another fix that was made.  Even if it has 
been fixed, it would be valuable if you could confirm.  If it is, mark the JIRA 
as fixed and close it.

Thanks

> 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)


[jira] [Commented] (METRON-364) Stellar - Adding Two Integers Does Not Equal an Integer

2016-12-05 Thread Josh Meyer (JIRA)

[ 
https://issues.apache.org/jira/browse/METRON-364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15722913#comment-15722913
 ] 

Josh Meyer commented on METRON-364:
---

I'd like to give this a shot if no one has taken this yet.

> 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)