/** * @param timeUnit - unit of time to round up to. * Creates a {@link FloorDateExpression} with default multiplier of 1. */ public static Expression create(Expression expr, TimeUnit timeUnit) throws SQLException { return create(expr, timeUnit, 1); }
/** * @param timeUnit - unit of time to round up to * @param multiplier - determines the roll up window size. * Create a {@link FloorDateExpression}. */ public static Expression create(Expression expr, TimeUnit timeUnit, int multiplier) throws SQLException { Expression timeUnitExpr = getTimeUnitExpr(timeUnit); Expression defaultMultiplierExpr = getMultiplierExpr(multiplier); List<Expression> expressions = Lists.newArrayList(expr, timeUnitExpr, defaultMultiplierExpr); return create(expressions); }
public static Expression getFloorExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); //FLOOR on timestamp doesn't really care about the nanos part i.e. it just sets it to zero. //Which is exactly what FloorDateExpression does too. if(firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) { return FloorDateExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return FloorDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }
@Override public Expression wrap(Expression lhs, Expression rhs, boolean rowKeyOrderOptimizable) throws SQLException { Expression e = rhs; PDataType rhsType = rhs.getDataType(); PDataType lhsType = lhs.getDataType(); if (rhsType == PDecimal.INSTANCE && lhsType != PDecimal.INSTANCE) { e = FloorDecimalExpression.create(rhs); } else if ((rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) && (lhsType != PTimestamp.INSTANCE && lhsType != PUnsignedTimestamp.INSTANCE)) { e = FloorDateExpression.create(rhs, TimeUnit.MILLISECOND); } e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength(), rowKeyOrderOptimizable); return e; }
/** * @param timeUnit - unit of time to round up to. * Creates a {@link FloorDateExpression} with default multiplier of 1. */ public static Expression create(Expression expr, TimeUnit timeUnit) throws SQLException { return create(expr, timeUnit, 1); }
/** * @param timeUnit - unit of time to round up to. * Creates a {@link FloorDateExpression} with default multiplier of 1. */ public static Expression create(Expression expr, TimeUnit timeUnit) throws SQLException { return create(expr, timeUnit, 1); }
@Test public void testFloorDateExpressionForWeek() throws Exception { Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2016-01-07 08:17:28"), PDate.INSTANCE); Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.WEEK); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); floorDateExpression.evaluate(null, ptr); Object result = floorDateExpression.getDataType().toObject(ptr); assertTrue(result instanceof Date); Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2016-01-04 00:00:00"), resultDate); } }
@Test public void testFloorDateExpression() throws Exception { LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE); Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.DAY); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); floorDateExpression.evaluate(null, ptr); Object result = floorDateExpression.getDataType().toObject(ptr); assertTrue(result instanceof Date); Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2012-01-01 00:00:00"), resultDate); }
@Test public void testFloorDateExpressionWithMultiplier() throws Exception { Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE); Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.SECOND, 10); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); floorDateExpression.evaluate(null, ptr); Object result = floorDateExpression.getDataType().toObject(ptr); assertTrue(result instanceof Date); Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2012-01-01 14:25:20"), resultDate); }
/** * @param timeUnit - unit of time to round up to * @param multiplier - determines the roll up window size. * Create a {@link FloorDateExpression}. */ public static Expression create(Expression expr, TimeUnit timeUnit, int multiplier) throws SQLException { Expression timeUnitExpr = getTimeUnitExpr(timeUnit); Expression defaultMultiplierExpr = getMultiplierExpr(multiplier); List<Expression> expressions = Lists.newArrayList(expr, timeUnitExpr, defaultMultiplierExpr); return create(expressions); }
/** * @param timeUnit - unit of time to round up to * @param multiplier - determines the roll up window size. * Create a {@link FloorDateExpression}. */ public static Expression create(Expression expr, TimeUnit timeUnit, int multiplier) throws SQLException { Expression timeUnitExpr = getTimeUnitExpr(timeUnit); Expression defaultMultiplierExpr = getMultiplierExpr(multiplier); List<Expression> expressions = Lists.newArrayList(expr, timeUnitExpr, defaultMultiplierExpr); return create(expressions); }
public static Expression getFloorExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); //FLOOR on timestamp doesn't really care about the nanos part i.e. it just sets it to zero. //Which is exactly what FloorDateExpression does too. if(firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) { return FloorDateExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return FloorDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }
public static Expression getFloorExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); //FLOOR on timestamp doesn't really care about the nanos part i.e. it just sets it to zero. //Which is exactly what FloorDateExpression does too. if(firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) { return FloorDateExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return FloorDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }
@Override public Expression wrap(Expression lhs, Expression rhs, boolean rowKeyOrderOptimizable) throws SQLException { Expression e = rhs; PDataType rhsType = rhs.getDataType(); PDataType lhsType = lhs.getDataType(); if (rhsType == PDecimal.INSTANCE && lhsType != PDecimal.INSTANCE) { e = FloorDecimalExpression.create(rhs); } else if ((rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) && (lhsType != PTimestamp.INSTANCE && lhsType != PUnsignedTimestamp.INSTANCE)) { e = FloorDateExpression.create(rhs, TimeUnit.MILLISECOND); } e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength(), rowKeyOrderOptimizable); return e; }
@Override public Expression wrap(Expression lhs, Expression rhs, boolean rowKeyOrderOptimizable) throws SQLException { Expression e = rhs; PDataType rhsType = rhs.getDataType(); PDataType lhsType = lhs.getDataType(); if (rhsType == PDecimal.INSTANCE && lhsType != PDecimal.INSTANCE) { e = FloorDecimalExpression.create(rhs); } else if ((rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) && (lhsType != PTimestamp.INSTANCE && lhsType != PUnsignedTimestamp.INSTANCE)) { e = FloorDateExpression.create(rhs, TimeUnit.MILLISECOND); } e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength(), rowKeyOrderOptimizable); return e; }