-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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: Scripting support for casting functions CAST and CONVERT #36640
Conversation
Pinging @elastic/es-search |
run the gradle build tests 2 |
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.
LGTM! Left a couple of comments, and also can we have an integ test with the cast used also in the HAVING?
// Casting | ||
// | ||
public static Object convert(Object value, String typeName) { | ||
if (value == null) { |
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 think it's unnecessary, it's done internally in convert()
# | ||
# Casting | ||
# | ||
def convert(Object, String) |
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 have a slight preference to name it cast
which is the main name for SQL, but convert is also good.
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.
+1 on cast for me as well.
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.
LGTM with the implementation moving over to processScript
instead.
@@ -74,6 +78,18 @@ protected Processor makeProcessor() { | |||
return new CastProcessor(DataTypeConversion.conversionFor(from(), to())); | |||
} | |||
|
|||
@Override | |||
public ScriptTemplate asScript() { | |||
ScriptTemplate fieldAsScript = asScript(field()); |
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.
Since the solution is to use a slightly different script, simply override processScript
(see its implementations for examples like MathFunction
). This way you only need to define the string and not worry about the boiler-plate around passing the script further.
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.
With processScript
we cannot set the dataType as parameter and we are forced to send it as String inline. Will leave it as is at the moment, as discussed.
# | ||
# Casting | ||
# | ||
def convert(Object, String) |
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.
+1 on cast for me as well.
@astefan then let's go ahead and merge this and check afterwards the HAVING case. |
closes #34557 |
This PR fixes #36061. Up until this point, there was no scripting support for CAST and CONVERT and, as such, CAST and CONVERT cannot be used in GROUP BY and ORDER BY expressions (where Painless scripting is used).