Creating out of code Expressions

59 views
Skip to first unread message

mil...@adfin.com

unread,
Apr 21, 2014, 7:17:49 PM4/21/14
to supersonic-...@googlegroups.com
We've been using Supersonic for a while and built a lot of things ontop of it (Operations, Indexing, etc) however to this day we haven't built a custom Expression. I've sat down to look at what's needed to do this but it doesn't strike me as strait forward. There's many layers of templeting indirections, and the expression type is being passed as an enum that comes from protobuf. Is there a very simple expression that we can use as a basis of our code? Is it possible to build a new expression outside of the library codebase?

Just to shed some light I'm planing on writing a Map expression (one that is able to map one column value to another) the hope being to have this expression be part a series of projectAs.

Piotr Tabor

unread,
Apr 22, 2014, 3:26:14 AM4/22/14
to Milosz Tanski, supersonic-...@googlegroups.com
You just need to implement BoundExpression interface: 


you might extend one of the Base classes: 

than usually you create a factory method that builds such BoundExpression: 

The method creating BoundExpression should comply with one of types defined here: 

And finally one of the methods: CreateExpressionForExistingBoundFactory: 
will create the Expression* for you.


On Mon, Apr 21, 2014 at 4:17 PM, <mil...@adfin.com> wrote:
We've been using Supersonic for a while and built a lot of things ontop of it (Operations, Indexing, etc) however to this day we haven't built a custom Expression. I've sat down to look at what's needed to do this but it doesn't strike me as strait forward. There's many layers of templeting indirections, and the expression type is being passed as an enum that comes from protobuf. Is there a very simple expression that we can use as a basis of our code? Is it possible to build a new expression outside of the library codebase?

Just to shed some light I'm planing on writing a Map expression (one that is able to map one column value to another) the hope being to have this expression be part a series of projectAs.

--
You received this message because you are subscribed to the Google Groups "Supersonic Query Engine Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-...@googlegroups.com.
To post to this group, send email to supersonic-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Onufry Wojtaszczyk

unread,
Apr 22, 2014, 10:54:26 AM4/22/14
to Piotr Tabor, Milosz Tanski, supersonic-...@googlegroups.com
Most of the templates that you see (including the fact the expression type is an enum) is to use the code around templatization - the stuff that allows for faster evaluation of expressions (generally by offloading all the branching to happen before processing a single block and by inlining everything). If you wanted to use this (for an expression that actually calculates something), I would say that the ABS expression is pretty simple. Besides the bolilerplate in math_expressions.h and .cc, the equivalent boilerplate in math_bound_expressions (the .cc contains a bit of type magic that declares ABS on a UINT to be optimized out), it is registered in operators.proto, and the actual operation is defined in math_evaluators.h. The link between the enum and the evaluator is provided in expression_traits.h.
So, in order to define your own expression that uses the template magic to evaluate, you should define the equivalent boilerplate for Expression and BoundExprsesion, add your expression to the enum, add the traits to expression_traits.h, and add the actual functor that defines the expression somewhere where it will be included into expression_traits.h.

Onufry

mil...@adfin.com

unread,
Apr 22, 2014, 11:28:57 PM4/22/14
to supersonic-...@googlegroups.com, Piotr Tabor, Milosz Tanski
Thanks guys, I was able to implement my Map expression today. Thanks for the explanations on how to implement this (and links to code). Actually the RE2 Expression code ended up being a good example of how to build this.


On Tuesday, April 22, 2014 10:54:26 AM UTC-4, Onufry Wojtaszczyk wrote:
Most of the templates that you see (including the fact the expression type is an enum) is to use the code around templatization - the stuff that allows for faster evaluation of expressions (generally by offloading all the branching to happen before processing a single block and by inlining everything). If you wanted to use this (for an expression that actually calculates something), I would say that the ABS expression is pretty simple. Besides the bolilerplate in math_expressions.h and .cc, the equivalent boilerplate in math_bound_expressions (the .cc contains a bit of type magic that declares ABS on a UINT to be optimized out), it is registered in operators.proto, and the actual operation is defined in math_evaluators.h. The link between the enum and the evaluator is provided in expression_traits.h.
So, in order to define your own expression that uses the template magic to evaluate, you should define the equivalent boilerplate for Expression and BoundExprsesion, add your expression to the enum, add the traits to expression_traits.h, and add the actual functor that defines the expression somewhere where it will be included into expression_traits.h.

Onufry
On Tue, Apr 22, 2014 at 9:26 AM, Piotr Tabor <pt...@google.com> wrote:
You just need to implement BoundExpression interface: 


you might extend one of the Base classes: 

than usually you create a factory method that builds such BoundExpression: 

The method creating BoundExpression should comply with one of types defined here: 

And finally one of the methods: CreateExpressionForExistingBoundFactory: 
will create the Expression* for you.
On Mon, Apr 21, 2014 at 4:17 PM, <mil...@adfin.com> wrote:
We've been using Supersonic for a while and built a lot of things ontop of it (Operations, Indexing, etc) however to this day we haven't built a custom Expression. I've sat down to look at what's needed to do this but it doesn't strike me as strait forward. There's many layers of templeting indirections, and the expression type is being passed as an enum that comes from protobuf. Is there a very simple expression that we can use as a basis of our code? Is it possible to build a new expression outside of the library codebase?

Just to shed some light I'm planing on writing a Map expression (one that is able to map one column value to another) the hope being to have this expression be part a series of projectAs.

--
You received this message because you are subscribed to the Google Groups "Supersonic Query Engine Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-engine+unsub...@googlegroups.com.

To post to this group, send email to supersonic-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Supersonic Query Engine Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-engine+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages