forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Implement DATE_PARSE function for parsing strings into DATE valu…
…es (#57391) (#59699) Implement DATE_PARSE(<date_str>, <pattern_str>) function which allows to parse a date string according to the specified pattern into a date object. The patterns allowed are those of java.time.format.DateTimeFormatter. Closes #54962 Co-authored-by: Marios Trivyzas <matriv@users.noreply.github.com> Co-authored-by: Patrick Jiang(白泽) <dreamlike.sky@foxmail.com> (cherry picked from commit 647a413d9b21bd3938f1716bb19f8407e1334125)
- Loading branch information
Showing
14 changed files
with
349 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
.../main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/DateParse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime; | ||
|
||
import org.elasticsearch.xpack.ql.expression.Expression; | ||
import org.elasticsearch.xpack.ql.expression.function.scalar.BinaryScalarFunction; | ||
import org.elasticsearch.xpack.ql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.ql.tree.Source; | ||
import org.elasticsearch.xpack.ql.type.DataType; | ||
import org.elasticsearch.xpack.sql.type.SqlDataTypes; | ||
|
||
import java.time.ZoneId; | ||
|
||
import static org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeParseProcessor.Parser.DATE; | ||
|
||
public class DateParse extends BaseDateTimeParseFunction { | ||
|
||
public DateParse(Source source, Expression datePart, Expression timestamp, ZoneId zoneId) { | ||
super(source, datePart, timestamp, zoneId); | ||
} | ||
|
||
@Override | ||
protected DateTimeParseProcessor.Parser parser() { | ||
return DATE; | ||
} | ||
|
||
@Override | ||
protected NodeInfo.NodeCtor3<Expression, Expression, ZoneId, BaseDateTimeParseFunction> ctorForInfo() { | ||
return DateParse::new; | ||
} | ||
|
||
@Override | ||
protected BinaryScalarFunction replaceChildren(Expression timestamp, Expression pattern) { | ||
return new DateParse(source(), timestamp, pattern, zoneId()); | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return SqlDataTypes.DATE; | ||
} | ||
|
||
@Override | ||
protected String scriptMethodName() { | ||
return "dateParse"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.