@@ -214,22 +214,22 @@ public static Expression microsecond(DateTimeV2Literal date) {
214
214
*/
215
215
@ ExecFunction (name = "dayofyear" , argTypes = {"DATE" }, returnType = "SMALLINT" )
216
216
public static Expression dayOfYear (DateLiteral date ) {
217
- return new SmallIntLiteral ((short ) date .toJavaDateType (). getDayOfYear ());
217
+ return new SmallIntLiteral ((short ) date .getDayOfYear ());
218
218
}
219
219
220
220
@ ExecFunction (name = "dayofyear" , argTypes = {"DATETIME" }, returnType = "SMALLINT" )
221
221
public static Expression dayOfYear (DateTimeLiteral date ) {
222
- return new SmallIntLiteral ((short ) date .toJavaDateType (). getDayOfYear ());
222
+ return new SmallIntLiteral ((short ) date .getDayOfYear ());
223
223
}
224
224
225
225
@ ExecFunction (name = "dayofyear" , argTypes = {"DATEV2" }, returnType = "SMALLINT" )
226
226
public static Expression dayOfYear (DateV2Literal date ) {
227
- return new SmallIntLiteral ((short ) date .toJavaDateType (). getDayOfYear ());
227
+ return new SmallIntLiteral ((short ) date .getDayOfYear ());
228
228
}
229
229
230
230
@ ExecFunction (name = "dayofyear" , argTypes = {"DATETIMEV2" }, returnType = "SMALLINT" )
231
231
public static Expression dayOfYear (DateTimeV2Literal date ) {
232
- return new SmallIntLiteral ((short ) date .toJavaDateType (). getDayOfYear ());
232
+ return new SmallIntLiteral ((short ) date .getDayOfYear ());
233
233
}
234
234
235
235
/**
@@ -260,22 +260,22 @@ public static Expression dayOfMonth(DateTimeV2Literal date) {
260
260
*/
261
261
@ ExecFunction (name = "dayofweek" , argTypes = {"DATE" }, returnType = "TINYINT" )
262
262
public static Expression dayOfWeek (DateLiteral date ) {
263
- return new TinyIntLiteral ((byte ) (date .toJavaDateType (). getDayOfWeek (). getValue () % 7 + 1 ));
263
+ return new TinyIntLiteral ((byte ) (date .getDayOfWeek () % 7 + 1 ));
264
264
}
265
265
266
266
@ ExecFunction (name = "dayofweek" , argTypes = {"DATETIME" }, returnType = "TINYINT" )
267
267
public static Expression dayOfWeek (DateTimeLiteral date ) {
268
- return new TinyIntLiteral ((byte ) (date .toJavaDateType (). getDayOfWeek (). getValue () % 7 + 1 ));
268
+ return new TinyIntLiteral ((byte ) (date .getDayOfWeek () % 7 + 1 ));
269
269
}
270
270
271
271
@ ExecFunction (name = "dayofweek" , argTypes = {"DATEV2" }, returnType = "TINYINT" )
272
272
public static Expression dayOfWeek (DateV2Literal date ) {
273
- return new TinyIntLiteral ((byte ) (date .toJavaDateType (). getDayOfWeek (). getValue () % 7 + 1 ));
273
+ return new TinyIntLiteral ((byte ) (date .getDayOfWeek () % 7 + 1 ));
274
274
}
275
275
276
276
@ ExecFunction (name = "dayofweek" , argTypes = {"DATETIMEV2" }, returnType = "TINYINT" )
277
277
public static Expression dayOfWeek (DateTimeV2Literal date ) {
278
- return new TinyIntLiteral ((byte ) (date .toJavaDateType (). getDayOfWeek (). getValue () % 7 + 1 ));
278
+ return new TinyIntLiteral ((byte ) (date .getDayOfWeek () % 7 + 1 ));
279
279
}
280
280
281
281
private static int distanceToFirstDayOfWeek (LocalDateTime dateTime ) {
@@ -853,18 +853,53 @@ public static Expression yearWeek(LocalDateTime localDateTime, int mode) {
853
853
}
854
854
}
855
855
856
+ /**
857
+ *
858
+ * @param dateTime
859
+ * @return
860
+ */
856
861
@ ExecFunction (name = "weekofyear" , argTypes = {"DATETIMEV2" }, returnType = "TINYINT" )
857
862
public static Expression weekOfYear (DateTimeV2Literal dateTime ) {
863
+ if (dateTime .getYear () == 0 && dateTime .getDayOfWeek () == 1 ) {
864
+ if (dateTime .getMonth () == 1 && dateTime .getDay () == 2 ) {
865
+ return new TinyIntLiteral ((byte ) 1 );
866
+ }
867
+ return new TinyIntLiteral (
868
+ (byte ) (dateTime .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()) + 1 ));
869
+ }
858
870
return new TinyIntLiteral ((byte ) dateTime .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()));
859
871
}
860
872
873
+ /**
874
+ *
875
+ * @param dateTime
876
+ * @return
877
+ */
861
878
@ ExecFunction (name = "weekofyear" , argTypes = {"DATETIME" }, returnType = "TINYINT" )
862
879
public static Expression weekOfYear (DateTimeLiteral dateTime ) {
880
+ if (dateTime .getYear () == 0 && dateTime .getDayOfWeek () == 1 ) {
881
+ if (dateTime .getMonth () == 1 && dateTime .getDay () == 2 ) {
882
+ return new TinyIntLiteral ((byte ) 1 );
883
+ }
884
+ return new TinyIntLiteral (
885
+ (byte ) (dateTime .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()) + 1 ));
886
+ }
863
887
return new TinyIntLiteral ((byte ) dateTime .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()));
864
888
}
865
889
890
+ /**
891
+ *
892
+ * @param date
893
+ * @return
894
+ */
866
895
@ ExecFunction (name = "weekofyear" , argTypes = {"DATEV2" }, returnType = "TINYINT" )
867
896
public static Expression weekOfYear (DateV2Literal date ) {
897
+ if (date .getYear () == 0 && date .getDayOfWeek () == 1 ) {
898
+ if (date .getMonth () == 1 && date .getDay () == 2 ) {
899
+ return new TinyIntLiteral ((byte ) 1 );
900
+ }
901
+ return new TinyIntLiteral ((byte ) (date .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()) + 1 ));
902
+ }
868
903
return new TinyIntLiteral ((byte ) date .toJavaDateType ().get (WeekFields .ISO .weekOfWeekBasedYear ()));
869
904
}
870
905
0 commit comments