Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support expressions #13

Open
rcoh opened this issue Mar 30, 2018 · 10 comments
Open

support expressions #13

rcoh opened this issue Mar 30, 2018 · 10 comments
Labels
enhancement New feature or request
Milestone

Comments

@rcoh
Copy link
Owner

rcoh commented Mar 30, 2018

eg. sum(response_ms*2). Expressions can be used either inline or as an assignment:
let response_ms = response_ms * 2

@rcoh rcoh modified the milestone: 1.0 Mar 30, 2018
@rcoh
Copy link
Owner Author

rcoh commented Apr 7, 2018

where is supported as well as some basic expressions

@rcoh
Copy link
Owner Author

rcoh commented Apr 9, 2018

equality expressions are supported. Arithmetic needed

@rcoh rcoh added the enhancement New feature or request label Jun 3, 2019
@tstack
Copy link
Contributor

tstack commented Jul 22, 2020

So, I'm taking a whack at this and running into an issue with eval_borrowed():

fn eval_borrowed<'a>(&self, record: &'a Data) -> Result<&'a T, EvalError>;

Since the lifetime of the result is the same as the input HashMap, I don't think there's a way to construct an intermediate value for the result of say an addition. Things have worked so far with bool since the true/false values are &'static. I thought about storing the intermediate in the input HashMap, but that is not mutable at this point. What are your thoughts @rcoh ? Should the result be cloned instead of returned by ref? Or, should the input HashMap be made mutable? Or...

@rcoh
Copy link
Owner Author

rcoh commented Jul 22, 2020 via email

@tstack
Copy link
Contributor

tstack commented Jul 22, 2020

can you just implement Evaluatable instead of EvalutatbleBorrowed?

Hmm, I don't think so... most things seem to call eval_borrowed() and it has a big match for the Expr enum that needs to have all cases satisfied. I don't know why EvaluatableBorrowed exists either. Probably for the sake of performance?

@rcoh
Copy link
Owner Author

rcoh commented Jul 22, 2020

Yeah I was probably trying to avoid cloning. It could really mess things up but we could:

  • Switch to cloning during eval (RIP eval borrowed)
  • Switch to Rc/Arc for the output of eval to avoid a full clone
  • Implement Copy for Data::Value either by cloning the string or by sticking the string in an Rc.

@rcoh
Copy link
Owner Author

rcoh commented Jul 22, 2020

OK, I played around with it a little bit. It's a midsize refactor, but I think the answer is to replace eval_borrowed with eval_cow:

pub trait EvaluatableCow<T: Clone> {
    fn eval_cow<'a>(&self, record: &'a Data) -> Result<Cow<'a, T>, EvalError>;
}

Cow will allow eval to return something either borrowed or owned and it's pretty ergonomic to use since it implements the std::borrow magic.

I think it may be a pretty big refactoring, so I can take it on if you want.

@tstack
Copy link
Contributor

tstack commented Jul 22, 2020

I removed borrowed and have it working. I'll try to implement the Cow version.

... but, there's a lifetime in the Cow type signature. Won't that still cause the same problem?

@rcoh
Copy link
Owner Author

rcoh commented Jul 22, 2020 via email

@tstack
Copy link
Contributor

tstack commented Jul 7, 2021

Do you happen to remember what is left to do here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants