Skip to content

Commit 74fd5da

Browse files
authored
[fix](Nereids) time extract function constant folding core (#26292)
some time extract function changed return type in the previous PR #18369 but it is not change FE constant folding function signature. This is let them have same signature to avoid BE core.
1 parent a89477e commit 74fd5da

1 file changed

Lines changed: 70 additions & 68 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java‎

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
2828
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
2929
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
30+
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
31+
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
3032
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
3133
import org.apache.doris.nereids.types.VarcharType;
3234
import org.apache.doris.nereids.util.DateUtils;
@@ -55,132 +57,132 @@ public static Expression dateV2(DateTimeV2Literal dateTime) {
5557
/**
5658
* Executable datetime extract year
5759
*/
58-
@ExecFunction(name = "year", argTypes = {"DATE"}, returnType = "INT")
60+
@ExecFunction(name = "year", argTypes = {"DATE"}, returnType = "SMALLINT")
5961
public static Expression year(DateLiteral date) {
60-
return new IntegerLiteral(((int) date.getYear()));
62+
return new SmallIntLiteral(((short) date.getYear()));
6163
}
6264

63-
@ExecFunction(name = "year", argTypes = {"DATETIME"}, returnType = "INT")
65+
@ExecFunction(name = "year", argTypes = {"DATETIME"}, returnType = "SMALLINT")
6466
public static Expression year(DateTimeLiteral date) {
65-
return new IntegerLiteral(((int) date.getYear()));
67+
return new SmallIntLiteral(((short) date.getYear()));
6668
}
6769

68-
@ExecFunction(name = "year", argTypes = {"DATEV2"}, returnType = "INT")
70+
@ExecFunction(name = "year", argTypes = {"DATEV2"}, returnType = "SMALLINT")
6971
public static Expression year(DateV2Literal date) {
70-
return new IntegerLiteral(((int) date.getYear()));
72+
return new SmallIntLiteral(((short) date.getYear()));
7173
}
7274

73-
@ExecFunction(name = "year", argTypes = {"DATETIMEV2"}, returnType = "INT")
75+
@ExecFunction(name = "year", argTypes = {"DATETIMEV2"}, returnType = "SMALLINT")
7476
public static Expression year(DateTimeV2Literal date) {
75-
return new IntegerLiteral(((int) date.getYear()));
77+
return new SmallIntLiteral(((short) date.getYear()));
7678
}
7779

7880
/**
7981
* Executable datetime extract quarter
8082
*/
81-
@ExecFunction(name = "quarter", argTypes = {"DATE"}, returnType = "INT")
83+
@ExecFunction(name = "quarter", argTypes = {"DATE"}, returnType = "TINYINT")
8284
public static Expression quarter(DateLiteral date) {
83-
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
85+
return new TinyIntLiteral((byte) (((byte) date.getMonth() - 1) / 3 + 1));
8486
}
8587

86-
@ExecFunction(name = "quarter", argTypes = {"DATETIME"}, returnType = "INT")
88+
@ExecFunction(name = "quarter", argTypes = {"DATETIME"}, returnType = "TINYINT")
8789
public static Expression quarter(DateTimeLiteral date) {
88-
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
90+
return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1));
8991
}
9092

91-
@ExecFunction(name = "quarter", argTypes = {"DATEV2"}, returnType = "INT")
93+
@ExecFunction(name = "quarter", argTypes = {"DATEV2"}, returnType = "TINYINT")
9294
public static Expression quarter(DateV2Literal date) {
93-
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
95+
return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1));
9496
}
9597

96-
@ExecFunction(name = "quarter", argTypes = {"DATETIMEV2"}, returnType = "INT")
98+
@ExecFunction(name = "quarter", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
9799
public static Expression quarter(DateTimeV2Literal date) {
98-
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
100+
return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1));
99101
}
100102

101103
/**
102104
* Executable datetime extract month
103105
*/
104-
@ExecFunction(name = "month", argTypes = {"DATE"}, returnType = "INT")
106+
@ExecFunction(name = "month", argTypes = {"DATE"}, returnType = "TINYINT")
105107
public static Expression month(DateLiteral date) {
106-
return new IntegerLiteral(((int) date.getMonth()));
108+
return new TinyIntLiteral((byte) date.getMonth());
107109
}
108110

109-
@ExecFunction(name = "month", argTypes = {"DATETIME"}, returnType = "INT")
111+
@ExecFunction(name = "month", argTypes = {"DATETIME"}, returnType = "TINYINT")
110112
public static Expression month(DateTimeLiteral date) {
111-
return new IntegerLiteral(((int) date.getMonth()));
113+
return new TinyIntLiteral((byte) date.getMonth());
112114
}
113115

