-
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
Expose multi-valued dates to scripts and document painless's date functions #22875
Conversation
Instead of continuing down the rabbit hole of "dates as longs" and the |
I'm all for making dates dates instead of longs. I think it'd break backwards compatibility but it wouldn't be too bad because it is already funny. @clintongormley do you think we can break backwards compatibility for date fields in scripts in 5.3 or 5.4? If we can't then maybe we should do something like what this PR proposes and pull dates into their own |
No
Is there nothing we can do to support both? Would be good to have deprecation warnings and give people a migration path in the same version. Even if it is a setting that they can change to enable to new behaviour. |
I don't think there is any non-breaking way to do it. We could minimize the breakage by supporting The other thing we'd lose is the ability to interpret |
That's what I was thinking of.
Right. Hmmm I'm really torn here. It's a breaking change, but it would be a significant improvement to the user experience today. As you say, there's a good chance that this won't hurt many users, but I'm still reluctant to do this in a minor release, unless there's a setting (opt in? opt out) to control behaviour. What about an opt in setting, and deprecation logging that points towards the setting so that users have the opportunity to migrate? I know that sounds complex, but what do you think? |
I think it sounds complex, yeah. What I'd prefer to do is:
So then: |
That sounds better to me - thank you |
@rjernst, how do you feel about my plan in #22875 (comment) ? |
I'm not thrilled about the length of it, but I can live with it. |
@rjernst would you like to review this PR then, as step 1 in the three step plan? |
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.
Looks good, I left a few suggestions.
/** | ||
* Implements {@link AbstractList} to throw helpful error messages when someone attempts to modify the doc values list. | ||
*/ | ||
public abstract class AbstractScriptDocValues<T> extends AbstractList<T> { |
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.
Could this just be a private inner class for ScriptDocValues? I don't like it being public.
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.
And can you explain why this is more helpful than using unmodifiableList
?
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.
It returns better error messages when you try to modify it. The javadoc mentions that. There is no other reason for the class.
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 ScriptDocValues
is an interface this can't be a private inner class. I can only be public. I could have made this private or package private but I didn't because I figured implementers may want to use it. We do let plugins add mappers.
It might make more sense to make ScriptDocValues
an abstract class and add these?
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.
Sure, changing ScriptDocValues
to an abstract class sounds fine to me.
/** | ||
* Implements {@link AbstractList} to throw helpful error messages when someone attempts to modify the doc values list. | ||
*/ | ||
public abstract class AbstractScriptDocValues<T> extends AbstractList<T> { |
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.
Maybe call this AbstractUnmodifiableList?
|
||
private final SortedNumericDocValues values; | ||
private final MutableDateTime date = new MutableDateTime(0, DateTimeZone.UTC); | ||
/** | ||
* Values wrapped in {@link MutableDateTime}. Null by default an allocated on first usage so there is no cost if not used. We keep |
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.
Nit: shorter max column for javadocs?
dates = new MutableDateTime[ArrayUtil.oversize(max(1, values.count()), RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; | ||
dates[index] = new MutableDateTime(value, DateTimeZone.UTC); | ||
} else { | ||
if (index >= dates.length) { |
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.
Can we just keep it simple here and eagerly allocate the array to full size (and fill it completely) above? These should be small sizes (single digits). I don't think we need to optimize as if this array could be hundreds of elements.
@rjernst I pushed a few more patches. Would you like to take a look? |
|
||
/** | ||
* Return a copy of the list of the values for the current document. | ||
*/ | ||
List<T> getValues(); | ||
public final List<T> getValues() { |
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'm curious why we have getValues if all of these classes already extend list? Nothing to do with this PR, just something I noticed: since we are looking at breaking changes in the future, maybe this could be cleaned up too (either extend list, or have getValues())
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've opened #22919 to talk about it.
} | ||
return; | ||
} | ||
if (values.count() > dates.length) { |
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.
Can you add a note here that this would only happen when switching to a different document?
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.
Sure!
Implemented by wrapping an array of reused `ModuleDateTime`s that we grow when needed. The `ModuleDateTime`s are reused when we move to the next document. Also improves the error message returned when attempting to modify the `ScriptdocValues` and removes a couple of allocations. Relates to elastic#22162
Add implementations of all the List modification methods that throw nice error messages.
5db71ea
to
e1980d8
Compare
…ctions (#22875) Implemented by wrapping an array of reused `ModuleDateTime`s that we grow when needed. The `ModuleDateTime`s are reused when we move to the next document. Also improves the error message returned when attempting to modify the `ScriptdocValues`, removes a couple of allocations, and documents that the date functions are available in Painless. Relates to #22162
Instead of longs. If you want millis since epoch you can call doc.date_field.value.millis. Relates to #22875
ScriptDocValues.Longs#getDates
which can be used to iterate over all date doc values. Attempts to minimize the number of allocations involved without adding a lot of management burden.getDates
above, Painless had fairly decent, undocumented date support.ScriptDocValues
.getValues
. Now that we have the nicer error messages it is more obvious why it is unneeded.Closes #22162