Skip to content

Commit 7aad648

Browse files
author
Andras Palinkas
authored
SQL: Fix the MINUTE_OF_DAY() function that throws exception when used in comparisons (#68783) (#68854)
The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressible using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of #67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
1 parent eb850c1 commit 7aad648

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

x-pack/plugin/sql/qa/server/src/main/resources/datetime.csv-spec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ SELECT WEEK(birth_date) week, birth_date FROM test_emp WHERE WEEK(birth_date) >
153153
2 |1953-01-07T00:00:00.000Z
154154
;
155155

156+
minuteOfDayFilterEquality
157+
SELECT MINUTE_OF_DAY(CONCAT(CONCAT('2021-01-22T14:26:06.', (salary % 2)::text), 'Z')::datetime) AS min_of_day
158+
FROM test_emp WHERE min_of_day = 866 LIMIT 2;
159+
160+
min_of_day:i
161+
---------------
162+
866
163+
866
164+
;
165+
156166
selectAddWithDateTime
157167
schema::dt_year:s|dt_quarter:s|dt_month:s|dt_week:s|dt_day:s|dt_hours:s|dt_min:s|dt_sec:s|dt_millis:s|dt_mcsec:s|dt_nsec:s
158168
SELECT DATE_ADD('year', 10, '2019-09-04T11:22:33.123Z'::datetime)::string as dt_year, DATE_ADD('quarter', -10, '2019-09-04T11:22:33.123Z'::datetime)::string as dt_quarter, DATE_ADD('month', 20, '2019-09-04T11:22:33.123Z'::datetime)::string as dt_month,

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/MinuteOfDay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ protected MinuteOfDay replaceChild(Expression newChild) {
3434

3535
@Override
3636
public String dateTimeFormat() {
37-
throw new UnsupportedOperationException("is there a format for it?");
37+
return null;
3838
}
3939
}

0 commit comments

Comments
 (0)