You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/08/06 18:50:00 UTC

[jira] [Commented] (METRON-1090) STELLAR Add Assignment capability to Stellar language

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

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

GitHub user ottobackwards opened a pull request:

    https://github.com/apache/metron/pull/687

    METRON-1090 [NO MERGE UNTIL METRON-711] Add Assignment to Stellar Language

    This PR adds support for Assignment to the Stellar Language.  It is dependent on [METRON-711](https://github.com/apache/metron/pull/686) before it can be merge.
    
    I still need to do the doc work, and more testing.
    
    ## Concept
    
    - Allow for assignment of values to variables only
    - Assignment both returns the assigned value AND updates the variable
    - VariableResolver implementation may or may not choose to support updates
    - The Shell handles all assignments ( foo := 'val' ) as ("foo = 'val'"). Exposing the whole operation to Stellar allows catching illegal values and grammar
    - The LambdaExpression does attempt to update variables, but this would have effect if the state was using a VariableResolver instance that supported updates AND the variable was not a 'lambda' variable.
    
    ```java
     String expr  = "MAP([ foo, bar, baz ], (item) -> count *= 2  )";
          Map<String,Object> map = new HashMap<String,Object>(){{
            put("foo",1);
            put("bar",1);
            put("baz",1);
            put("count", 1);
          }};
          for(int i = 0 ; i < 5; i++){
            run(expr, map);
          }
          Assert.assertEquals(new DecimalFormat("#").format(Math.pow(2,15)), map.get("count").toString());
    ```
    
    Support for:
    = , +=, -=, *=,  /=
    
    
    ## Side effects:
    This is opt-in for the resolvers.  The MapVariableResolver does NOT support update, so there is no change to Enrichment, Parsers, Profile, and Shell ( beyond what has been mentioned ). 
    
    ## Testing:
    See BasicStellarTest:test*Assign() for some usages.
    
    - Existing profiles, enrichments, parser transforms would work
    - Run different statements in the shell ( including those that would have worked before like = := 6.
     - more to come
    
    
    > This PR is to get the concept as a proposal out for review and start the discussion.  I will start a 
    > discuss thread as well.
    ---------
    > Note: This PR resolves [METRON-693 : Stellar REPL lets reserved tokens be used as unusable variable names](https://issues.apache.org/jira/browse/METRON-693)  as well.
    
    
    ## 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)?
    
    > and METRON-711
    
    ### For code changes:
    - [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
    - [ ] Have you included steps or a guide to how the change may be verified and tested manually?
    - [ ] 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?
    - [ ] 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)? 
    - [ ] 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:
    - [ ] 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/ottobackwards/metron stellar_assign

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

    https://github.com/apache/metron/pull/687.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 #687
    
----
commit 215dc969026fa557a0a0f3efb9fe2bc170666b9a
Author: Otto Fowler <ot...@gmail.com>
Date:   2017-08-06T02:14:51Z

    Do not set variables when exceptions are thrown from assignment.
    Also remove executeStellar which is not required, if it doesn't eat the exception

commit f8e2fa9bdecd48fd70f03f2337439582ce341e21
Author: Otto Fowler <ot...@gmail.com>
Date:   2017-08-06T14:20:32Z

    Adds Variable Assignment to the Stellar Lanaguage
    
    =, +=, -=, *=, /=
    
    This are valid for assignment to variables.  All assignments return the value assigned,
    as other scripting languages do.
    
    VariableResolver extended with an update() method, though it may not be supported
    by all resolvers, this gives the ability to update variables and save between calls.
    
    The shell was updated for this, such that assignment calls
    
    More testing need and doc but I wanted to get it out there.
    This is dependent on PR 686

----


> STELLAR Add Assignment capability to Stellar language
> -----------------------------------------------------
>
>                 Key: METRON-1090
>                 URL: https://issues.apache.org/jira/browse/METRON-1090
>             Project: Metron
>          Issue Type: New Feature
>            Reporter: Otto Fowler
>            Assignee: Otto Fowler
>
> Add support for =, +=, -=, *=, /= for variables in stellar.
> foo = 5  returns 5 AND sets foo to 5 if the VariableResolver supports it.
> The shell should be changed to assign variables using this syntax, because exposing the left side to stellar allows catching errors for invalid keywords in left side.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)