use virtual columns for sql simple aggregators instead of inline expressions#12251
Conversation
| String vc = virtualColumnRegistry.getVirtualColumnByExpression(arg, resolutionArg.getType()); | ||
| fieldName = vc != null ? vc : null; | ||
| expression = vc != null ? null : arg.getExpression(); | ||
| if (arg.getType() == DruidExpression.NodeType.LITERAL) { |
There was a problem hiding this comment.
This doesn't really feel like somethign that each implementation should have to do to me... Could we not like pass in the virtualColumnRegistry to the DruidExpression and ask it to tell us the expression to use? Where, like, in the literal case, it would give us an expression that's just a literal and in the non-literal case it would register the thing and then return the name to use for it?
There was a problem hiding this comment.
i did consolidate this into a static method in SimpleSqlAggregator while you were typing this comment, I haven't really decided on baking it into VirtualColumnRegistry in some way yet though, will think about it some more.
There was a problem hiding this comment.
after further thought i've decided to just always use a virtual column, even for literals, so this code is simplified a bit now
…ual-column-instead-of-inline-expressions
|
I have confirmed this change is safe for min/max aggregators, which have special logic when using the added a couple of additional tests from this investigation, just to document inconsistencies in behavior. It also appears that the "string wrappers" that the numeric aggregators use, |
Description
Follow-up to #12241, this PR updates the "simple" SQL aggregators, such as
SUM,MIN, andMAXto useVirtualColumninstead of the inlineexpressionto maximize expression re-use for anything more complicated than a literal value.CalciteQueryTest.testExpressionAggregationshas been update to have aggregators which share a common expression, which will now be shared between these two aggregators instead of each specifying it inline. Additionally, this allows these aggregators to participate in the 'specialization' added in #12241.Finally, did some follow-up javadoc and naming adjustments per comments in the previous PR.
Key changed/added classes in this PR
SimpleSqlAggregatorDruidExpressionVirtualColumnRegistryThis PR has: