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

[Remove] Remaining Joda and Joda Dependency #10949

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Removed
- Remove deprecated classes for Rounding ([#10956](https://github.com/opensearch-project/OpenSearch/issues/10956))
- [Remove] Remaining Joda and Joda Dependency ([#10949](https://github.com/opensearch-project/OpenSearch/pull/10949))

### Fixed
- Fix failure in dissect ingest processor parsing empty brackets ([#9225](https://github.com/opensearch-project/OpenSearch/pull/9255))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

package org.opensearch.benchmark.time;

import org.opensearch.common.joda.Joda;
import org.opensearch.common.time.DateFormatter;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand All @@ -56,15 +55,9 @@
public class DateFormatterBenchmark {

private final DateFormatter javaFormatter = DateFormatter.forPattern("8year_month_day||ordinal_date||epoch_millis");
private final DateFormatter jodaFormatter = Joda.forPattern("year_month_day||ordinal_date||epoch_millis");

@Benchmark
public TemporalAccessor parseJavaDate() {
return javaFormatter.parse("1234567890");
}

@Benchmark
public TemporalAccessor parseJodaDate() {
return jodaFormatter.parse("1234567890");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ java.util.concurrent.Future#cancel(boolean)
org.opensearch.common.io.PathUtils#get(java.lang.String, java.lang.String[])
org.opensearch.common.io.PathUtils#get(java.net.URI)

@defaultMessage Constructing a DateTime without a time zone is dangerous
org.joda.time.DateTime#<init>()
org.joda.time.DateTime#<init>(long)
org.joda.time.DateTime#<init>(int, int, int, int, int)
org.joda.time.DateTime#<init>(int, int, int, int, int, int)
org.joda.time.DateTime#<init>(int, int, int, int, int, int, int)
org.joda.time.DateTime#now()
org.joda.time.DateTimeZone#getDefault()

@defaultMessage Local times may be ambiguous or nonexistent in a specific time zones. Use ZoneRules#getValidOffsets() instead.
java.time.LocalDateTime#atZone(java.time.ZoneId)
java.time.ZonedDateTime#of(int, int, int, int, int, int, int, java.time.ZoneId)
Expand Down
1 change: 0 additions & 1 deletion buildSrc/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jakarta_annotation = 1.3.5
jna = 5.13.0

netty = 4.1.100.Final
joda = 2.12.2

# project reactor
reactor_netty = 1.1.12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@
import org.opensearch.script.Script;
import org.opensearch.script.ScriptType;
import org.opensearch.search.fetch.subphase.FetchSourceContext;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;

import java.io.IOException;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1022,7 +1024,8 @@ private void validateBulkResponses(int nbItems, boolean[] errors, BulkResponse b
public void testUrlEncode() throws IOException {
String indexPattern = "<logstash-{now/M}>";
String expectedIndex = "logstash-"
+ DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(DateTimeZone.UTC).monthOfYear().roundFloorCopy());
+ DateTimeFormatter.ofPattern("uuuu.MM.dd", Locale.ROOT)
.format(ZonedDateTime.now(ZoneOffset.UTC).withDayOfMonth(1).with(LocalTime.MIN));
{
IndexRequest indexRequest = new IndexRequest(indexPattern).id("id#1");
indexRequest.source("field", "value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
package org.opensearch.script.expression;

import org.apache.lucene.search.DoubleValuesSource;
import org.opensearch.common.time.DateFormatters;
import org.opensearch.index.fielddata.IndexFieldData;
import org.opensearch.search.MultiValueMode;
import org.joda.time.ReadableDateTime;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

/**
* Expressions API for date objects (.date)
Expand Down Expand Up @@ -87,41 +90,51 @@
static DoubleValuesSource getVariable(IndexFieldData<?> fieldData, String fieldName, String variable) {
switch (variable) {
case CENTURY_OF_ERA_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getCenturyOfEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.YEAR_OF_ERA) / 100);

Check warning on line 93 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L93

Added line #L93 was not covered by tests
case DAY_OF_MONTH_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfMonth);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getDayOfMonth);

Check warning on line 95 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L95

Added line #L95 was not covered by tests
case DAY_OF_WEEK_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfWeek);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.getDayOfWeek().getValue());

Check warning on line 97 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L97

Added line #L97 was not covered by tests
case DAY_OF_YEAR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getDayOfYear);

Check warning on line 99 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L99

Added line #L99 was not covered by tests
case ERA_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.ERA));

Check warning on line 101 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L101

Added line #L101 was not covered by tests
case HOUR_OF_DAY_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getHourOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getHour);

Check warning on line 103 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L103

Added line #L103 was not covered by tests
case MILLIS_OF_DAY_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMillisOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.MILLI_OF_DAY));

Check warning on line 105 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L105

Added line #L105 was not covered by tests
case MILLIS_OF_SECOND_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMillisOfSecond);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.MILLI_OF_SECOND));

Check warning on line 107 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L107

Added line #L107 was not covered by tests
case MINUTE_OF_DAY_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMinuteOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.MINUTE_OF_DAY));

Check warning on line 109 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L109

Added line #L109 was not covered by tests
case MINUTE_OF_HOUR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMinuteOfHour);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getMinute);

Check warning on line 111 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L111

Added line #L111 was not covered by tests
case MONTH_OF_YEAR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMonthOfYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getMonthValue);

Check warning on line 113 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L113

Added line #L113 was not covered by tests
case SECOND_OF_DAY_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getSecondOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.SECOND_OF_DAY));

Check warning on line 115 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L115

Added line #L115 was not covered by tests
case SECOND_OF_MINUTE_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getSecondOfMinute);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getSecond);

Check warning on line 117 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L117

Added line #L117 was not covered by tests
case WEEK_OF_WEEK_YEAR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getWeekOfWeekyear);
return new DateObjectValueSource(

Check warning on line 119 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L119

Added line #L119 was not covered by tests
fieldData,
MultiValueMode.MIN,
variable,
zdt -> zdt.get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear())

Check warning on line 123 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L123

Added line #L123 was not covered by tests
);
case WEEK_YEAR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getWeekyear);
return new DateObjectValueSource(

Check warning on line 126 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L126

Added line #L126 was not covered by tests
fieldData,
MultiValueMode.MIN,
variable,
zdt -> zdt.get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear())

Check warning on line 130 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L130

Added line #L130 was not covered by tests
);
case YEAR_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ZonedDateTime::getYear);

Check warning on line 133 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L133

Added line #L133 was not covered by tests
case YEAR_OF_CENTURY_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYearOfCentury);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.YEAR_OF_ERA) % 100);

Check warning on line 135 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L135

Added line #L135 was not covered by tests
case YEAR_OF_ERA_VARIABLE:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYearOfEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, zdt -> zdt.get(ChronoField.YEAR_OF_ERA));

Check warning on line 137 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L137

Added line #L137 was not covered by tests
default:
throw new IllegalArgumentException(
"Member variable [" + variable + "] does not exist for date object on field [" + fieldName + "]."
Expand All @@ -132,41 +145,51 @@
static DoubleValuesSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {
switch (method) {
case GETCENTURY_OF_ERA_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getCenturyOfEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.YEAR_OF_ERA) / 100);

Check warning on line 148 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L148

Added line #L148 was not covered by tests
case GETDAY_OF_MONTH_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfMonth);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getDayOfMonth);

Check warning on line 150 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L150

Added line #L150 was not covered by tests
case GETDAY_OF_WEEK_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfWeek);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.getDayOfWeek().getValue());

Check warning on line 152 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L152

Added line #L152 was not covered by tests
case GETDAY_OF_YEAR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getDayOfYear);

Check warning on line 154 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L154

Added line #L154 was not covered by tests
case GETERA_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.ERA));

Check warning on line 156 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L156

Added line #L156 was not covered by tests
case GETHOUR_OF_DAY_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getHourOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getHour);

Check warning on line 158 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L158

Added line #L158 was not covered by tests
case GETMILLIS_OF_DAY_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMillisOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.MILLI_OF_DAY));

Check warning on line 160 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L160

Added line #L160 was not covered by tests
case GETMILLIS_OF_SECOND_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMillisOfSecond);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.MILLI_OF_SECOND));

Check warning on line 162 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L162

Added line #L162 was not covered by tests
case GETMINUTE_OF_DAY_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMinuteOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.MINUTE_OF_DAY));

Check warning on line 164 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L164

Added line #L164 was not covered by tests
case GETMINUTE_OF_HOUR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMinuteOfHour);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getMinute);

Check warning on line 166 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L166

Added line #L166 was not covered by tests
case GETMONTH_OF_YEAR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMonthOfYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getMonthValue);

Check warning on line 168 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L168

Added line #L168 was not covered by tests
case GETSECOND_OF_DAY_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getSecondOfDay);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.SECOND_OF_DAY));

Check warning on line 170 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L170

Added line #L170 was not covered by tests
case GETSECOND_OF_MINUTE_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getSecondOfMinute);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getSecond);

Check warning on line 172 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L172

Added line #L172 was not covered by tests
case GETWEEK_OF_WEEK_YEAR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getWeekOfWeekyear);
return new DateObjectValueSource(

Check warning on line 174 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L174

Added line #L174 was not covered by tests
fieldData,
MultiValueMode.MIN,
method,
zdt -> zdt.get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear())

Check warning on line 178 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L178

Added line #L178 was not covered by tests
);
case GETWEEK_YEAR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getWeekyear);
return new DateObjectValueSource(

Check warning on line 181 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L181

Added line #L181 was not covered by tests
fieldData,
MultiValueMode.MIN,
method,
zdt -> zdt.get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear())

Check warning on line 185 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L185

Added line #L185 was not covered by tests
);
case GETYEAR_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYear);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ZonedDateTime::getYear);

Check warning on line 188 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L188

Added line #L188 was not covered by tests
case GETYEAR_OF_CENTURY_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYearOfCentury);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.YEAR_OF_ERA) % 100);

Check warning on line 190 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L190

Added line #L190 was not covered by tests
case GETYEAR_OF_ERA_METHOD:
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYearOfEra);
return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, zdt -> zdt.get(ChronoField.YEAR_OF_ERA));

Check warning on line 192 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObject.java#L192

Added line #L192 was not covered by tests
default:
throw new IllegalArgumentException(
"Member method [" + method + "] does not exist for date object on field [" + fieldName + "]."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@
import org.opensearch.index.fielddata.LeafNumericFieldData;
import org.opensearch.index.fielddata.NumericDoubleValues;
import org.opensearch.search.MultiValueMode;
import org.joda.time.DateTimeZone;
import org.joda.time.MutableDateTime;
import org.joda.time.ReadableDateTime;

import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Objects;
import java.util.function.ToIntFunction;

/** Extracts a portion of a date field with joda time */
/** Extracts a portion of a date field with java time */
class DateObjectValueSource extends FieldDataValueSource {

final String methodName;
final ToIntFunction<ReadableDateTime> function;
final ToIntFunction<ZonedDateTime> function;

DateObjectValueSource(
IndexFieldData<?> indexFieldData,
MultiValueMode multiValueMode,
String methodName,
ToIntFunction<ReadableDateTime> function
ToIntFunction<ZonedDateTime> function
) {
super(indexFieldData, multiValueMode);

Expand All @@ -69,13 +69,11 @@
@Override
public DoubleValues getValues(LeafReaderContext leaf, DoubleValues scores) {
LeafNumericFieldData leafData = (LeafNumericFieldData) fieldData.load(leaf);
MutableDateTime joda = new MutableDateTime(0, DateTimeZone.UTC);
NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues());
return new DoubleValues() {
@Override
public double doubleValue() throws IOException {
joda.setMillis((long) docValues.doubleValue());
return function.applyAsInt(joda);
return function.applyAsInt(ZonedDateTime.ofInstant(Instant.ofEpochMilli((long) docValues.doubleValue()), ZoneOffset.UTC));

Check warning on line 76 in modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObjectValueSource.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-expression/src/main/java/org/opensearch/script/expression/DateObjectValueSource.java#L76

Added line #L76 was not covered by tests
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion plugins/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ dependencies {
api "com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}"
api "com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}"
api "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${versions.jackson}"
api "joda-time:joda-time:${versions.joda}"
api "org.slf4j:slf4j-api:${versions.slf4j}"

// network stack
Expand Down Expand Up @@ -129,6 +128,7 @@ test {
// this is tested explicitly in separate test tasks
exclude '**/RepositoryCredentialsTests.class'
exclude '**/S3RepositoryThirdPartyTests.class'
systemProperty 'aws.region', 'us-east-2'
nknize marked this conversation as resolved.
Show resolved Hide resolved
}

boolean useFixture = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"Verify that we can still use index with camel case date field":
- do:
bulk:
refresh: true
body:
- '{"index": {"_index": "camel_case_date_format"}}'
- '{"date_field": "2023-02-01T00:00+01:00"}'

- do:
search:
rest_total_hits_as_int: true
index: camel_case_date_format
body:
query:
range:
date_field:
gte: "2023-01-01T00:00+01:00"
lte: "2023-03-01T00:00+01:00"
Loading
Loading