You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by cestella <gi...@git.apache.org> on 2017/07/13 09:25:19 UTC
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
GitHub user cestella opened a pull request:
https://github.com/apache/metron/pull/650
METRON-1038: Stellar should have a better collection of basic math operations
## Contributor Comments
At the moment the math functions are woefully incomplete.
We should add at least the ones difficult or impossible to reconstruct using existing stellar primitives/math functions:
* log10
* log2
* ln
* sqrt
* ceil
* floor
* sin
* cos
* tan
It should be sufficient to test these out in the Stellar REPL for manual evaluation. I have also refactored and added a more robust suite of unit tests for existing basic math functions as well as these new ones.
## Pull Request Checklist
Thank you for submitting a contribution to Apache Metron.
Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.
Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) for complete smoke testing guides.
In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
- [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
### For code changes:
- [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
- [x] Have you included steps or a guide to how the change may be verified and tested manually?
- [x] Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:
```
mvn -q clean integration-test install && build_utils/verify_licenses.sh
```
- [x] Have you written or updated unit tests and or integration tests to verify your changes?
- [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [x] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
### For documentation related changes:
- [x] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`:
```
cd site-book
mvn site
```
#### Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that [travis-ci](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cestella/incubator-metron METRON-1038
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/metron/pull/650.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 #650
----
commit 87f1cc99144de3fd6b920c10fbe7e1c1c00d0baf
Author: cstella <ce...@gmail.com>
Date: 2017-07-13T09:06:10Z
METRON-1038: Stellar should have a better collection of basic math operations
commit ee6c609664f37c7a4fb376431a1bbcd98c08faa2
Author: cstella <ce...@gmail.com>
Date: 2017-07-13T09:21:38Z
Updating docs
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127220966
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ ;
+
--- End diff --
Is there a reason why only this subset of Math.* is exposed? What about the rest? Are they not needed, applicable, or left for future work?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130883104
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/StellarMathFunction.java ---
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.ParseException;
+import org.apache.metron.stellar.dsl.StellarFunction;
+
+import java.util.List;
+
+public class StellarMathFunction implements StellarFunction {
+ MathOperation _func;
+ public StellarMathFunction(MathOperations _func) {
+ this._func = _func.op;
+ }
+
+ public StellarMathFunction(MathOperation _func) {
+ this._func = _func;
+ }
+
+ @Override
+ public Object apply(List<Object> args, Context context) throws ParseException {
+ if(args.size() < _func.getMaxArgs()) {
--- End diff --
Agreed, we need `getMinArgs()`. This is confusing; good catch.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129375260
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -613,6 +684,12 @@ In the core language functions, we support basic functional programming primitiv
* key - Property to get the value for
* Returns: String
+### `TAN`
+ * Description: Returns the `tan` of a number.
--- End diff --
You know what I want :-)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127220715
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
--- End diff --
Why have this private? why not have stellar/common/util/math/*
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130880080
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -613,6 +684,12 @@ In the core language functions, we support basic functional programming primitiv
* key - Property to get the value for
* Returns: String
+### `TAN`
+ * Description: Returns the `tan` of a number.
--- End diff --
yep :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130880027
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -581,6 +634,24 @@ In the core language functions, we support basic functional programming primitiv
* group - The integer that selects what group to select, starting at 1
* Returns: The value of the group, or null if not matched or no group at index.
+### `ROUND`
+ * Description: Rounds a number to the nearest integer
+ * Input:
+ * number - The number to round
+ * Returns: The nearest integer.
+
+### `SIN`
+ * Description: Returns the `sin` of a number.
+ * Input:
+ * number - The number to take the `sin` of
+ * Returns: The `sin` of the number passed in.
+
+### `SQRT`
+ * Description: Returns the `sqrt` of a number.
--- End diff --
yep
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129384644
--- Diff: metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/MathFunctionsTest.java ---
@@ -38,10 +46,156 @@ public static Object run(String rule, Map<String, Object> variables) {
@Test
public void testAbs() {
- Assert.assertEquals((Double)run("ABS(value)", ImmutableMap.of("value", 0)), 0, 1e-7);
- Assert.assertTrue(Double.isNaN((Double)run("ABS(value)", ImmutableMap.of("value", Double.NaN))));
- Assert.assertEquals((Double)run("ABS(value)", ImmutableMap.of("value", 10.5)), 10.5, 1e-7);
- Assert.assertEquals((Double)run("ABS(value)", ImmutableMap.of("value", -10.5)), 10.5, 1e-7);
+ assertValues("ABS",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(10.5d, 10.5d);
+ put(-10.5d, 10.5d);
+ }}
+ );
+ }
+
+ @Test
+ public void testSqrt() {
+ assertValues("SQRT",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(25d, 5d);
+ put(-10.5d, Double.NaN);
+ }}
+ );
+ }
+
+ @Test
+ public void testCeil() {
+ assertValues("CEIL",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(10.5d, 11d);
+ put(-10.5d, -10d);
+ }}
+ );
+ }
+
+ @Test
+ public void testFloor() {
+ assertValues("FLOOR",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(10.5d, 10d);
+ put(-10.5d, -11d);
+ }}
+ );
+ }
+
+ @Test
+ public void testSin() {
+ assertValues("SIN",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(Math.PI/6, 0.5);
+ put(Math.PI/4, Math.sqrt(2)/2.0);
+ put(Math.PI/3, Math.sqrt(3)/2.0);
+ put(Math.PI/2, 1d);
+ }}
+ );
+ }
+
+ @Test
+ public void testCos() {
+ assertValues("COS",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 1d);
+ put(Math.PI/6, Math.sqrt(3)/2.0);
+ put(Math.PI/4, Math.sqrt(2)/2.0);
+ put(Math.PI/3, 0.5d);
+ put(Math.PI/2, 0d);
+ }}
+ );
+ }
+
+ @Test
+ public void testTan() {
+ assertValues("TAN",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(Math.PI/6, Math.sqrt(3)/3.0);
+ put(Math.PI/4, 1d);
+ put(Math.PI/3, Math.sqrt(3));
+ put(Math.PI/2, Math.sin(Math.PI/2)/Math.cos(Math.PI/2));
+ }}
+ );
+ }
+
+ @Test
+ public void testExp() {
+ assertValues("EXP",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 1d);
+ put(0.5d, Math.sqrt(Math.E));
+ put(-0.5d, 1/Math.sqrt(Math.E));
+ put(1d, Math.E);
+ put(2d, Math.E*Math.E);
+ }}
+ );
+ }
+
+ @Test
+ public void testRound() {
+ assertValues("ROUND",
+ new HashMap<Double, Double>(baseExpectations) {{
+ put(0d, 0d);
+ put(0.5d, 1d);
+ put(0.4d, 0d);
+ put(-0.5d, 0d);
+ }}
+ );
+ }
+
+ @Test
+ public void testNaturalLog() {
+ testLog("LN", Math.E);
+ }
+
+ @Test
+ public void testLog2() {
+ testLog("LOG2", 2);
+ }
+
+ @Test
+ public void testLog10() {
+ testLog("LOG10", 10);
+ }
+
+ public void assertValues(String func, Map<Double, Double> expected) {
+ for(Map.Entry<Double, Double> test : expected.entrySet()) {
+ for(String expr : ImmutableList.of(func + "(value)"
+ ,func + "(" + test.getKey() + ")"
+ )
+ )
+ {
+ if (Double.isNaN(test.getValue())) {
+ Assert.assertTrue(expr + " != NaN, where value == " + test.getKey(), Double.isNaN(toDouble(run(expr, ImmutableMap.of("value", test.getKey())))));
+ } else {
+ Assert.assertEquals(expr + " != " + test.getValue() + " (where value == " + test.getKey() + ")", test.getValue(), toDouble(run(expr, ImmutableMap.of("value", test.getKey()))), EPSILON);
+ }
+ }
+ }
+ }
+
+ public Double toDouble(Object n) {
+ return ((Number)n).doubleValue();
+ }
+
+ public void testLog(String logExpr, double base) {
+ Map<Double, Double> expectedValues = new HashMap<Double, Double>(baseExpectations) {{
+ put(base, 1d);
+ put(0d, Double.NEGATIVE_INFINITY);
+ }};
+ for(int i = 1;i <= 10;++i) {
+ expectedValues.put(Math.pow(base, i), (double)i);
+ }
+ assertValues(logExpr, expectedValues);
--- End diff --
These test look pretty good.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127242100
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ ;
+
--- End diff --
Honestly, I just added the ones that seem to be the most pressingly missing and that we could not recreate using primitives. Did you have any functions that you wanted in there?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127245372
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ ;
+
--- End diff --
I agree. I think that in general when we are adapting or exposing a set of functionality from java or from apache-commons we should state our intent explicitly for the record.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130886124
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -101,58 +101,69 @@ In the core language functions, we support basic functional programming primitiv
## Stellar Core Functions
-| |
-| ---------- |
-| [ `ABS`](../../metron-analytics/metron-statistics#abs) |
-| [ `APPEND_IF_MISSING`](#append_if_missing) |
-| [ `BIN`](../../metron-analytics/metron-statistics#bin) |
-| [ `BLOOM_ADD`](#bloom_add) |
-| [ `BLOOM_EXISTS`](#bloom_exists) |
-| [ `BLOOM_INIT`](#bloom_init) |
-| [ `BLOOM_MERGE`](#bloom_merge) |
-| [ `CHOP`](#chop) |
-| [ `CHOMP`](#chomp) |
-| [ `COUNT_MATCHES`](#count_matches) |
-| [ `DAY_OF_MONTH`](#day_of_month) |
-| [ `DAY_OF_WEEK`](#day_of_week) |
-| [ `DAY_OF_YEAR`](#day_of_year) |
-| [ `DECODE`](#decode) |
-| [ `DOMAIN_REMOVE_SUBDOMAINS`](#domain_remove_subdomains) |
-| [ `DOMAIN_REMOVE_TLD`](#domain_remove_tld) |
-| [ `DOMAIN_TO_TLD`](#domain_to_tld) |
-| [ `ENCODE`](#encode) |
-| [ `ENDS_WITH`](#ends_with) |
-| [ `ENRICHMENT_EXISTS`](#enrichment_exists) |
-| [ `ENRICHMENT_GET`](#enrichment_get) |
-| [ `FILL_LEFT`](#fill_left) |
-| [ `FILL_RIGHT`](#fill_right) |
-| [ `FILTER`](#filter) |
-| [ `FORMAT`](#format) |
-| [ `HLLP_CARDINALITY`](../../metron-analytics/metron-statistics#hllp_cardinality) |
-| [ `HLLP_INIT`](../../metron-analytics/metron-statistics#hllp_init) |
-| [ `HLLP_MERGE`](../../metron-analytics/metron-statistics#hllp_merge) |
-| [ `HLLP_OFFER`](../../metron-analytics/metron-statistics#hllp_offer) |
-| [ `GEO_GET`](#geo_get) |
-| [ `GET`](#get) |
-| [ `GET_FIRST`](#get_first) |
-| [ `GET_LAST`](#get_last) |
-| [ `GET_SUPPORTED_ENCODINGS`](#get_supported_encodings) |
-| [ `IN_SUBNET`](#in_subnet) |
-| [ `IS_DATE`](#is_date) |
-| [ `IS_ENCODING`](#is_encoding) |
-| [ `IS_DOMAIN`](#is_domain) |
-| [ `IS_EMAIL`](#is_email) |
-| [ `IS_EMPTY`](#is_empty) |
-| [ `IS_INTEGER`](#is_integer) |
-| [ `IS_IP`](#is_ip) |
-| [ `IS_URL`](#is_url) |
-| [ `JOIN`](#join) |
-| [ `KAFKA_GET`](#kafka_get) |
-| [ `KAFKA_PROPS`](#kafka_props) |
-| [ `KAFKA_PUT`](#kafka_put) |
-| [ `KAFKA_TAIL`](#kafka_tail) |
-| [ `LENGTH`](#length) |
+| |
+| ---------- |
+| [ `ABS`](../../metron-analytics/metron-statistics#abs) |
+| [ `APPEND_IF_MISSING`](#append_if_missing) |
+| [ `BIN`](../../metron-analytics/metron-statistics#bin) |
+| [ `BLOOM_ADD`](#bloom_add) |
+| [ `BLOOM_EXISTS`](#bloom_exists) |
+| [ `BLOOM_INIT`](#bloom_init) |
+| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEILING`](#ceiling) |
+| [ `COS`](#cos) |
+| [ `CHOP`](#chop) |
+| [ `CHOMP`](#chomp) |
+| [ `COUNT_MATCHES`](#count_matches) |
+| [ `DAY_OF_MONTH`](#day_of_month) |
+| [ `DAY_OF_WEEK`](#day_of_week) |
+| [ `DAY_OF_YEAR`](#day_of_year) |
+| [ `DECODE`](#decode) |
+| [ `DOMAIN_REMOVE_SUBDOMAINS`](#domain_remove_subdomains) |
+| [ `DOMAIN_REMOVE_TLD`](#domain_remove_tld) |
+| [ `DOMAIN_TO_TLD`](#domain_to_tld) |
+| [ `ENCODE`](#encode) |
+| [ `ENDS_WITH`](#ends_with) |
+| [ `ENRICHMENT_EXISTS`](#enrichment_exists) |
+| [ `ENRICHMENT_GET`](#enrichment_get) |
+| [ `EXP`](#exp) |
+| [ `FILL_LEFT`](#fill_left) |
+| [ `FILL_RIGHT`](#fill_right) |
+| [ `FILTER`](#filter) |
+| [ `FLOOR`](#floor) |
+| [ `FORMAT`](#format) |
+| [ `HLLP_CARDINALITY`](../../metron-analytics/metron-statistics#hllp_cardinality) |
+| [ `HLLP_INIT`](../../metron-analytics/metron-statistics#hllp_init) |
+| [ `HLLP_MERGE`](../../metron-analytics/metron-statistics#hllp_merge) |
+| [ `HLLP_OFFER`](../../metron-analytics/metron-statistics#hllp_offer) |
+| [ `GEO_GET`](#geo_get) |
+| [ `GET`](#get) |
+| [ `GET_FIRST`](#get_first) |
+| [ `GET_LAST`](#get_last) |
+| [ `GET_SUPPORTED_ENCODINGS`](#get_supported_encodings) |
+| [ `IN_SUBNET`](#in_subnet) |
+| [ `IS_DATE`](#is_date) |
+| [ `IS_ENCODING`](#is_encoding) |
+| [ `IS_DOMAIN`](#is_domain) |
+| [ `IS_EMAIL`](#is_email) |
+| [ `IS_EMPTY`](#is_empty) |
+| [ `IS_INTEGER`](#is_integer) |
+| [ `IS_IP`](#is_ip) |
+| [ `IS_URL`](#is_url) |
+| [ `JOIN`](#join) |
+| [ `KAFKA_GET`](#kafka_get) |
+| [ `KAFKA_PROPS`](#kafka_props) |
+| [ `KAFKA_PUT`](#kafka_put) |
+| [ `KAFKA_TAIL`](#kafka_tail) |
+| [ `LENGTH`](#length) |
+<<<<<<< HEAD
--- End diff --
yep, fixed. Good eye :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130879898
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -110,6 +110,8 @@ In the core language functions, we support basic functional programming primitiv
| [ `BLOOM_EXISTS`](#bloom_exists) |
| [ `BLOOM_INIT`](#bloom_init) |
| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEIL`](#ceil) |
--- End diff --
Yep, changing it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127242712
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ ;
+
--- End diff --
I think they're all applicable, most of the remainder aren't as useful to Metron, IMO, but I would be willing to go through and add them if we feel that there is a need for completeness.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by simonellistonball <gi...@git.apache.org>.
Github user simonellistonball commented on the issue:
https://github.com/apache/metron/pull/650
I would like it to be committed to make it much easier for me to port my PR to it.... so +1 (non-binding)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130879985
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -238,6 +249,18 @@ In the core language functions, we support basic functional programming primitiv
* bloomfilters - A list of bloom filters to merge
* Returns: Bloom Filter or null if the list is empty
+### `CEIL`
+ * Description: Returns the ceiling of a number.
+ * Input:
+ * number - The number to take the ceiling of
+ * Returns: The ceiling of the number passed in.
+
+### `COS`
+ * Description: Returns the `cos` of a number.
--- End diff --
yep
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129378858
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/MathOperations.java ---
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import java.util.function.Function;
+
+public enum MathOperations implements Function<Number[], Number> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ EXP(d -> Math.exp(d)),
+ ROUND(new MathOperation(d -> {
+ Double val = d[0].doubleValue();
+ return Double.isNaN(val)?Double.NaN:Math.round(d[0].doubleValue());
+ }, 1)),
+ ;
+
+ private static class SingleOpFunc implements Function<Number[], Number> {
+ Function<Double, Number> f;
+ public SingleOpFunc(Function<Double, Number> f) {
+ this.f = f;
+ }
+ @Override
+ public Number apply(Number[] numbers) {
+ return f.apply(numbers[0].doubleValue());
+ }
+ }
--- End diff --
Wouldn't it make sense to give BinaryOp equal billing?
Or are you going to make @simonellistonball work it out? :-)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129374680
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -238,6 +249,18 @@ In the core language functions, we support basic functional programming primitiv
* bloomfilters - A list of bloom filters to merge
* Returns: Bloom Filter or null if the list is empty
+### `CEIL`
+ * Description: Returns the ceiling of a number.
+ * Input:
+ * number - The number to take the ceiling of
+ * Returns: The ceiling of the number passed in.
+
+### `COS`
+ * Description: Returns the `cos` of a number.
--- End diff --
Returns the cosine of a number.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129375196
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -581,6 +634,24 @@ In the core language functions, we support basic functional programming primitiv
* group - The integer that selects what group to select, starting at 1
* Returns: The value of the group, or null if not matched or no group at index.
+### `ROUND`
+ * Description: Rounds a number to the nearest integer
+ * Input:
+ * number - The number to round
+ * Returns: The nearest integer.
+
+### `SIN`
+ * Description: Returns the `sin` of a number.
+ * Input:
+ * number - The number to take the `sin` of
+ * Returns: The `sin` of the number passed in.
+
+### `SQRT`
+ * Description: Returns the `sqrt` of a number.
--- End diff --
Returns the square root of a number.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/650
Ok, I reacted to @mattf-horton and @justinleet 's comments:
* adjusted some naming and made the documentation match up
* adjusted the `ROUND` documentation to indicate half-up rounding.
* added some abstraction candy around binary functions
Let me know what you guys think.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on the issue:
https://github.com/apache/metron/pull/650
+1, lgtm. By the way, my mentions of BiFunction were incorrect because MathFunction takes an array of numbers as its (sole) argument. But glad to see you added Min Args as well as Max Args.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130883191
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/MathOperations.java ---
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import java.util.function.Function;
+
+public enum MathOperations implements Function<Number[], Number> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ EXP(d -> Math.exp(d)),
+ ROUND(new MathOperation(d -> {
+ Double val = d[0].doubleValue();
+ return Double.isNaN(val)?Double.NaN:Math.round(d[0].doubleValue());
+ }, 1)),
+ ;
+
+ private static class SingleOpFunc implements Function<Number[], Number> {
+ Function<Double, Number> f;
+ public SingleOpFunc(Function<Double, Number> f) {
+ this.f = f;
+ }
+ @Override
+ public Number apply(Number[] numbers) {
+ return f.apply(numbers[0].doubleValue());
+ }
+ }
--- End diff --
yep, I'll add it here; makes sense.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129379273
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/MathOperations.java ---
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import java.util.function.Function;
+
+public enum MathOperations implements Function<Number[], Number> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ EXP(d -> Math.exp(d)),
+ ROUND(new MathOperation(d -> {
+ Double val = d[0].doubleValue();
+ return Double.isNaN(val)?Double.NaN:Math.round(d[0].doubleValue());
+ }, 1)),
+ ;
+
+ private static class SingleOpFunc implements Function<Number[], Number> {
+ Function<Double, Number> f;
+ public SingleOpFunc(Function<Double, Number> f) {
+ this.f = f;
+ }
+ @Override
+ public Number apply(Number[] numbers) {
+ return f.apply(numbers[0].doubleValue());
+ }
+ }
+
+ MathOperation op;
+ MathOperations(Function<Double, Number> singleArg) {
+ op = new MathOperation(new SingleOpFunc(singleArg), 1);
+ }
--- End diff --
same here, MathOperations(BiFunction<Double, Double, Number> doublearg)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129380511
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -19,45 +19,179 @@
*/
package org.apache.metron.stellar.dsl.functions;
+import org.apache.metron.stellar.common.utils.math.MathOperations;
+import org.apache.metron.stellar.common.utils.math.StellarMathFunction;
import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.stellar.dsl.ParseException;
import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
+
@Stellar(name="ABS"
,description="Returns the absolute value of a number."
,params = {
"number - The number to take the absolute value of"
}
, returns="The absolute value of the number passed in."
)
- public static class Abs implements StellarFunction {
+ public static class Abs extends StellarMathFunction{
+
+
+ public Abs() {
+ super(MathOperations.ABS);
+ }
+ }
+
+ @Stellar(name="LOG10"
+ ,description="Returns the log (base 10) of a number."
+ ,params = {
+ "number - The number to take the log (base 10) value of"
+ }
+ , returns="The log (base 10) of the number passed in."
+ )
+ public static class Log10 extends StellarMathFunction {
+ public Log10() {
+ super(MathOperations.LOG10);
+ }
+
+ }
+
+ @Stellar(name="LOG2"
+ ,description="Returns the log (base 2) of a number."
+ ,params = {
+ "number - The number to take the log (base 2) value of"
+ }
+ , returns="The log (base 2) of the number passed in."
+ )
+ public static class Log2 extends StellarMathFunction {
+ public Log2() {
+ super(MathOperations.LOG2);
+ }
- @Override
- public Object apply(List<Object> args, Context context) throws ParseException {
- if(args.size() < 1) {
- return Double.NaN;
- }
- Number n = (Number)args.get(0);
- if(n == null) {
- return Double.NaN;
- }
- return Math.abs(n.doubleValue());
+ }
+
+ @Stellar(name="LN"
+ ,description="Returns the natural log of a number."
+ ,params = {
+ "number - The number to take the natural log value of"
+ }
+ , returns="The natural log of the number passed in."
+ )
+ public static class Ln extends StellarMathFunction {
+ public Ln() {
+ super(MathOperations.LN);
}
- @Override
- public void initialize(Context context) {
+ }
+ @Stellar(name="SQRT"
+ ,description="Returns the square root of a number."
+ ,params = {
+ "number - The number to take the square root of"
+ }
+ , returns="The square root of the number passed in."
+ )
+ public static class Sqrt extends StellarMathFunction {
+ public Sqrt() {
+ super(MathOperations.SQRT);
}
- @Override
- public boolean isInitialized() {
- return true;
+ }
+
+ @Stellar(name="CEIL"
+ ,description="Returns the ceiling of a number."
+ ,params = {
+ "number - The number to take the ceiling of"
+ }
+ , returns="The ceiling of the number passed in."
+ )
+ public static class Ceil extends StellarMathFunction {
+ public Ceil() {
+ super(MathOperations.CEIL);
}
+
}
+ @Stellar(name="FLOOR"
+ ,description="Returns the floor of a number."
+ ,params = {
+ "number - The number to take the floor of"
+ }
+ , returns="The floor of the number passed in."
+ )
+ public static class Floor extends StellarMathFunction {
+ public Floor() {
+ super(MathOperations.FLOOR);
+ }
+ }
+
+ @Stellar(name="SIN"
+ ,description="Returns the sin of a number."
+ ,params = {
+ "number - The number to take the sin of"
+ }
+ , returns="The sin of the number passed in."
+ )
+ public static class Sin extends StellarMathFunction {
+ public Sin() {
+ super(MathOperations.SIN);
+ }
+ }
+
+ @Stellar(name="COS"
+ ,description="Returns the cos of a number."
+ ,params = {
+ "number - The number to take the cos of"
+ }
+ , returns="The cos of the number passed in."
+ )
+ public static class Cos extends StellarMathFunction {
+ public Cos() {
+ super(MathOperations.COS);
+ }
+ }
+
+ @Stellar(name="TAN"
+ ,description="Returns the tan of a number."
+ ,params = {
+ "number - The number to take the tan of"
+ }
+ , returns="The tan of the number passed in."
+ )
+ public static class Tan extends StellarMathFunction {
+ public Tan() {
+ super(MathOperations.TAN);
+ }
+ }
+
+ @Stellar(name="EXP"
+ ,description="Returns Euler's number raised to the power of the argument"
+ ,params = {
+ "number - The power to which e is raised."
+ }
+ , returns="Euler's number raised to the power of the argument."
+ )
+ public static class Exp extends StellarMathFunction {
+ public Exp() {
+ super(MathOperations.EXP);
+ }
+ }
+
+ @Stellar(name="ROUND"
+ ,description="Rounds a number to the nearest integer"
--- End diff --
I'm okay not documenting this, since it is the norm, but if documented here do it in the .md file too.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/metron/pull/650
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by jjmeyer0 <gi...@git.apache.org>.
Github user jjmeyer0 commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130885709
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -101,58 +101,69 @@ In the core language functions, we support basic functional programming primitiv
## Stellar Core Functions
-| |
-| ---------- |
-| [ `ABS`](../../metron-analytics/metron-statistics#abs) |
-| [ `APPEND_IF_MISSING`](#append_if_missing) |
-| [ `BIN`](../../metron-analytics/metron-statistics#bin) |
-| [ `BLOOM_ADD`](#bloom_add) |
-| [ `BLOOM_EXISTS`](#bloom_exists) |
-| [ `BLOOM_INIT`](#bloom_init) |
-| [ `BLOOM_MERGE`](#bloom_merge) |
-| [ `CHOP`](#chop) |
-| [ `CHOMP`](#chomp) |
-| [ `COUNT_MATCHES`](#count_matches) |
-| [ `DAY_OF_MONTH`](#day_of_month) |
-| [ `DAY_OF_WEEK`](#day_of_week) |
-| [ `DAY_OF_YEAR`](#day_of_year) |
-| [ `DECODE`](#decode) |
-| [ `DOMAIN_REMOVE_SUBDOMAINS`](#domain_remove_subdomains) |
-| [ `DOMAIN_REMOVE_TLD`](#domain_remove_tld) |
-| [ `DOMAIN_TO_TLD`](#domain_to_tld) |
-| [ `ENCODE`](#encode) |
-| [ `ENDS_WITH`](#ends_with) |
-| [ `ENRICHMENT_EXISTS`](#enrichment_exists) |
-| [ `ENRICHMENT_GET`](#enrichment_get) |
-| [ `FILL_LEFT`](#fill_left) |
-| [ `FILL_RIGHT`](#fill_right) |
-| [ `FILTER`](#filter) |
-| [ `FORMAT`](#format) |
-| [ `HLLP_CARDINALITY`](../../metron-analytics/metron-statistics#hllp_cardinality) |
-| [ `HLLP_INIT`](../../metron-analytics/metron-statistics#hllp_init) |
-| [ `HLLP_MERGE`](../../metron-analytics/metron-statistics#hllp_merge) |
-| [ `HLLP_OFFER`](../../metron-analytics/metron-statistics#hllp_offer) |
-| [ `GEO_GET`](#geo_get) |
-| [ `GET`](#get) |
-| [ `GET_FIRST`](#get_first) |
-| [ `GET_LAST`](#get_last) |
-| [ `GET_SUPPORTED_ENCODINGS`](#get_supported_encodings) |
-| [ `IN_SUBNET`](#in_subnet) |
-| [ `IS_DATE`](#is_date) |
-| [ `IS_ENCODING`](#is_encoding) |
-| [ `IS_DOMAIN`](#is_domain) |
-| [ `IS_EMAIL`](#is_email) |
-| [ `IS_EMPTY`](#is_empty) |
-| [ `IS_INTEGER`](#is_integer) |
-| [ `IS_IP`](#is_ip) |
-| [ `IS_URL`](#is_url) |
-| [ `JOIN`](#join) |
-| [ `KAFKA_GET`](#kafka_get) |
-| [ `KAFKA_PROPS`](#kafka_props) |
-| [ `KAFKA_PUT`](#kafka_put) |
-| [ `KAFKA_TAIL`](#kafka_tail) |
-| [ `LENGTH`](#length) |
+| |
+| ---------- |
+| [ `ABS`](../../metron-analytics/metron-statistics#abs) |
+| [ `APPEND_IF_MISSING`](#append_if_missing) |
+| [ `BIN`](../../metron-analytics/metron-statistics#bin) |
+| [ `BLOOM_ADD`](#bloom_add) |
+| [ `BLOOM_EXISTS`](#bloom_exists) |
+| [ `BLOOM_INIT`](#bloom_init) |
+| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEILING`](#ceiling) |
+| [ `COS`](#cos) |
+| [ `CHOP`](#chop) |
+| [ `CHOMP`](#chomp) |
+| [ `COUNT_MATCHES`](#count_matches) |
+| [ `DAY_OF_MONTH`](#day_of_month) |
+| [ `DAY_OF_WEEK`](#day_of_week) |
+| [ `DAY_OF_YEAR`](#day_of_year) |
+| [ `DECODE`](#decode) |
+| [ `DOMAIN_REMOVE_SUBDOMAINS`](#domain_remove_subdomains) |
+| [ `DOMAIN_REMOVE_TLD`](#domain_remove_tld) |
+| [ `DOMAIN_TO_TLD`](#domain_to_tld) |
+| [ `ENCODE`](#encode) |
+| [ `ENDS_WITH`](#ends_with) |
+| [ `ENRICHMENT_EXISTS`](#enrichment_exists) |
+| [ `ENRICHMENT_GET`](#enrichment_get) |
+| [ `EXP`](#exp) |
+| [ `FILL_LEFT`](#fill_left) |
+| [ `FILL_RIGHT`](#fill_right) |
+| [ `FILTER`](#filter) |
+| [ `FLOOR`](#floor) |
+| [ `FORMAT`](#format) |
+| [ `HLLP_CARDINALITY`](../../metron-analytics/metron-statistics#hllp_cardinality) |
+| [ `HLLP_INIT`](../../metron-analytics/metron-statistics#hllp_init) |
+| [ `HLLP_MERGE`](../../metron-analytics/metron-statistics#hllp_merge) |
+| [ `HLLP_OFFER`](../../metron-analytics/metron-statistics#hllp_offer) |
+| [ `GEO_GET`](#geo_get) |
+| [ `GET`](#get) |
+| [ `GET_FIRST`](#get_first) |
+| [ `GET_LAST`](#get_last) |
+| [ `GET_SUPPORTED_ENCODINGS`](#get_supported_encodings) |
+| [ `IN_SUBNET`](#in_subnet) |
+| [ `IS_DATE`](#is_date) |
+| [ `IS_ENCODING`](#is_encoding) |
+| [ `IS_DOMAIN`](#is_domain) |
+| [ `IS_EMAIL`](#is_email) |
+| [ `IS_EMPTY`](#is_empty) |
+| [ `IS_INTEGER`](#is_integer) |
+| [ `IS_IP`](#is_ip) |
+| [ `IS_URL`](#is_url) |
+| [ `JOIN`](#join) |
+| [ `KAFKA_GET`](#kafka_get) |
+| [ `KAFKA_PROPS`](#kafka_props) |
+| [ `KAFKA_PUT`](#kafka_put) |
+| [ `KAFKA_TAIL`](#kafka_tail) |
+| [ `LENGTH`](#length) |
+<<<<<<< HEAD
--- End diff --
@cestella looks like something may have happened with a merge.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/650
Any comments or review here?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129375098
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -581,6 +634,24 @@ In the core language functions, we support basic functional programming primitiv
* group - The integer that selects what group to select, starting at 1
* Returns: The value of the group, or null if not matched or no group at index.
+### `ROUND`
+ * Description: Rounds a number to the nearest integer
+ * Input:
+ * number - The number to round
+ * Returns: The nearest integer.
+
+### `SIN`
+ * Description: Returns the `sin` of a number.
--- End diff --
Returns the sine of a number.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129374210
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -110,6 +110,8 @@ In the core language functions, we support basic functional programming primitiv
| [ `BLOOM_EXISTS`](#bloom_exists) |
| [ `BLOOM_INIT`](#bloom_init) |
| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEIL`](#ceil) |
--- End diff --
If this means CEILING, let's call it that?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130879927
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -110,6 +110,8 @@ In the core language functions, we support basic functional programming primitiv
| [ `BLOOM_EXISTS`](#bloom_exists) |
| [ `BLOOM_INIT`](#bloom_init) |
| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEIL`](#ceil) |
+| [ `COS`](#ceil) |
--- End diff --
Thanks, good catch.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/650
Committed, but I wanted to make a comment about the BiFunction. Honestly, I like the notion of providing candy for 2-arg functions like we did for single-arg functions. I think it'll make it super easy for @simonellistonball to add `POWER`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron issue #650: METRON-1038: Stellar should have a better collection of b...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:
https://github.com/apache/metron/pull/650
Ok, I broke this abstraction out a bit and made it easier to add non-single-arg functions (a la POW, which is a separate PR by @simonellistonball ). I also went ahead and added `ROUND` and `EXP`. I looked through the remainder of the math functions and honestly, I didn't see a strong reason to include any of the rest of them immediately. I'd RATHER them come in via separate PRs with some justification of use.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by justinleet <gi...@git.apache.org>.
Github user justinleet commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129292540
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -19,45 +19,179 @@
*/
package org.apache.metron.stellar.dsl.functions;
+import org.apache.metron.stellar.common.utils.math.MathOperations;
+import org.apache.metron.stellar.common.utils.math.StellarMathFunction;
import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.stellar.dsl.ParseException;
import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
+
@Stellar(name="ABS"
,description="Returns the absolute value of a number."
,params = {
"number - The number to take the absolute value of"
}
, returns="The absolute value of the number passed in."
)
- public static class Abs implements StellarFunction {
+ public static class Abs extends StellarMathFunction{
+
+
+ public Abs() {
+ super(MathOperations.ABS);
+ }
+ }
+
+ @Stellar(name="LOG10"
+ ,description="Returns the log (base 10) of a number."
+ ,params = {
+ "number - The number to take the log (base 10) value of"
+ }
+ , returns="The log (base 10) of the number passed in."
+ )
+ public static class Log10 extends StellarMathFunction {
+ public Log10() {
+ super(MathOperations.LOG10);
+ }
+
+ }
+
+ @Stellar(name="LOG2"
+ ,description="Returns the log (base 2) of a number."
+ ,params = {
+ "number - The number to take the log (base 2) value of"
+ }
+ , returns="The log (base 2) of the number passed in."
+ )
+ public static class Log2 extends StellarMathFunction {
+ public Log2() {
+ super(MathOperations.LOG2);
+ }
- @Override
- public Object apply(List<Object> args, Context context) throws ParseException {
- if(args.size() < 1) {
- return Double.NaN;
- }
- Number n = (Number)args.get(0);
- if(n == null) {
- return Double.NaN;
- }
- return Math.abs(n.doubleValue());
+ }
+
+ @Stellar(name="LN"
+ ,description="Returns the natural log of a number."
+ ,params = {
+ "number - The number to take the natural log value of"
+ }
+ , returns="The natural log of the number passed in."
+ )
+ public static class Ln extends StellarMathFunction {
+ public Ln() {
+ super(MathOperations.LN);
}
- @Override
- public void initialize(Context context) {
+ }
+ @Stellar(name="SQRT"
+ ,description="Returns the square root of a number."
+ ,params = {
+ "number - The number to take the square root of"
+ }
+ , returns="The square root of the number passed in."
+ )
+ public static class Sqrt extends StellarMathFunction {
+ public Sqrt() {
+ super(MathOperations.SQRT);
}
- @Override
- public boolean isInitialized() {
- return true;
+ }
+
+ @Stellar(name="CEIL"
+ ,description="Returns the ceiling of a number."
+ ,params = {
+ "number - The number to take the ceiling of"
+ }
+ , returns="The ceiling of the number passed in."
+ )
+ public static class Ceil extends StellarMathFunction {
+ public Ceil() {
+ super(MathOperations.CEIL);
}
+
}
+ @Stellar(name="FLOOR"
+ ,description="Returns the floor of a number."
+ ,params = {
+ "number - The number to take the floor of"
+ }
+ , returns="The floor of the number passed in."
+ )
+ public static class Floor extends StellarMathFunction {
+ public Floor() {
+ super(MathOperations.FLOOR);
+ }
+ }
+
+ @Stellar(name="SIN"
+ ,description="Returns the sin of a number."
+ ,params = {
+ "number - The number to take the sin of"
+ }
+ , returns="The sin of the number passed in."
+ )
+ public static class Sin extends StellarMathFunction {
+ public Sin() {
+ super(MathOperations.SIN);
+ }
+ }
+
+ @Stellar(name="COS"
+ ,description="Returns the cos of a number."
+ ,params = {
+ "number - The number to take the cos of"
+ }
+ , returns="The cos of the number passed in."
+ )
+ public static class Cos extends StellarMathFunction {
+ public Cos() {
+ super(MathOperations.COS);
+ }
+ }
+
+ @Stellar(name="TAN"
+ ,description="Returns the tan of a number."
+ ,params = {
+ "number - The number to take the tan of"
+ }
+ , returns="The tan of the number passed in."
+ )
+ public static class Tan extends StellarMathFunction {
+ public Tan() {
+ super(MathOperations.TAN);
+ }
+ }
+
+ @Stellar(name="EXP"
+ ,description="Returns Euler's number raised to the power of the argument"
+ ,params = {
+ "number - The power to which e is raised."
+ }
+ , returns="Euler's number raised to the power of the argument."
+ )
+ public static class Exp extends StellarMathFunction {
+ public Exp() {
+ super(MathOperations.EXP);
+ }
+ }
+
+ @Stellar(name="ROUND"
+ ,description="Rounds a number to the nearest integer"
--- End diff --
Would you mind mentioning explicitly that this is half-up rounding? That's going to be the default assumption, but it should be explicit since we aren't supporting other modes for right now.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130883151
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/MathOperations.java ---
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import java.util.function.Function;
+
+public enum MathOperations implements Function<Number[], Number> {
+ ABS(d -> Math.abs(d)),
+ CEIL(d -> Math.ceil(d)),
+ COS(d -> Math.cos(d)),
+ FLOOR(d -> Math.floor(d)),
+ LOG10(d -> Math.log10(d)),
+ LOG2(d -> Math.log(d)/Math.log(2)),
+ LN(d -> Math.log(d)),
+ SIN(d -> Math.sin(d)),
+ SQRT(d -> Math.sqrt(d)),
+ TAN(d -> Math.tan(d)),
+ EXP(d -> Math.exp(d)),
+ ROUND(new MathOperation(d -> {
+ Double val = d[0].doubleValue();
+ return Double.isNaN(val)?Double.NaN:Math.round(d[0].doubleValue());
+ }, 1)),
+ ;
+
+ private static class SingleOpFunc implements Function<Number[], Number> {
+ Function<Double, Number> f;
+ public SingleOpFunc(Function<Double, Number> f) {
+ this.f = f;
+ }
+ @Override
+ public Number apply(Number[] numbers) {
+ return f.apply(numbers[0].doubleValue());
+ }
+ }
+
+ MathOperation op;
+ MathOperations(Function<Double, Number> singleArg) {
+ op = new MathOperation(new SingleOpFunc(singleArg), 1);
+ }
--- End diff --
Yeah, I'll add binary function too
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129384031
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/MathOperation.java ---
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import java.util.function.Function;
+
+public class MathOperation {
+ private int maxArgs;
+ private Function<Number[], Number> operation;
+ public MathOperation(Function<Number[], Number> operation, int maxArgs) {
+ this.operation = operation;
+ this.maxArgs = maxArgs;
+ }
--- End diff --
If you give equal billing to binary ops in MathOperations.java, as requested below, then this also needs an additional constructor with BiFunction arg, I think.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130880007
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -581,6 +634,24 @@ In the core language functions, we support basic functional programming primitiv
* group - The integer that selects what group to select, starting at 1
* Returns: The value of the group, or null if not matched or no group at index.
+### `ROUND`
+ * Description: Rounds a number to the nearest integer
+ * Input:
+ * number - The number to round
+ * Returns: The nearest integer.
+
+### `SIN`
+ * Description: Returns the `sin` of a number.
--- End diff --
yep
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129379794
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/math/StellarMathFunction.java ---
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.stellar.common.utils.math;
+
+import org.apache.metron.stellar.dsl.Context;
+import org.apache.metron.stellar.dsl.ParseException;
+import org.apache.metron.stellar.dsl.StellarFunction;
+
+import java.util.List;
+
+public class StellarMathFunction implements StellarFunction {
+ MathOperation _func;
+ public StellarMathFunction(MathOperations _func) {
+ this._func = _func.op;
+ }
+
+ public StellarMathFunction(MathOperation _func) {
+ this._func = _func;
+ }
+
+ @Override
+ public Object apply(List<Object> args, Context context) throws ParseException {
+ if(args.size() < _func.getMaxArgs()) {
--- End diff --
If this is the logical use of getMaxArgs() then it should be called minRequiredArgs(), shouldn't it? Or perhaps you need another member for that.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by mattf-horton <gi...@git.apache.org>.
Github user mattf-horton commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r129374250
--- Diff: metron-stellar/stellar-common/README.md ---
@@ -110,6 +110,8 @@ In the core language functions, we support basic functional programming primitiv
| [ `BLOOM_EXISTS`](#bloom_exists) |
| [ `BLOOM_INIT`](#bloom_init) |
| [ `BLOOM_MERGE`](#bloom_merge) |
+| [ `CEIL`](#ceil) |
+| [ `COS`](#ceil) |
--- End diff --
wrong link
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r127242317
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -25,17 +25,39 @@
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
- @Stellar(name="ABS"
- ,description="Returns the absolute value of a number."
- ,params = {
- "number - The number to take the absolute value of"
- }
- , returns="The absolute value of the number passed in."
- )
- public static class Abs implements StellarFunction {
+ private enum SingleArgMathFunctions implements Function<Double, Double> {
--- End diff --
I can certainly pull this out if you think it's useful. I didn't think it was super useful outside of a helper enum for this class.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] metron pull request #650: METRON-1038: Stellar should have a better collecti...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/650#discussion_r130879867
--- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
@@ -19,45 +19,179 @@
*/
package org.apache.metron.stellar.dsl.functions;
+import org.apache.metron.stellar.common.utils.math.MathOperations;
+import org.apache.metron.stellar.common.utils.math.StellarMathFunction;
import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.stellar.dsl.ParseException;
import org.apache.metron.stellar.dsl.Stellar;
import org.apache.metron.stellar.dsl.StellarFunction;
import java.util.List;
+import java.util.function.Function;
public class MathFunctions {
+
@Stellar(name="ABS"
,description="Returns the absolute value of a number."
,params = {
"number - The number to take the absolute value of"
}
, returns="The absolute value of the number passed in."
)
- public static class Abs implements StellarFunction {
+ public static class Abs extends StellarMathFunction{
+
+
+ public Abs() {
+ super(MathOperations.ABS);
+ }
+ }
+
+ @Stellar(name="LOG10"
+ ,description="Returns the log (base 10) of a number."
+ ,params = {
+ "number - The number to take the log (base 10) value of"
+ }
+ , returns="The log (base 10) of the number passed in."
+ )
+ public static class Log10 extends StellarMathFunction {
+ public Log10() {
+ super(MathOperations.LOG10);
+ }
+
+ }
+
+ @Stellar(name="LOG2"
+ ,description="Returns the log (base 2) of a number."
+ ,params = {
+ "number - The number to take the log (base 2) value of"
+ }
+ , returns="The log (base 2) of the number passed in."
+ )
+ public static class Log2 extends StellarMathFunction {
+ public Log2() {
+ super(MathOperations.LOG2);
+ }
- @Override
- public Object apply(List<Object> args, Context context) throws ParseException {
- if(args.size() < 1) {
- return Double.NaN;
- }
- Number n = (Number)args.get(0);
- if(n == null) {
- return Double.NaN;
- }
- return Math.abs(n.doubleValue());
+ }
+
+ @Stellar(name="LN"
+ ,description="Returns the natural log of a number."
+ ,params = {
+ "number - The number to take the natural log value of"
+ }
+ , returns="The natural log of the number passed in."
+ )
+ public static class Ln extends StellarMathFunction {
+ public Ln() {
+ super(MathOperations.LN);
}
- @Override
- public void initialize(Context context) {
+ }
+ @Stellar(name="SQRT"
+ ,description="Returns the square root of a number."
+ ,params = {
+ "number - The number to take the square root of"
+ }
+ , returns="The square root of the number passed in."
+ )
+ public static class Sqrt extends StellarMathFunction {
+ public Sqrt() {
+ super(MathOperations.SQRT);
}
- @Override
- public boolean isInitialized() {
- return true;
+ }
+
+ @Stellar(name="CEIL"
+ ,description="Returns the ceiling of a number."
+ ,params = {
+ "number - The number to take the ceiling of"
+ }
+ , returns="The ceiling of the number passed in."
+ )
+ public static class Ceil extends StellarMathFunction {
+ public Ceil() {
+ super(MathOperations.CEIL);
}
+
}
+ @Stellar(name="FLOOR"
+ ,description="Returns the floor of a number."
+ ,params = {
+ "number - The number to take the floor of"
+ }
+ , returns="The floor of the number passed in."
+ )
+ public static class Floor extends StellarMathFunction {
+ public Floor() {
+ super(MathOperations.FLOOR);
+ }
+ }
+
+ @Stellar(name="SIN"
+ ,description="Returns the sin of a number."
+ ,params = {
+ "number - The number to take the sin of"
+ }
+ , returns="The sin of the number passed in."
+ )
+ public static class Sin extends StellarMathFunction {
+ public Sin() {
+ super(MathOperations.SIN);
+ }
+ }
+
+ @Stellar(name="COS"
+ ,description="Returns the cos of a number."
+ ,params = {
+ "number - The number to take the cos of"
+ }
+ , returns="The cos of the number passed in."
+ )
+ public static class Cos extends StellarMathFunction {
+ public Cos() {
+ super(MathOperations.COS);
+ }
+ }
+
+ @Stellar(name="TAN"
+ ,description="Returns the tan of a number."
+ ,params = {
+ "number - The number to take the tan of"
+ }
+ , returns="The tan of the number passed in."
+ )
+ public static class Tan extends StellarMathFunction {
+ public Tan() {
+ super(MathOperations.TAN);
+ }
+ }
+
+ @Stellar(name="EXP"
+ ,description="Returns Euler's number raised to the power of the argument"
+ ,params = {
+ "number - The power to which e is raised."
+ }
+ , returns="Euler's number raised to the power of the argument."
+ )
+ public static class Exp extends StellarMathFunction {
+ public Exp() {
+ super(MathOperations.EXP);
+ }
+ }
+
+ @Stellar(name="ROUND"
+ ,description="Rounds a number to the nearest integer"
--- End diff --
Yeah, I documented it in the most recent commit.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---