Skip to content

Commit

Permalink
update according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fang-xing-esql committed Mar 19, 2024
1 parent 61b5257 commit 76909d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import static java.util.Collections.singletonList;
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
import static org.elasticsearch.xpack.esql.stats.FeatureMetric.LIMIT;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.DEFAULT_DATE_TIME_FORMATTER;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.convertDatetimeStringToLong;
import static org.elasticsearch.xpack.ql.analyzer.AnalyzerRules.resolveFunction;
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ static BytesRef process(long val, BytesRef formatter, @Fixed Locale locale) {
public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEvaluator.Factory> toEvaluator) {
var fieldEvaluator = toEvaluator.apply(field);
if (format == null) {
return dvrCtx -> new DateFormatConstantEvaluator(
source(),
fieldEvaluator.get(dvrCtx),
DEFAULT_DATE_TIME_FORMATTER,
dvrCtx
);
return dvrCtx -> new DateFormatConstantEvaluator(source(), fieldEvaluator.get(dvrCtx), DEFAULT_DATE_TIME_FORMATTER, dvrCtx);
}
if (format.dataType() != DataTypes.KEYWORD) {
throw new IllegalArgumentException("unsupported data type for format [" + format.dataType() + "]");
Expand All @@ -121,9 +116,7 @@ public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEv
}

private static DateFormatter toFormatter(Object format, Locale locale) {
DateFormatter result = format == null
? DEFAULT_DATE_TIME_FORMATTER
: DateFormatter.forPattern(((BytesRef) format).utf8ToString());
DateFormatter result = format == null ? DEFAULT_DATE_TIME_FORMATTER : DateFormatter.forPattern(((BytesRef) format).utf8ToString());
return result.withLocale(locale);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.function.Supplier;

import static java.util.Collections.emptyList;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.ESQL_DEFAULT_DATE_TIME_FORMATTER;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.DEFAULT_DATE_TIME_FORMATTER;

public class ToDatetimeTests extends AbstractFunctionTestCase {
public ToDatetimeTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
Expand Down Expand Up @@ -118,7 +118,7 @@ public static Iterable<Object[]> parameters() {
)
),
DataTypes.DATETIME,
bytesRef -> ESQL_DEFAULT_DATE_TIME_FORMATTER.parseMillis(((BytesRef) bytesRef).utf8ToString()),
bytesRef -> DEFAULT_DATE_TIME_FORMATTER.parseMillis(((BytesRef) bytesRef).utf8ToString()),
emptyList()
);
TestCaseSupplier.unary(
Expand Down

0 comments on commit 76909d8

Please sign in to comment.