Skip to content

Commit 76dedf5

Browse files
committed
work 2
1 parent 38a58cd commit 76dedf5

File tree

10 files changed

+50
-22
lines changed

10 files changed

+50
-22
lines changed

docs/reference/query-languages/esql/_snippets/functions/functionNamedParams/date_parse.md

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/date_parse.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/date_parse.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/date_parse.md

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/images/functions/date_parse.svg

Lines changed: 1 addition & 1 deletion
Loading

x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,22 +644,25 @@ emp_no:integer | new_date:datetime | birth_date:datetime | bool:
644644
10050 | 1958-05-21T00:00:00.000Z | 1958-05-21T00:00:00.000Z | true
645645
;
646646

647-
evalDateParseWithTimezone
648-
row a = "10-10-25" | eval b = date_parse(a, "dd-mm-yyyy", {"time_zone":"Europe/Paris"}) | keep b;
647+
evalDateParseWithTimezoneOption
648+
required_capability: date_parse_options
649+
row a = "10-10-2025" | eval b = date_parse("dd-mm-yyyy", a, {"time_zone":"Europe/Paris"}) | keep b;
649650

650651
b:datetime
651652
2024-12-31T23:00:00.000Z
652653
;
653654

654-
evalDateParseWithLocale
655-
row a = "10 septembre 2025" | eval b = date_parse(a, "dd-mm-yyyy", {"locale":"fr"}) | keep b;
655+
evalDateParseWithLocaleOption
656+
required_capability: date_parse_options
657+
row a = "10 septembre 2025" | eval b = date_parse("dd MMMM yyyy", a, {"locale":"fr"}) | keep b;
656658

657659
b:datetime
658660
2025-09-10T00:00:00.000Z
659661
;
660662

661-
evalDateParseWithLocaleAndTimezone
662-
row a = "10 septembre 2025" | eval b = date_parse(a, "dd-mm-yyyy", {"locale":"fr","time_zone":"Europe/Paris"}) | keep b;
663+
evalDateParseWithLocaleAndTimezoneOption
664+
required_capability: date_parse_options
665+
row a = "10 septembre 2025" | eval b = date_parse("dd MMMM yyyy", a, {"locale":"fr","time_zone":"Europe/Paris"}) | keep b;
663666

664667
b:datetime
665668
2025-09-09T22:00:00.000Z

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,11 @@ public enum Cap {
15161516
*/
15171517
FIX_FILTER_ORDINALS,
15181518

1519+
/**
1520+
* Optional options argument for DATE_PARSE
1521+
*/
1522+
DATE_PARSE_OPTIONS,
1523+
15191524
;
15201525

15211526
private final boolean enabled;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,15 @@ protected static <T extends Function> FunctionDefinition def(Class<T> function,
10421042
throw new QlIllegalArgumentException("expects one, two or three arguments");
10431043
} else if (hasMinimumTwo && (children.size() > 3 || children.size() < 2)) {
10441044
throw new QlIllegalArgumentException("expects two or three arguments");
1045-
} else if (hasMinimumTwo == false && children.size() != 3) {
1045+
} else if (hasMinimumOne == false && hasMinimumTwo == false && children.size() != 3) {
10461046
throw new QlIllegalArgumentException("expects exactly three arguments");
10471047
}
1048-
return ctorRef.build(source, children.get(0), children.get(1), children.size() == 3 ? children.get(2) : null);
1048+
return ctorRef.build(
1049+
source,
1050+
children.get(0),
1051+
children.size() > 1 ? children.get(1) : null,
1052+
children.size() == 3 ? children.get(2) : null
1053+
);
10491054
};
10501055
return def(function, builder, names);
10511056
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateParse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public DateParse(
9797
valueHint = { "standard" },
9898
description = "The locale to use when parsing the date, relevant when parsing month names or week days."
9999
) },
100-
description = "(Optional) Additional options for date parsing as <<esql-function-named-params,function named parameters>>.",
100+
description = "(Optional) Additional options for date parsing, specifying time zone and locale as <<esql-function-named-params,function named parameters>>.",
101101
optional = true
102102
) Expression options
103103
) {
@@ -134,7 +134,6 @@ public void writeTo(StreamOutput out) throws IOException {
134134
out.writeNamedWriteable(children().get(0));
135135
out.writeOptionalNamedWriteable(children().size() > 1 ? children().get(1) : null);
136136
out.writeOptionalNamedWriteable(children().size() > 2 ? children().get(2) : null);
137-
out.writeOptionalNamedWriteable(children().size() > 3 ? children().get(3) : null);
138137
}
139138

140139
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateParseTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ public void testInvalidPattern() {
167167

168168
public void testInvalidLocale() {
169169
String pattern = "YYYY";
170-
String locale = "NON-EXISTING-LOCALE";
170+
String locale = "nonexistinglocale";
171171
DriverContext driverContext = driverContext();
172-
InvalidArgumentException e = expectThrows(
173-
InvalidArgumentException.class,
172+
IllegalArgumentException e = expectThrows(
173+
IllegalArgumentException.class,
174174
() -> evaluator(
175175
new DateParse(
176176
Source.EMPTY,
@@ -193,8 +193,8 @@ public void testInvalidTimezone() {
193193
String pattern = "YYYY";
194194
String timezone = "NON-EXISTING-TIMEZONE";
195195
DriverContext driverContext = driverContext();
196-
InvalidArgumentException e = expectThrows(
197-
InvalidArgumentException.class,
196+
IllegalArgumentException e = expectThrows(
197+
IllegalArgumentException.class,
198198
() -> evaluator(
199199
new DateParse(
200200
Source.EMPTY,

0 commit comments

Comments
 (0)