Skip to content

Constant flattening in math expression#3090

Merged
fjy merged 3 commits intoapache:masterfrom
navis:expr-const-flatten
Nov 14, 2016
Merged

Constant flattening in math expression#3090
fjy merged 3 commits intoapache:masterfrom
navis:expr-const-flatten

Conversation

@navis
Copy link
Copy Markdown
Contributor

@navis navis commented Jun 7, 2016

constant expression in math-expr can be simplified in compile time when all of the arguments are constant and the function is deterministic (currently all functions and operation in math-expr is deterministic). For example, (8 + 7) * 10) now returns simply 150 not (* (+ 8 7) 10).

@navis navis mentioned this pull request Jun 7, 2016
@navis navis force-pushed the expr-const-flatten branch from bdce500 to 94034d8 Compare June 7, 2016 02:32
@navis navis changed the title Constant flatteing in math expression Constant flattening in math expression Jun 7, 2016
@navis navis force-pushed the expr-const-flatten branch from 94034d8 to c018556 Compare June 7, 2016 07:16
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit : this can be changed to single condition check,
if(eval instanceof Long)
return LongExpr(..)
else ret DoubleExpr(...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's problem that we don't have type information for evaluation result. Wishfully #2836 would be included in sometime. Addressed anyway, thanks.

@navis navis force-pushed the expr-const-flatten branch from c018556 to 0ec4b1b Compare June 8, 2016 00:00
@jaehc
Copy link
Copy Markdown
Contributor

jaehc commented Oct 19, 2016

LGTM

@navis navis force-pushed the expr-const-flatten branch 4 times, most recently from bb62934 to 8f47e73 Compare October 25, 2016 23:41
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs 2 arguments, plural

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2836

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially now that you're using getFunction() to access this, making this (and the logger) private would be cleaner. Maybe add a hasFunction() if needed for ExprListenerImpl.exitFunctionExpr()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really extend Function? What do you expect FunctionFactory.apply() to do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this not to make two classes (factory and function) for each stateful functions. if it's look that bad, I can separate these two.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this for now, maybe we can revisit once you have some implementations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer either dynamically constructing by class name or doing else if for UnaryNotExpr() and returning original expr for unimplemented cases. Someone's going to add another UnaryExpr type and this won't work right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fail if the List object is immutable. Can we either enforce that the list is mutable or write into another list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made new list

@navis
Copy link
Copy Markdown
Contributor Author

navis commented Nov 3, 2016

rebased on #2836 and waiting it to be committed

@gianm
Copy link
Copy Markdown
Contributor

gianm commented Nov 3, 2016

@navis we can take another look after rebased; #2836 is committed.

@navis navis force-pushed the expr-const-flatten branch from 8f47e73 to 30cca12 Compare November 4, 2016 00:05
@navis
Copy link
Copy Markdown
Contributor Author

navis commented Nov 4, 2016

rebased on master

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just be sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary parentheses around value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary parentheses around value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IAE("Invalid function name '%s'", name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, fattening -> flattening I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@dclim
Copy link
Copy Markdown
Contributor

dclim commented Nov 4, 2016

Minor cleanup, otherwise LGTM 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not instanceof ConstantExpr? It seems like there is no point to having "ConstantExpr" as an interface if we can't use it to figure out if something is a constant or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it feasible to add isConstant as a method on Expr?

I think it's nice to have all the logic for a particular expr together in the expr class, rather than spread around the project in methods like isConstant and flatten. That makes it easier to add new exprs without having to update a lot of different places in the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with instanceof ConstantExpr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect this to happen "normally" or is this really a problem indicating a bug? If it's going to happen "normally" it shouldn't be log.info as that will be too noisy in the logs. If it indicates a bug, please bump it up to log.warn.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped up to warn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, what's going on here? It looks like this is saying that f(const) = null which doesn't seem right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be Evals.isAllConstants(fattening). fixed and added test case

@gianm gianm added this to the 0.9.3 milestone Nov 4, 2016
@navis navis force-pushed the expr-const-flatten branch from 30cca12 to 7182e0b Compare November 7, 2016 00:41
@fjy
Copy link
Copy Markdown
Contributor

fjy commented Nov 8, 2016

@navis I think there's a few remaining issues. Any chance to finish this up?

@navis navis force-pushed the expr-const-flatten branch from 7182e0b to 0597931 Compare November 10, 2016 00:34
@navis
Copy link
Copy Markdown
Contributor Author

navis commented Nov 10, 2016

@fjy I think I've addressed all comments

@fjy fjy closed this Nov 10, 2016
@fjy fjy reopened this Nov 10, 2016
@fjy
Copy link
Copy Markdown
Contributor

fjy commented Nov 10, 2016

@nishantmonu51 any more comments?

@fjy
Copy link
Copy Markdown
Contributor

fjy commented Nov 14, 2016

👍

@fjy fjy merged commit bb26636 into apache:master Nov 14, 2016
fundead pushed a commit to fundead/druid that referenced this pull request Dec 7, 2016
* Constant flatteing in math expression

* Addressed comments and fixed some bugs

* Addressed comments
dgolitsyn pushed a commit to metamx/druid that referenced this pull request Feb 14, 2017
* Constant flatteing in math expression

* Addressed comments and fixed some bugs

* Addressed comments
seoeun25 pushed a commit to seoeun25/incubator-druid that referenced this pull request Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants