-
Notifications
You must be signed in to change notification settings - Fork 505
METRON-1563 [DISCUSS] Add Assignment to Stellar Language #687
Conversation
|
Added pre and post increment and decrement |
|
Is this ready for review? If so, can you deconflict? |
|
should be set @JonZeolla |
|
It is fair to say that this PR is more for conceptual review than anything else. |
|
Reviewer Note: Would a default method on the interface be better for update()? |
|
Hmm, so this is an interesting one. We sorta have a de facto assignment outside of stellar, but I'd be interested in having it moved into stellar like this. I'd also be sorta ok with it being Also, it seems like processing a stellar statement should return 2 things now:
We should also refactor the |
|
I would like to mention that I'm actually much more open minded to moving to |
|
I just removed the conflicts and changed StellarAssignment to account for this |
|
The question for me @cestella is the resolvers, and the consequences of having them support updating etc. I left it so that they don't by default because I didn't understand all the consequences and thought we could think it through |
|
Yeah, I'm ok with them not updating at the moment (though I think that's where we may want to go). I think a stop-gap is to just be able to pass back the variable assigned and the value from a stellar statement. We manage updating the resolvers out of band in the existing code. |
|
@cestella also: |
|
well, |
|
POV issue I think. Stellar has the LANGUAGE ( grammar ), the default implementation, and the 'host' execution mechanics.
The issue may not be being the same as much as the necessity for Does that make sense? |
|
Agreed, this is a POV issue. Though from the user perspective they aren't distinguishing between "this is in the REPL" vs "this is in the enrichment topology", so I think we do need to manage the experience if we're moving functionality from the MACHINE to the LANGUAGE to ensure it's consistent. Beyond that, it's unclear whether we need an resolver |
|
By punt you mean leave this implementation that doesn't implement update in the resolvers? |
|
also, we aren't consistent, in some places ( transformations ) we use the configuration logical structure to imply assignment, in enrichment it is |
|
I have not looked at the code yet, but wanted to comment on the assignment discussion. IMO focusing on user experience is the way to go. To that end...
All of that can happen in this PR or as multiple PRs (however @ottobackwards sees fit), but that is the right end state. Alternative Option: The only other reasonable option IMO is to support both I am mildly against the "Alternative Option", but wanted to offer it up for discussion. |
|
Yeah, I'm totally cool with going with Migration, sadly sometimes, is also part of user experience. :) |
Very true. That's why I offered up the "Alternative Option". Only my own laziness makes me "mildly against" that :) . But based on user experience (like you mention), I think we should probably do it. |
|
hah, well @nickwallen, laziness is often a good trait in a developer. Honestly, I am ok with not migrating here in favor of more intuitive approaches. I chose |
Oh, and one clarification. No users will have production code (like an enrichment) that uses |
|
@cestella @nickwallen |
|
@nickwallen No, that's not correct. Stellar enrichments can contain |
|
As a professed language nut, when you mention the word "variable", I think "scope". And it seems to me that by placing the responsibility for variable assignment/update in the VariableResolver, you've actually tied into a very natural definition of scope given the way MapVariableResolver already works in association with a target dictionary or stack of dictionaries. A. I think you should explicitly discuss scope in the documentation. There are several scopes already being used in practice, and I think users need to understand how it all works together, otherwise they will misunderstand and be bewildered. I am, no doubt, a good example, so dense that I have to ask the questions below :-) B. I don't understand why you don't go ahead and enable update in MapVariableResolver, since IIRC that's the resolver for essentially everything interesting that uses variables in Stellar. C. Do I understand correctly from the patch, that variable assignment IS enabled in lambda expressions? Presumably the scope will be the same instance dictionary where the input variables are stored, thus making them local, correct? Can new variables be created as well as input variables be updated? D. The following scopes come to mind, with associated need for clarification:
|
|
So a bunch more comments came in while I was writing the above. Nick's comment about enrichments using assignment already of course modifies my comment about Profilers, etc. Just making it uniform would give users a lot less to wonder about. As for := vs =, it's not so terrible to have both as exact synonyms. This gives you both your preferred aesthetics and backward compatibility. |
Thanks for clarifying, but 'ugh'. I'll have to look at how that is implemented. I didn't realize we had a separate implementation of assignment. Does this PR address that? Shouldn't we have one implementation of the assignment mechanism? Good commentary from @mattf-horton . I knew there was a reason why I didn't want to touch this. :) |
|
OK, The others can comment, but I think proper scope would be implemented within the execution of the call stack, not arbitrarily by the resolvers. Each resolver should be a 'scope' and new scopes should be created. A. Because it is a resolver thing, where would you document it in a way that makes sense? I have been thinking that we should refactor to explicitly support scoping in the processor/evaluations and then have the resolvers used in scope as scope implementations. So the nesting of scopes would not be done in the resolver. B. As noted in the PR description, I was hoping for discussion ( THIS discussion as a matter of fact ). Having had some issues with my other PRs and scope, I chose to explicitly NOT go that far until we talked it through. I did not feel all the way back then that I had enough of a grasp of the different resolvers to change their behavior and understand the consequences either way. C. The LambaExpression actually delegates to the state variable resolver: VariableResolver variableResolver = new DefaultVariableResolver(
variable -> lambdaVariables.getOrDefault(variable
, state.variableResolver.resolve(variable)
), variable -> true,
(variable, value) -> {
if (state.variableResolver.exists(variable)) {
state.variableResolver.update(variable, value);
}
});D.
|
|
@ottobackwards And yet this discussion primarily relates to whether the assignment operation as defined in Enrichment should be unified with the assignment operation being added to core stellar, presumably due to user demand. |
|
So, I was wrong when I initially looked at this PR, this adds variable updates to the resolver. Should we perhaps separate parsing assignments (e.g. move |
|
@mattf-horton if by 'due to user demand' you mean to work around the fact that assignment was not in the language in the first place, ok. |
|
Bump |
@ottobackwards I didn't see you respond to this. I would agree with @cestella on this. |
|
@nickwallen @cestella @mattf-horton , Sorry, I thought that question was more to @mattf-horton at the time. @cestella I'm not sure I understand what you are saying. Are you saying that we should not do assignment until we overhaul the current mechanisms? That this is too much a 1/2 measure? |
|
This is pretty old at this point, and there has been a lot of discussion all over the place about it. I'm not sure I can sum up where we are. @cestella can you sum up your current feeling on how we can move this forward? |
|
Bump @cestella |
|
Sorry, @ottobackwards this got lost in the shuffle. What I was saying was that I think we should not adjust the VariableResolver infrastructure to update variables as the result of assignments, but rather return back the variable and the updated object. For instance, in the I guess ultimately, I suggest a tactical solution that leads us to the right direction rather than trying to fix it all at once. Thoughts? |
|
I don't quite get what you are saying. I can't wrap my head around it. If you look at the example from the PR description under concept, that doesn't work without the resolver being updated. I have to be missing something |
|
So, I guess I'm suggesting that this is like..3/4 of the way to a complete solution, which is for stellar to handle variable assignments completely. Specifically, I'd say that our dominantly used variable resolver ( What I'm suggesting is one of these:
Ultimately, I LOVE this PR and I don't want you to think that I'm poo-pooing it. I think this is great work and I look forward to the feature being added. It just seemed ALMOST done, but not quite enough to stand by itself in master because the gap may leave people confused. |
|
Ok, so we are on the same page. I purposely did not put the update in the map resolver because I knew it warranted more discussion etc, and this is it. I just wasn't sure I was understanding what you were saying exactly, and honestly, every time i go back to read from the start @mattf-horton 's comments make me mush minded ;) Now we have to pick one of the options above to continue with. |
|
I think I have a minor preference for 2, honestly. I like this work and don't want it to languish or grow too big. Entirely as an aside, we should probably have a set of microbenchmark tests for stellar to ensure no performance regressions given changes to the grammar. |
|
I have renamed in preparation for the Feature branch based on the original jira ( create a new subtask to land this on feature and change to that ID ) |
=, +=, -=, *=, /= 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
fixes for handling validate with null values
375df1d to
2e94e14
Compare
|
Ok everyone, this has moved to the new PR. Thanks! |
|
btw, if you haven't checked the new fb and pr, the initial pr has landed, and has added support for |
This PR adds support for Assignment to the Stellar Language. It is dependent on METRON-711 before it can be merged.
I still need to do the doc work, and more testing.
Concept
Support for:
= , +=, -=, *=, /=, ++var, --var, var++, var--
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.
NOTE
Pull Request Checklist
Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines 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:
For code changes:
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:
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?
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: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 is set up for your personal repository such that your branches are built there before submitting a pull request.