Skip to content
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: Handle the bwc Joda ZonedDateTime scripting class in Painless #37024

Merged
merged 3 commits into from Jan 4, 2019

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Dec 28, 2018

The casting method used in Painless scripting by ES SQL didn't account for JodaCompatibleZonedDateTime class introduced as part of this PR. This PR fixes this and addresses #37023.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -468,6 +468,10 @@ public static String ucase(String s) {
// Casting
//
public static Object cast(Object value, String typeName) {
return DataTypeConversion.convert(value, DataType.fromTypeName(typeName));
Object safeDateTimeValue = value;
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to rework this as part of asDateTime which handles the various types of dates that can be encountered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wasn't 100% happy about the duplicated code, either. I've pushed another approach. Let me know what you think @costin.

@astefan
Copy link
Contributor Author

astefan commented Dec 31, 2018

run the gradle build tests 2

2 similar comments
@astefan
Copy link
Contributor Author

astefan commented Dec 31, 2018

run the gradle build tests 2

@astefan
Copy link
Contributor Author

astefan commented Dec 31, 2018

run the gradle build tests 2

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Don't like the leniency however I don't have any other suggestions.

@@ -355,11 +359,14 @@ public static ZonedDateTime asDateTime(Object dateTime) {
if (dateTime instanceof ZonedDateTime) {
return (ZonedDateTime) dateTime;
}
if (dateTime instanceof Number) {
return DateUtils.of(((Number) dateTime).longValue());
if (false == lenient) {
Copy link
Member

Choose a reason for hiding this comment

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

Keep the instanceof check clean and move the if on the throw:

if (dateTime instanceof ...)
if (dateTime instanceof ...)
if (dateTime instanceof ...)

if (lenient) { return dateTime; } else { throw exception }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@costin if I take the instanceof Number condition out of the if (lenient) part, there will be failures for queries that order by or group by a casted numeric function. This is because the asDateTime is specifically being used for date/time values whereas, in case of CONVERT or CAST the instanceof Number part will be applied for NON-date/time numerics, as well.

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM

@astefan astefan merged commit 3578e69 into elastic:master Jan 4, 2019
@astefan astefan deleted the 37023_fix branch January 4, 2019 07:20
astefan added a commit that referenced this pull request Jan 4, 2019
…37024)

* Handle the bwc Joda ZonedDateTime scripting class in Painless

* Integrated the types checking in the already existent method

(cherry picked from commit 3578e69)
astefan added a commit that referenced this pull request Jan 4, 2019
…37024)

* Handle the bwc Joda ZonedDateTime scripting class in Painless

* Integrated the types checking in the already existent method

(cherry picked from commit 3578e69)
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.

None yet

5 participants