Skip to content

Commit f6bac9a

Browse files
committed
EXPB-2885 Fix SqlFunctions.customDateAdd
1 parent 840aff6 commit f6bac9a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4978,6 +4978,21 @@ public static int customDateAdd(DataContext root,
49784978
return timeFrameSet.addDate(date, interval, timeFrame);
49794979
}
49804980

4981+
/** SQL {@code DATEADD} function applied to a custom time frame.
4982+
*
4983+
* <p>Custom time frames are created as part of a {@link TimeFrameSet}.
4984+
* This method retrieves the session's time frame set from the
4985+
* {@link DataContext.Variable#TIME_FRAME_SET} variable, then looks up the
4986+
* time frame by name. */
4987+
public static int customDateAdd(DataContext root,
4988+
TimeUnitRange timeFrameName, int interval, int date) {
4989+
final TimeFrameSet timeFrameSet =
4990+
requireNonNull(DataContext.Variable.TIME_FRAME_SET.get(root));
4991+
final TimeFrame timeFrame = timeFrameSet.get(timeFrameName.startUnit);
4992+
return timeFrameSet.addDate(date, interval, timeFrame);
4993+
}
4994+
4995+
49814996
/** SQL {@code TIMESTAMPADD} function applied to a custom time frame.
49824997
*
49834998
* <p>Custom time frames are created and accessed as described in
@@ -4990,6 +5005,19 @@ public static long customTimestampAdd(DataContext root,
49905005
return timeFrameSet.addTimestamp(timestamp, interval, timeFrame);
49915006
}
49925007

5008+
/** SQL {@code TIMESTAMPADD} function applied to a custom time frame.
5009+
*
5010+
* <p>Custom time frames are created and accessed as described in
5011+
* {@link #customDateAdd}. */
5012+
public static long customTimestampAdd(DataContext root,
5013+
TimeUnitRange timeFrameName, long interval, long timestamp) {
5014+
final TimeFrameSet timeFrameSet =
5015+
requireNonNull(DataContext.Variable.TIME_FRAME_SET.get(root));
5016+
final TimeFrame timeFrame = timeFrameSet.get(timeFrameName.startUnit);
5017+
return timeFrameSet.addTimestamp(timestamp, interval, timeFrame);
5018+
}
5019+
5020+
49935021
/** SQL {@code DATEDIFF} function applied to a custom time frame.
49945022
*
49955023
* <p>Custom time frames are created and accessed as described in

0 commit comments

Comments
 (0)