Search in sources :

Example 1 with Holder

use of org.apache.calcite.util.Holder in project calcite by apache.

the class SqlOperatorBaseTest method currentTimeString.

/**
 * Returns a time string, in GMT, that will be valid for at least 2 minutes.
 *
 * <p>For example, at "2005-01-01 12:34:56 PST", returns "2005-01-01 20:".
 * At "2005-01-01 12:34:59 PST", waits a minute, then returns "2005-01-01
 * 21:".
 *
 * @param tz Time zone
 * @return Time string
 */
protected static Pair<String, Hook.Closeable> currentTimeString(TimeZone tz) {
    final Calendar calendar;
    final Hook.Closeable closeable;
    if (CalciteAssert.ENABLE_SLOW) {
        calendar = getCalendarNotTooNear(Calendar.HOUR_OF_DAY);
        closeable = new Hook.Closeable() {

            public void close() {
            }
        };
    } else {
        calendar = Util.calendar();
        calendar.set(Calendar.YEAR, 2014);
        calendar.set(Calendar.MONTH, 8);
        calendar.set(Calendar.DATE, 7);
        calendar.set(Calendar.HOUR_OF_DAY, 17);
        calendar.set(Calendar.MINUTE, 8);
        calendar.set(Calendar.SECOND, 48);
        calendar.set(Calendar.MILLISECOND, 15);
        final long timeInMillis = calendar.getTimeInMillis();
        closeable = Hook.CURRENT_TIME.addThread(new Function<Holder<Long>, Void>() {

            public Void apply(Holder<Long> o) {
                o.set(timeInMillis);
                return null;
            }
        });
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:", Locale.ROOT);
    sdf.setTimeZone(tz);
    return Pair.of(sdf.format(calendar.getTime()), closeable);
}
Also used : Hook(org.apache.calcite.runtime.Hook) Function(com.google.common.base.Function) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction) Calendar(java.util.Calendar) Holder(org.apache.calcite.util.Holder) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Function (com.google.common.base.Function)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Hook (org.apache.calcite.runtime.Hook)1 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)1 Holder (org.apache.calcite.util.Holder)1