Skip to content

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Oct 14, 2025

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.

@elasticsearchmachine elasticsearchmachine added v9.3.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Oct 14, 2025
@nik9000 nik9000 requested a review from ivancea October 15, 2025 13:19
Copy link
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

@flash1293 flash1293 marked this pull request as ready for review October 17, 2025 09:53
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Oct 17, 2025
@flash1293 flash1293 added >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL labels Oct 17, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Oct 17, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @flash1293, I've created a changelog YAML for you.

assertThat(e.getMessage(), startsWith("invalid date pattern for []: Invalid format: [" + pattern + "]"));
}

public void testInvalidLocale() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add those tests as TestCaseSuppliers in the parameters() method? They automatically execute a bunch of cases.
I'm not sure of how map parameters work there really, but if it works like other params,you would be able to just test that it returns null with a warning with the error, which is what the user would see

second = randomValueOtherThan(second, () -> randomBoolean() ? null : randomChild());
}
return new DateParse(source, first, second);
Expression options = instance.children().size() == 3 ? instance.children().get(2) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use a switch here, to only change 1 field. For example:

@Override
protected Top mutateInstance(Top instance) throws IOException {
Source source = instance.source();
Expression field = instance.field();
Expression limit = instance.limitField();
Expression order = instance.orderField();
switch (between(0, 2)) {
case 0 -> field = randomValueOtherThan(field, AbstractExpressionSerializationTests::randomChild);
case 1 -> limit = randomValueOtherThan(limit, AbstractExpressionSerializationTests::randomChild);
case 2 -> order = randomValueOtherThan(order, AbstractExpressionSerializationTests::randomChild);
}
return new Top(source, field, limit, order);
}

Expression first = randomChild();
Expression second = randomBoolean() ? null : randomChild();
return new DateParse(source, first, second);
Expression options = second != null && randomBoolean() ? randomChild() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we create the options even if "second" is null?

super(source, fields(first, second, options));
this.field = second != null ? second : first;
this.format = second != null ? first : null;
this.options = options;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This troubles me a bit. We're only allowing the options if the 2 previous parameters are present, even knowing that the format is optional too. That means, we're not allowing something like: DATE_PARSE(date, {})

However, the SVG (docs) shows it correctly.

Now, I don't know if we did something like this before, or if we should allow it. Our function overriding detection is quite manual right now, to begin with. I would like if somebody else from the team can review this first.

The worse that could happen if we ship this is that:

  • We would have incorrect docs
  • We would probably give meaningless errors, as users would expect the map parameter to "work"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call... To me both allowing DATE_PARSE(date, {}) or enforcing three params for options make sense, if we clearly communicate this to the user.

Happy for someone else to make the call.

Copy link
Contributor Author

@flash1293 flash1293 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, DATE_PARSE(date_string, {\"time_zone\": \"Europe/Paris\",\"locale\":\"fr\"}) yields

{
  "error": {
    "root_cause": [
      {
        "type": "verification_exception",
        "reason": "Found 1 problem\nline 1:51: second argument of [DATE_PARSE(date_string, {\"time_zone\": \"Europe/Paris\",\"locale\":\"fr\"})] must be [string], found value [{\"time_zone\": \"Europe/Paris\",\"locale\":\"fr\"}] type [unsupported]"
      }
    ],
    "type": "verification_exception",
    "reason": "Found 1 problem\nline 1:51: second argument of [DATE_PARSE(date_string, {\"time_zone\": \"Europe/Paris\",\"locale\":\"fr\"})] must be [string], found value [{\"time_zone\": \"Europe/Paris\",\"locale\":\"fr\"}] type [unsupported]"
  },
  "status": 400
}

right now.

Your call of course, but if you feel comfortable with this behavior, we can get it in, then follow up later with supporting a more flexible calling pattern - we are lucky that the existing behavior on this PR is a subset of what could realistically be supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with closing this as-is. I would try to follow up soon though, as to not have the wrong docs there.

Btw, I was discussing this a bit, and I think we could make a working check here. Something like:

if (options == null) {
    if (second == null) {
        // 1 parameter, it's the date
    } else {
        if (second instanceof MapExpression) {
            // Second and options params, no format
        } else {
            // First and second params, no options
        }
    }
} else {
    // 3 params available, no doubt here
}

In general, having an optional param before a required is quite weird. But this is ""historical"" already, so here we are. For this special case, I think the logic to check it shouldn't be too complex, and we can manage to do it.
If there's some weird planning error after doing it, we can check it 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESQL: Support locale and timezone setting for date parsing

3 participants