@Nonnull @Override protected Period getPeriod(int period) { return Period.days(period); }
@Override public Void visitIntervalDayConstant(IntervalDayExpression lExpr, StringBuilder sb) throws RuntimeException { sb.append("cast( '"); sb.append(Period.days(lExpr.getIntervalDay()).plusMillis(lExpr.getIntervalMillis()).toString()); sb.append("' as INTERVALDAY)"); return null; }
@Nullable @Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery query ) { final RexCall call = (RexCall) rexNode; if (call.getOperands().size() != 1) { throw new IllegalStateException("to_date() requires 1 argument, got " + call.getOperands().size()); } final String arg = DruidExpressions.toDruidExpression(call.getOperands().get(0), rowType, query); if (arg == null) { return null; } return DruidExpressions.applyTimestampFloor( arg, Period.days(1).toString(), "", timezoneId(query, call.getOperands().get(0))); } }
if (granularity.getPeriod().equals(Period.days(1))) { final TimestampFloorExprMacro.TimestampFloorExpr floorExpr = Expressions.asTimestampFloorExpr( input,
new PeriodGranularity(Period.days(1), null, plannerContext.getTimeZone()), plannerContext.getExprMacroTable() );
final TimeZone tz = timezoneId(query, call.getOperands().get(0)); return applyTimestampFormat( DruidExpressions.applyTimestampFloor(arg, Period.days(1).toString(), "", tz), YYYY_MM_DD, tz);
private static DruidExpression castCharToDateTime( final PlannerContext plannerContext, final DruidExpression operand, final SqlTypeName toType ) { // Cast strings to datetimes by parsing them from SQL format. final DruidExpression timestampExpression = DruidExpression.fromFunctionCall( "timestamp_parse", ImmutableList.of( operand, DruidExpression.fromExpression(DruidExpression.nullLiteral()), DruidExpression.fromExpression(DruidExpression.stringLiteral(plannerContext.getTimeZone().getID())) ) ); if (toType == SqlTypeName.DATE) { return TimeFloorOperatorConversion.applyTimestampFloor( timestampExpression, new PeriodGranularity(Period.days(1), null, plannerContext.getTimeZone()), plannerContext.getExprMacroTable() ); } else if (toType == SqlTypeName.TIMESTAMP) { return timestampExpression; } else { throw new ISE("Unsupported DateTime type[%s]", toType); } }
@Override public Period toPeriod(int length) { return Period.days(length); } },
ImmutableMap.of("t", now.minus(Period.days(1)).getMillis(), "dim1", "foo", "met1", 2.0),
@Test public void testTimeseriesUsingCastAsDate() throws Exception { testQuery( "SELECT SUM(cnt), dt FROM (\n" + " SELECT CAST(__time AS DATE) AS dt,\n" + " cnt FROM druid.foo\n" + ") AS x\n" + "GROUP BY dt\n" + "ORDER BY dt", ImmutableList.of( Druids.newTimeseriesQueryBuilder() .dataSource(CalciteTests.DATASOURCE1) .intervals(QSS(Filtration.eternity())) .granularity(new PeriodGranularity(Period.days(1), null, DateTimeZone.UTC)) .aggregators(AGGS(new LongSumAggregatorFactory("a0", "cnt"))) .context(TIMESERIES_CONTEXT_DEFAULT) .build() ), ImmutableList.of( new Object[]{1L, D("2000-01-01")}, new Object[]{1L, D("2000-01-02")}, new Object[]{1L, D("2000-01-03")}, new Object[]{1L, D("2001-01-01")}, new Object[]{1L, D("2001-01-02")}, new Object[]{1L, D("2001-01-03")} ) ); }
p = Period.hours(time); } else if (units.startsWith("day")) { p = Period.days(time);
public Period getDelta() { return Period.days(daysDelta).plusMinutes(minutesDelta); }
public Period getDelta() { return Period.days(daysDelta).plusMinutes(minutesDelta); }
@Override public Void visitIntervalDayConstant(IntervalDayExpression lExpr, StringBuilder sb) throws RuntimeException { sb.append("cast( '"); sb.append(Period.days(lExpr.getIntervalDay()).plusMillis(lExpr.getIntervalMillis()).toString()); sb.append("' as INTERVALDAY)"); return null; }
@Override public Void visitIntervalDayConstant(IntervalDayExpression lExpr, StringBuilder sb) throws RuntimeException { sb.append("cast( '"); sb.append(Period.days(lExpr.getIntervalDay()).plusMillis(lExpr.getIntervalMillis()).toString()); sb.append("' as INTERVALDAY)"); return null; }
@Programmatic public Period daysBetween(final int minDays, final int maxDays) { return Period.days(fake.ints().between(minDays, maxDays)); }
public void verifyLatestDateInDatePicker() { String currentDate = datePickerInput.getAttribute("value"); String yesterday = DateTimeFormat.forPattern("MMMM d, yyyy") .withLocale(Locale.ENGLISH) .print(DateTime.now().minus(Period.days(1)).withZone(DateTimeZone.UTC)); String dayBeforeYesterday = DateTimeFormat.forPattern("MMMM d, yyyy") .withLocale(Locale.ENGLISH) .print(DateTime.now().minus(Period.days(2)).withZone(DateTimeZone.UTC)); Assertion.assertTrue( yesterday.equals(currentDate) || dayBeforeYesterday.equals(currentDate), "Current date does not match yesterday or the day before" ); }
public static IntervalDaySecond interval_day(int days, int millis) { return new IntervalDaySecond(Period.days(days).plusMillis(millis)); }
@Override public void run(final MyEvent event) { if (!shouldFail) { return; } final NullPointerException exceptionForTests = new NullPointerException("Expected exception for tests"); // 4 retries throw new QueueRetryException(exceptionForTests, ImmutableList.<Period>of(Period.millis(1), Period.millis(1), Period.millis(1), Period.days(1))); } });
@Test public void testDateMinusDate() throws Exception { testBuilder() .sqlQuery("SELECT (CAST(\"datetime0\" AS DATE) - CAST({d '2004-01-01'} AS DATE)) res1 FROM (VALUES({ts '2017-01-13 01:02:03'})) tbl(datetime0)") .ordered() .baselineColumns("res1") .baselineValues(Period.days(4761)) .go(); }