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
@github-actions
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually it's different because this is not just a per-row warning. It actually fails the query. Since they are static this isn't a recoverable error.

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 👀

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 idea to check with instanceof MapExpression, this seems to work fine, updated the PR

@flash1293
Copy link
Contributor Author

Should be ready for another look

@flash1293
Copy link
Contributor Author

flash1293 commented Oct 22, 2025

I've been trying to figure it out, but I can't make it work, I'm stuck. Happy to pair with someone. It seems like the failure test case builder is building a failure case where the third parameter is null, and it complains it's not rejected as unresolved. I think I have to add a test case for this so it's marked as valid, but I can't manage to - if I try something like

new TestCaseSupplier(
                    List.of(DataType.KEYWORD, DataType.KEYWORD, DataType.NULL),
                    () -> new TestCaseSupplier.TestCase(
                        List.of(
                            new TestCaseSupplier.TypedData(new BytesRef("yyyy-MM-dd"), DataType.KEYWORD, "pattern"),
                            new TestCaseSupplier.TypedData(new BytesRef("2023-05-05"), DataType.KEYWORD, "date"),
                            new TestCaseSupplier.TypedData(
                                null,
                                DataType.NULL,
                                "options"
                            )
                        ),
                        "DateParseEvaluator[val=Attribute[channel=1], formatter=Attribute[channel=0]]",
                        DataType.DATETIME,
                        equalTo(1683244800000L)
                    )
                )

it breaks really bad and I'm not sure why. I get a bit confused with the null as in Java null pointer vs. ESQL null, something's up there and I'm not even sure what the right behavior should be - do we want to allow date_parse(a, b, null) or not, and depending on the answer, how do I construct the right test cases?

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM.

Enjoy fighting CI.

type = "keyword",
valueHint = { "standard" },
description = "The locale to use when parsing the date, relevant when parsing month names or week days."
) },
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's a way we can declare this thing once and reuse it. Java annotations have such weird rules.

return list;
}

private Expression field() {
Copy link
Member

Choose a reason for hiding this comment

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

Worth a javadoc - it's the value to translate but the name field is ambiguous.

return second != null ? second : first;
}

private Expression format() {
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth a javadoc too.


private final Expression first;
private final Expression second;
private final Expression third;
Copy link
Member

Choose a reason for hiding this comment

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

It's worth leaving a comment explaining that you chose to do this naming instead of in the ctor because the first and last parameter is optional and it's just easier to do handle it this way.

children.get(0),
children.size() > 1 ? children.get(1) : null,
children.size() == 3 ? children.get(2) : null
);
Copy link
Member

Choose a reason for hiding this comment

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

That's.... fun. I don't really like it but it gets the job done. We can refine this later.

@flash1293
Copy link
Contributor Author

Test failure looks like CI instability (503), trying to rerun

@flash1293 flash1293 enabled auto-merge (squash) October 24, 2025 12:33
@flash1293 flash1293 merged commit f40259a into elastic:main Oct 24, 2025
34 checks passed
fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Nov 3, 2025
Fixes elastic#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.
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

4 participants