-
Notifications
You must be signed in to change notification settings - Fork 140
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
Fix: Date field format parsing for legacy query engine #3160
base: main
Are you sure you want to change the base?
Fix: Date field format parsing for legacy query engine #3160
Conversation
Signed-off-by: Andy Kwok <[email protected]>
Signed-off-by: Andy Kwok <[email protected]>
@parked-toes, @dai-chen and @anasalkouz |
Signed-off-by: Andy Kwok <[email protected]>
@dai-chen I have fixed the spotlessJavaCheck, and tested it offline. |
// It's possible to have date stored in second / millisecond form without explicit | ||
// format hint. | ||
// Parse it on a best-effort basis. |
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 you check if anything in OpenSearch's DateFormatters
can be reused?
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 dont see there is a suitable method I can call to detect and parse it on best effort basis, if we decide the use DataFormatters
, the logic will turns into following:
try {
parsedDate = Date.from(DateFormatters.from(
DateFormatter.forPattern("epoch_millis").parse(columnOriginalDate))
.toInstant());
} catch (DateTimeException ex) {
// Fallback to epoch_second
try {
parsedDate = Date.from(DateFormatters.from(
DateFormatter.forPattern("epoch_second").parse(columnOriginalDate))
.toInstant());
} catch (DateTimeException innerEx) {
parsedDate =
DateUtils.parseDate(
columnOriginalDate,
FORMAT_DOT_OPENSEARCH_DASHBOARDS_SAMPLE_DATA_LOGS_EXCEPTION,
FORMAT_DOT_OPENSEARCH_DASHBOARDS_SAMPLE_DATA_FLIGHTS_EXCEPTION,
FORMAT_DOT_OPENSEARCH_DASHBOARDS_SAMPLE_DATA_FLIGHTS_EXCEPTION_NO_TIME,
FORMAT_DOT_OPENSEARCH_DASHBOARDS_SAMPLE_DATA_ECOMMERCE_EXCEPTION,
FORMAT_DOT_DATE_AND_TIME,
FORMAT_DOT_DATE);
}
Because I need the try-catch to perform the parsing logic fallback from millisecond, second and eventually a normal date String.
Which I don't think that is ideal from the performance perspective, as this will run against every row being resulted.
@andy-k-improving It seem CI is failing on IT task. I've triggered the CI again. Please check if there is still failure. |
Signed-off-by: Andy Kwok <[email protected]>
Thanks, indeed we have a breaking change on the date field presentation on v1 engine (The old engine). |
Signed-off-by: Andy Kwok <[email protected]>
I have updated |
@dai-chen Would you mind to have another look on this? |
Description
This is a MR, which aim to fix the issue described over #1545 to align the representation of
date
field between the legacy engine and the v2 engine.Code changes highlight:
break
identifier fromDateFieldFormatter
, the current behaviour will only parse the firstdate
field from the resultSet, which is not a valid assumption, because OpenSearch as platform allow multipledate
fields co-exist on an index, also this is not an uncommon use-case for enterprise. Hence alldate
fields present on any given index should be formatted regardless of the order.epoch_millis
being explicitly specified on field format, in this particular case there is no clear hint from the query indicate this is numeric timestamp from OpenSearch.Although issue is being reported #1545 under nested-query, however this bug has wider impact outside of nested-query, and the conditions to trigger are:
date
fields are being specified on the Index schema WITHOUT any explicitformat
configuration.When this happen, the current behaviour will only parse the first
date
field from the resultset.Reference doc:
https://opensearch.org/docs/latest/field-types/supported-field-types/date/
Related Issues
Resolves #1545
Testing plan
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.