Skip to content

Commit f40259a

Browse files
authored
ESQL: Locale and timezone argument for date_parse (#136548)
Fixes #132487 ``` POST _query { "query": """ ROW date_string="10 septembre 2025" | EVAL date = DATE_PARSE("dd MMMM yyyy", date_string, {"locale": "fr", "time_zone": "Europe/Paris" }) """ } ``` returns ``` date_string | date -----------------+------------------------ 10 septembre 2025|2025-09-09T22:00:00.000Z ``` In case the time zone or the locale can't be resolved, this throws an error.
1 parent aaa9202 commit f40259a

File tree

15 files changed

+482
-135
lines changed

15 files changed

+482
-135
lines changed

docs/changelog/136548.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 136548
2+
summary: Locale and timezone argument for `date_parse`
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 132487

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: 7 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

docs/reference/query-languages/esql/kibana/definition/functions/date_parse.json

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

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,46 @@ 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+
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;
650+
651+
b:datetime
652+
2024-12-31T23:00:00.000Z
653+
;
654+
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;
658+
659+
b:datetime
660+
2025-09-10T00:00:00.000Z
661+
;
662+
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;
666+
667+
b:datetime
668+
2025-09-09T22:00:00.000Z
669+
;
670+
671+
evalDateParseDefaultFormatWithTimezoneOption
672+
required_capability: date_parse_options
673+
row a = "2023-02-01T12:15:55.000+01:00" | eval b = date_parse(a, {"time_zone":"Europe/Paris"}) | keep b;
674+
675+
b:datetime
676+
2023-02-01T11:15:55.000Z
677+
;
678+
679+
evalDateParseDefaultFormatWithLocaleOption
680+
required_capability: date_parse_options
681+
row a = "2023-02-01T12:15:55.000Z" | eval b = date_parse(a, {"locale":"fr"}) | keep b;
682+
683+
b:datetime
684+
2023-02-01T12:15:55.000Z
685+
;
686+
647687
dateFields
648688
from employees | where emp_no == 10049 or emp_no == 10050
649689
| eval year = date_extract("year", birth_date), month = date_extract("month_of_year", birth_date), day = date_extract("day_of_month", birth_date)

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
@@ -1532,6 +1532,11 @@ public enum Cap {
15321532
*/
15331533
FIX_FILTER_ORDINALS,
15341534

1535+
/**
1536+
* Optional options argument for DATE_PARSE
1537+
*/
1538+
DATE_PARSE_OPTIONS,
1539+
15351540
/**
15361541
* Allow multiple patterns for GROK command
15371542
*/

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,12 +1042,20 @@ public interface BinaryBuilder<T> {
10421042
protected static <T extends Function> FunctionDefinition def(Class<T> function, TernaryBuilder<T> ctorRef, String... names) {
10431043
FunctionBuilder builder = (source, children, cfg) -> {
10441044
boolean hasMinimumTwo = OptionalArgument.class.isAssignableFrom(function);
1045-
if (hasMinimumTwo && (children.size() > 3 || children.size() < 2)) {
1045+
boolean hasMinimumOne = TwoOptionalArguments.class.isAssignableFrom(function);
1046+
if (hasMinimumOne && (children.size() > 3 || children.isEmpty())) {
1047+
throw new QlIllegalArgumentException("expects one, two or three arguments");
1048+
} else if (hasMinimumTwo && (children.size() > 3 || children.size() < 2)) {
10461049
throw new QlIllegalArgumentException("expects two or three arguments");
1047-
} else if (hasMinimumTwo == false && children.size() != 3) {
1050+
} else if (hasMinimumOne == false && hasMinimumTwo == false && children.size() != 3) {
10481051
throw new QlIllegalArgumentException("expects exactly three arguments");
10491052
}
1050-
return ctorRef.build(source, children.get(0), children.get(1), children.size() == 3 ? children.get(2) : null);
1053+
return ctorRef.build(
1054+
source,
1055+
children.get(0),
1056+
children.size() > 1 ? children.get(1) : null,
1057+
children.size() == 3 ? children.get(2) : null
1058+
);
10511059
};
10521060
return def(function, builder, names);
10531061
}

0 commit comments

Comments
 (0)