Skip to content

Commit

Permalink
EXPB-2885 Fix SqlFunctions.customDateAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
kramerul committed Oct 7, 2024
1 parent 840aff6 commit f6bac9a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4978,6 +4978,21 @@ public static int customDateAdd(DataContext root,
return timeFrameSet.addDate(date, interval, timeFrame);
}

/** SQL {@code DATEADD} function applied to a custom time frame.
*
* <p>Custom time frames are created as part of a {@link TimeFrameSet}.
* This method retrieves the session's time frame set from the
* {@link DataContext.Variable#TIME_FRAME_SET} variable, then looks up the
* time frame by name. */
public static int customDateAdd(DataContext root,
TimeUnitRange timeFrameName, int interval, int date) {
final TimeFrameSet timeFrameSet =
requireNonNull(DataContext.Variable.TIME_FRAME_SET.get(root));
final TimeFrame timeFrame = timeFrameSet.get(timeFrameName.startUnit);
return timeFrameSet.addDate(date, interval, timeFrame);
}


/** SQL {@code TIMESTAMPADD} function applied to a custom time frame.
*
* <p>Custom time frames are created and accessed as described in
Expand All @@ -4990,6 +5005,19 @@ public static long customTimestampAdd(DataContext root,
return timeFrameSet.addTimestamp(timestamp, interval, timeFrame);
}

/** SQL {@code TIMESTAMPADD} function applied to a custom time frame.
*
* <p>Custom time frames are created and accessed as described in
* {@link #customDateAdd}. */
public static long customTimestampAdd(DataContext root,
TimeUnitRange timeFrameName, long interval, long timestamp) {
final TimeFrameSet timeFrameSet =
requireNonNull(DataContext.Variable.TIME_FRAME_SET.get(root));
final TimeFrame timeFrame = timeFrameSet.get(timeFrameName.startUnit);
return timeFrameSet.addTimestamp(timestamp, interval, timeFrame);
}


/** SQL {@code DATEDIFF} function applied to a custom time frame.
*
* <p>Custom time frames are created and accessed as described in
Expand Down

0 comments on commit f6bac9a

Please sign in to comment.