-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
SQL: Fix result column names for arithmetic functions #33500
Changes from all commits
93744ee
032686c
c413094
46c1582
5b046e2
8692616
55fea13
23eb6d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import org.elasticsearch.xpack.sql.expression.Expression; | ||
import org.elasticsearch.xpack.sql.expression.Expressions; | ||
import org.elasticsearch.xpack.sql.expression.FieldAttribute; | ||
import org.elasticsearch.xpack.sql.expression.LiteralAttribute; | ||
import org.elasticsearch.xpack.sql.expression.function.Function; | ||
import org.elasticsearch.xpack.sql.expression.function.aggregate.AggregateFunctionAttribute; | ||
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinition; | ||
|
@@ -68,6 +69,9 @@ protected ScriptTemplate asScript(Expression exp) { | |
if (attr instanceof AggregateFunctionAttribute) { | ||
return asScriptFrom((AggregateFunctionAttribute) attr); | ||
} | ||
if (attr instanceof LiteralAttribute) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because at that point the literal expression is an |
||
return asScriptFrom((LiteralAttribute) attr); | ||
} | ||
// fall-back to | ||
return asScriptFrom((FieldAttribute) attr); | ||
} | ||
|
@@ -98,6 +102,12 @@ protected ScriptTemplate asScriptFrom(AggregateFunctionAttribute aggregate) { | |
aggregate.dataType()); | ||
} | ||
|
||
protected ScriptTemplate asScriptFrom(LiteralAttribute literal) { | ||
return new ScriptTemplate(formatScript("{}"), | ||
paramsBuilder().variable(literal.literal()).build(), | ||
literal.dataType()); | ||
} | ||
|
||
protected String formatScript(String scriptTemplate) { | ||
return formatTemplate(scriptTemplate); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we'd be better off being more OO here and adding a
colunmName
function toExpression
or something like that. The fix is fine with me as it stands but I think something like that would make a good follow up change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good example of code exposing conceptual leaks. You are right that this needs OO-ing. There's already a class for that
NamedExpression
is just thatLiteral
s are not yet one. Which is the culprit - I'll raise an issue to chase that down and make sure it sits well in the overall structure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised #33523