114-
@ExecFunction(name = "month", argTypes = {"DATEV2"}, returnType = "INT")
116+
@ExecFunction(name = "month", argTypes = {"DATEV2"}, returnType = "TINYINT")
115117
public static Expression month(DateV2Literal date) {
116-
return new IntegerLiteral(((int) date.getMonth()));
118+
return new TinyIntLiteral((byte) date.getMonth());
117119
}
118120

119-
@ExecFunction(name = "month", argTypes = {"DATETIMEV2"}, returnType = "INT")
121+
@ExecFunction(name = "month", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
120122
public static Expression month(DateTimeV2Literal date) {
121-
return new IntegerLiteral(((int) date.getMonth()));
123+
return new TinyIntLiteral((byte) date.getMonth());
122124
}
123125

124126
/**
125127
* Executable datetime extract day
126128
*/
127-
@ExecFunction(name = "day", argTypes = {"DATE"}, returnType = "INT")
129+
@ExecFunction(name = "day", argTypes = {"DATE"}, returnType = "TINYINT")
128130
public static Expression day(DateLiteral date) {
129-
return new IntegerLiteral(((int) date.getDay()));
131+
return new TinyIntLiteral((byte) date.getDay());
130132
}
131133

132-
@ExecFunction(name = "day", argTypes = {"DATETIME"}, returnType = "INT")
134+
@ExecFunction(name = "day", argTypes = {"DATETIME"}, returnType = "TINYINT")
133135
public static Expression day(DateTimeLiteral date) {
134-
return new IntegerLiteral(((int) date.getDay()));
136+
return new TinyIntLiteral((byte) date.getDay());
135137
}
136138

137-
@ExecFunction(name = "day", argTypes = {"DATEV2"}, returnType = "INT")
139+
@ExecFunction(name = "day", argTypes = {"DATEV2"}, returnType = "TINYINT")
138140
public static Expression day(DateV2Literal date) {
139-
return new IntegerLiteral(((int) date.getDay()));
141+
return new TinyIntLiteral((byte) date.getDay());
140142
}
141143

142-
@ExecFunction(name = "day", argTypes = {"DATETIMEV2"}, returnType = "INT")
144+
@ExecFunction(name = "day", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
143145
public static Expression day(DateTimeV2Literal date) {
144-
return new IntegerLiteral(((int) date.getDay()));
146+
return new TinyIntLiteral((byte) date.getDay());
145147
}
146148

147149
/**
148150
* Executable datetime extract hour
149151
*/
150-
@ExecFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "INT")
152+
@ExecFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "TINYINT")
151153
public static Expression hour(DateTimeLiteral date) {
152-
return new IntegerLiteral(((int) date.getHour()));
154+
return new TinyIntLiteral(((byte) date.getHour()));
153155
}
154156

155-
@ExecFunction(name = "hour", argTypes = {"DATETIMEV2"}, returnType = "INT")
157+
@ExecFunction(name = "hour", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
156158
public static Expression hour(DateTimeV2Literal date) {
157-
return new IntegerLiteral(((int) date.getHour()));
159+
return new TinyIntLiteral(((byte) date.getHour()));
158160
}
159161

160162
/**
161163
* Executable datetime extract hour
162164
*/
163-
@ExecFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "INT")
165+
@ExecFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "TINYINT")
164166
public static Expression minute(DateTimeLiteral date) {
165-
return new IntegerLiteral(((int) date.getMinute()));
167+
return new TinyIntLiteral(((byte) date.getMinute()));
166168
}
167169

