本文整理汇总了Java中org.apache.calcite.util.Util.calendar方法的典型用法代码示例。如果您正苦于以下问题:Java Util.calendar方法的具体用法?Java Util.calendar怎么用?Java Util.calendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.util.Util
的用法示例。
在下文中一共展示了Util.calendar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SparkHandlerImpl
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Creates a SparkHandlerImpl. */
private SparkHandlerImpl() {
classServer = new HttpServer(CLASS_DIR);
// Start the classServer and store its URI in a spark system property
// (which will be passed to executors so that they can connect to it)
classServer.start();
System.setProperty("spark.repl.class.uri", classServer.uri());
// Generate a starting point for class names that is unlikely to clash with
// previous classes. A better solution would be to clear the class directory
// on startup.
final Calendar calendar = Util.calendar();
classId = new AtomicInteger(
calendar.get(Calendar.HOUR_OF_DAY) * 10000
+ calendar.get(Calendar.MINUTE) * 100
+ calendar.get(Calendar.SECOND));
}
示例2: testFilterWithCast
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1738">[CALCITE-1738]
* Push CAST of literals to Druid</a>. */
@Test public void testFilterWithCast() {
final Fixture2 f = new Fixture2();
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.JANUARY, 1);
final TimestampString from = TimestampString.fromCalendarFields(c);
c.clear();
c.set(2011, Calendar.JANUARY, 1);
final TimestampString to = TimestampString.fromCalendarFields(c);
// d >= 2010-01-01 AND d < 2011-01-01
checkDateRangeNoSimplify(f,
f.and(
f.ge(f.d, f.cast(f.timestampDataType, f.timestampLiteral(from))),
f.lt(f.d, f.cast(f.timestampDataType, f.timestampLiteral(to)))),
is("[2010-01-01T00:00:00.000Z/2011-01-01T00:00:00.000Z]"));
}
示例3: timestampValue
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private Calendar timestampValue(RexLiteral timeLiteral) {
switch (timeLiteral.getTypeName()) {
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
final TimeZone tz = TimeZone.getTimeZone(this.timeZone);
return Util.calendar(
SqlFunctions.timestampWithLocalTimeZoneToTimestamp(
timeLiteral.getValueAs(Long.class), tz));
case TIMESTAMP:
return Util.calendar(timeLiteral.getValueAs(Long.class));
case DATE:
// Cast date to timestamp with local time zone
final DateString d = timeLiteral.getValueAs(DateString.class);
return Util.calendar(d.getMillisSinceEpoch());
default:
throw Util.unexpected(timeLiteral.getTypeName());
}
}
示例4: testDateLiteral
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Tests {@link RexBuilder#makeDateLiteral(DateString)}. */
@Test public void testDateLiteral() {
final RelDataTypeFactory typeFactory =
new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
RelDataType dateType = typeFactory.createSqlType(SqlTypeName.DATE);
final RexBuilder builder = new RexBuilder(typeFactory);
// Old way: provide a Calendar
final Calendar calendar = Util.calendar();
calendar.set(1969, Calendar.JULY, 21); // one small step
calendar.set(Calendar.MILLISECOND, 0);
checkDate(builder.makeLiteral(calendar, dateType, false));
// Old way #2: Provide in Integer
checkDate(builder.makeLiteral(MOON_DAY, dateType, false));
// The new way
final DateString d = new DateString(1969, 7, 21);
checkDate(builder.makeLiteral(d, dateType, false));
}
示例5: testFloorLtRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testFloorLtRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.lt(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<($9, 2011-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.lt(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<($9, 2010-01-01 00:00:00)"));
}
示例6: testFloorLeRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testFloorLeRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.le(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<($9, 2011-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.le(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<($9, 2011-01-01 00:00:00)"));
}
示例7: testFloorGtRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testFloorGtRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.gt(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">=($9, 2011-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.gt(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">=($9, 2011-01-01 00:00:00)"));
}
示例8: testFloorGeRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testFloorGeRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.ge(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">=($9, 2011-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.ge(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">=($9, 2010-01-01 00:00:00)"));
}
示例9: testFloorExtractBothRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testFloorExtractBothRewrite() {
final Calendar c = Util.calendar();
c.clear();
Fixture2 f = new Fixture2();
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f,
f.and(f.eq(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
f.eq(f.exMonthTs, f.literal(5))),
is("AND(AND(>=($9, 2010-01-01 00:00:00), <($9, 2011-01-01 00:00:00)),"
+ " AND(>=($9, 2010-05-01 00:00:00), <($9, 2010-06-01 00:00:00)))"));
// No lower range for floor
checkDateRange(f,
f.and(f.le(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
f.eq(f.exMonthTs, f.literal(5))),
is("AND(<($9, 2011-01-01 00:00:00), =(EXTRACT(FLAG(MONTH), $9), 5))"));
// No lower range for floor
checkDateRange(f,
f.and(f.gt(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
f.eq(f.exMonthTs, f.literal(5))),
is("AND(>=($9, 2011-01-01 00:00:00), =(EXTRACT(FLAG(MONTH), $9), 5))"));
// No upper range for individual floor rexNodes, but combined results in bounded interval
checkDateRange(f,
f.and(f.le(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
f.eq(f.exMonthTs, f.literal(5)),
f.ge(f.floorYear, f.timestampLiteral(TimestampString.fromCalendarFields(c)))),
is("AND(<($9, 2011-01-01 00:00:00), AND(>=($9, 2010-05-01 00:00:00),"
+ " <($9, 2010-06-01 00:00:00)), >=($9, 2010-01-01 00:00:00))"));
}
示例10: testCeilLtRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testCeilLtRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.lt(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<=($9, 2010-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.lt(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<=($9, 2009-01-01 00:00:00)"));
}
示例11: testCeilLeRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testCeilLeRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.le(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<=($9, 2010-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.le(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is("<=($9, 2010-01-01 00:00:00)"));
}
示例12: testCeilGtRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testCeilGtRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.gt(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">($9, 2010-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.gt(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">($9, 2010-01-01 00:00:00)"));
}
示例13: testCeilGeRewrite
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Test public void testCeilGeRewrite() {
final Calendar c = Util.calendar();
c.clear();
c.set(2010, Calendar.FEBRUARY, 10, 11, 12, 05);
final Fixture2 f = new Fixture2();
checkDateRange(f, f.ge(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">($9, 2010-01-01 00:00:00)"));
c.clear();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
checkDateRange(f, f.ge(f.ceilYear, f.timestampLiteral(TimestampString.fromCalendarFields(c))),
is(">($9, 2009-01-01 00:00:00)"));
}
示例14: getCalendarNotTooNear
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/**
* Returns a Calendar that is the current time, pausing if we are within 2
* minutes of midnight or the top of the hour.
*
* @param timeUnit Time unit
* @return calendar
*/
protected static Calendar getCalendarNotTooNear(int timeUnit) {
final Calendar cal = Util.calendar();
while (true) {
cal.setTimeInMillis(System.currentTimeMillis());
try {
switch (timeUnit) {
case Calendar.DAY_OF_MONTH:
// Within two minutes of the end of the day. Wait in 10s
// increments until calendar moves into the next next day.
if ((cal.get(Calendar.HOUR_OF_DAY) == 23)
&& (cal.get(Calendar.MINUTE) >= 58)) {
Thread.sleep(10 * 1000);
continue;
}
return cal;
case Calendar.HOUR_OF_DAY:
// Within two minutes of the top of the hour. Wait in 10s
// increments until calendar moves into the next next day.
if (cal.get(Calendar.MINUTE) >= 58) {
Thread.sleep(10 * 1000);
continue;
}
return cal;
default:
throw new AssertionError("unexpected time unit: " + timeUnit);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
示例15: currentTimeString
import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/**
* 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);
}