SQL: Adds MONTHNAME, DAYNAME and QUARTER functions#33411
SQL: Adds MONTHNAME, DAYNAME and QUARTER functions#33411astefan merged 9 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-search-aggs |
matriv
left a comment
There was a problem hiding this comment.
Nice work! Left some comments.
| def(MonthOfYear.class, MonthOfYear::new, "MONTH"), | ||
| def(Year.class, Year::new), | ||
| def(WeekOfYear.class, WeekOfYear::new, "WEEK"), | ||
| def(DayName.class, DayName::new, "DAYNAME"), |
There was a problem hiding this comment.
Why do we need alias here and next line?
There was a problem hiding this comment.
ah, ignore this, Checked already. It's because DayName becomes day_name.
There was a problem hiding this comment.
Should we make the class Dayname instead then? Do we want to support DAY_NAME as well as DAYNAME?
There was a problem hiding this comment.
@nik9000 I chose it like this because of consistency. There are other date/time functions that have aliases, even though the spec mentions only one name. For example WEEK (WEEK_OF_YEAR), HOUR (HOUR_OF_DAY) etc.
| throw new SqlIllegalArgumentException("A string or a date is required; received {}", l); | ||
| } | ||
| public Object doProcess(long millis) { | ||
| ReadableDateTime dt = new DateTime(millis, DateTimeZone.forTimeZone(timeZone())); |
There was a problem hiding this comment.
With the introduction of the abstract class, in case of 6.3- we already have a ReadableDateTime which we now convert to millis and then back to ReadableDateTime. Could this be a perf issue?
There was a problem hiding this comment.
Since this is operating on the data returned by the search it isn't as much of a problem as it could be. And it'll only come up during the rolling upgrade too. Since we're using the opportunity to switch from Joda time classes to Java 8 time classes I'm on board with it.
| class org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils { | ||
|
|
||
| Integer dateTimeChrono(long, String, String) | ||
| String dayName(long,String) |
There was a problem hiding this comment.
Minor: add a whitespace after comma here and below.
| assertEquals(1, proc.process("0")); | ||
| assertEquals(3, proc.process("-64164233612338")); | ||
| assertEquals(2, proc.process("64164233612338")); | ||
| } |
There was a problem hiding this comment.
Shouldn't we add nonUTC tests here as well?
|
As discussed, maybe consider to add some tests with the functions used in |
costin
left a comment
There was a problem hiding this comment.
Left some minor comments. Can you please add more integration tests with the functions in ORDER BY and HAVING?
|
|
||
| import java.util.TimeZone; | ||
|
|
||
| public abstract class BaseDateTimeFunction extends UnaryScalarFunction { |
There was a problem hiding this comment.
The class visibility could be package as the constructor.
| import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder.paramsBuilder; | ||
| import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate; | ||
|
|
||
| public abstract class NamedDateTimeFunction extends BaseDateTimeFunction { |
There was a problem hiding this comment.
Restrict class visibility to be inline with that of the constructor.
Plus javadocs.
| return timeZone; | ||
| } | ||
|
|
||
| // add tz along the rest of the params |
There was a problem hiding this comment.
I find this comment confusing, like a TODO. The intent is clear - the name has been overwritten, the method is needed.
| import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate; | ||
|
|
||
| /* | ||
| * Base class for the two "naming" date/time functions: month_name and day_name |
There was a problem hiding this comment.
To make it more "future-proof" maybe:
Base class for "naming" data/time functions like: month_namd and day-name.
* Added monthname, dayname and quarter functions * Updated docs tests with the new functions
|
6.x commit: 6832248 |
* master: Preserve cluster settings on full restart tests (elastic#33590) Use IndexWriter.getFlushingBytes() rather than tracking it ourselves (elastic#33582) Fix upgrading of list settings (elastic#33589) Add read-only Engine (elastic#33563) HLRC: Add ML get categories API (elastic#33465) SQL: Adds MONTHNAME, DAYNAME and QUARTER functions (elastic#33411) Add predicate_token_filter (elastic#33431) Fix Replace function. Adds more tests to all string functions. (elastic#33478) [ML] Rename input_fields to column_names in file structure (elastic#33568)
* master: (91 commits) Preserve cluster settings on full restart tests (elastic#33590) Use IndexWriter.getFlushingBytes() rather than tracking it ourselves (elastic#33582) Fix upgrading of list settings (elastic#33589) Add read-only Engine (elastic#33563) HLRC: Add ML get categories API (elastic#33465) SQL: Adds MONTHNAME, DAYNAME and QUARTER functions (elastic#33411) Add predicate_token_filter (elastic#33431) Fix Replace function. Adds more tests to all string functions. (elastic#33478) [ML] Rename input_fields to column_names in file structure (elastic#33568) Add full cluster restart base class (elastic#33577) Validate list values for settings (elastic#33503) Copy and validatie soft-deletes setting on resize (elastic#33517) Test: Fix package name SQL: Fix result column names for arithmetic functions (elastic#33500) Upgrade to latest Lucene snapshot (elastic#33505) Enable not wiping cluster settings after REST test (elastic#33575) MINOR: Remove Dead Code in SearchScript (elastic#33569) [Test] Remove duplicate method in TestShardRouting (elastic#32815) mute test on windows Update beats template to include apm-server metrics (elastic#33286) ...
This PR adds three functions from those listed here.