168-
@ExecFunction(name = "minute", argTypes = {"DATETIMEV2"}, returnType = "INT")
170+
@ExecFunction(name = "minute", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
169171
public static Expression minute(DateTimeV2Literal date) {
170-
return new IntegerLiteral(((int) date.getMinute()));
172+
return new TinyIntLiteral(((byte) date.getMinute()));
171173
}
172174

173175
/**
174176
* Executable datetime extract second
175177
*/
176-
@ExecFunction(name = "second", argTypes = {"DATETIME"}, returnType = "INT")
178+
@ExecFunction(name = "second", argTypes = {"DATETIME"}, returnType = "TINYINT")
177179
public static Expression second(DateTimeLiteral date) {
178-
return new IntegerLiteral(((int) date.getSecond()));
180+
return new TinyIntLiteral(((byte) date.getSecond()));
179181
}
180182

181-
@ExecFunction(name = "second", argTypes = {"DATETIMEV2"}, returnType = "INT")
183+
@ExecFunction(name = "second", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
182184
public static Expression second(DateTimeV2Literal date) {
183-
return new IntegerLiteral(((int) date.getSecond()));
185+
return new TinyIntLiteral(((byte) date.getSecond()));
184186
}
185187

186188
/**
@@ -194,70 +196,70 @@ public static Expression microsecond(DateTimeV2Literal date) {
194196
/**
195197
* Executable datetime extract dayofyear
196198
*/
197-
@ExecFunction(name = "dayofyear", argTypes = {"DATE"}, returnType = "INT")
199+
@ExecFunction(name = "dayofyear", argTypes = {"DATE"}, returnType = "SMALLINT")
198200
public static Expression dayOfYear(DateLiteral date) {
199-
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
201+
return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear());
200202
}
201203

202-
@ExecFunction(name = "dayofyear", argTypes = {"DATETIME"}, returnType = "INT")
204+
@ExecFunction(name = "dayofyear", argTypes = {"DATETIME"}, returnType = "SMALLINT")
203205
public static Expression dayOfYear(DateTimeLiteral date) {
204-
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
206+
return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear());
205207
}
206208

207-
@ExecFunction(name = "dayofyear", argTypes = {"DATEV2"}, returnType = "INT")
209+
@ExecFunction(name = "dayofyear", argTypes = {"DATEV2"}, returnType = "SMALLINT")
208210
public static Expression dayOfYear(DateV2Literal date) {
209-
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
211+
return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear());
210212
}
211213

212-
@ExecFunction(name = "dayofyear", argTypes = {"DATETIMEV2"}, returnType = "INT")
214+
@ExecFunction(name = "dayofyear", argTypes = {"DATETIMEV2"}, returnType = "SMALLINT")
213215
public static Expression dayOfYear(DateTimeV2Literal date) {
214-
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
216+
return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear());
215217
}
216218

217219
/**
218220
* Executable datetime extract dayofmonth
219221
*/
220-
@ExecFunction(name = "dayofmonth", argTypes = {"DATE"}, returnType = "INT")
222+
@ExecFunction(name = "dayofmonth", argTypes = {"DATE"}, returnType = "TINYINT")
221223
public static Expression dayOfMonth(DateLiteral date) {
222-
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
224+
return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth());
223225
}
224226

225-
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIME"}, returnType = "INT")
227+
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIME"}, returnType = "TINYINT")
226228
public static Expression dayOfMonth(DateTimeLiteral date) {
227-
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
229+
return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth());
228230
}
229231

230-
@ExecFunction(name = "dayofmonth", argTypes = {"DATEV2"}, returnType = "INT")
232+
@ExecFunction(name = "dayofmonth", argTypes = {"DATEV2"}, returnType = "TINYINT")
231233
public static Expression dayOfMonth(DateV2Literal date) {
232-
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
234+
return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth());
233235
}
234236

235-
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIMEV2"}, returnType = "INT")
237+
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
236238
public static Expression dayOfMonth(DateTimeV2Literal date) {
237-
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
239+
return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth());
238240
}
239241

240242
/**
241243
* Executable datetime extract dayofweek
242244
*/
243-
@ExecFunction(name = "dayofweek", argTypes = {"DATE"}, returnType = "INT")
245+
@ExecFunction(name = "dayofweek", argTypes = {"DATE"}, returnType = "TINYINT")
244246
public static Expression dayOfWeek(DateLiteral date) {
245-
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
247+
return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1));
246248
}
247249

248-
@ExecFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "INT")
250+
@ExecFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "TINYINT")
249251
public static Expression dayOfWeek(DateTimeLiteral date) {
250-
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
252+
return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1));
251253
}
252254

253-
@ExecFunction(name = "dayofweek", argTypes = {"DATEV2"}, returnType = "INT")
255+
@ExecFunction(name = "dayofweek", argTypes = {"DATEV2"}, returnType = "TINYINT")
254256
public static Expression dayOfWeek(DateV2Literal date) {
255-
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
257+
return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1));
256258
}
257259

258-
@ExecFunction(name = "dayofweek", argTypes = {"DATETIMEV2"}, returnType = "INT")
260+
@ExecFunction(name = "dayofweek", argTypes = {"DATETIMEV2"}, returnType = "TINYINT")
259261
public static Expression dayOfWeek(DateTimeV2Literal date) {
260-
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
262+
return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1));
261263
}
262264

263265
private static int distanceToFirstDayOfWeek(LocalDateTime dateTime) {

0 commit comments

Comments
 (0)