/** * @param timeUnit - unit of time to round up to. * Creates a {@link CeilDateExpression} 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 CeilDateExpression}. */ 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 CeilDateExpression.create(expressions); }
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); String timeUnit = (String)((LiteralExpression)children.get(1)).getValue(); if(TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) { return new CeilTimestampExpression(children); } // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); return CeilDateExpression.create(newChildren); }
public static Expression getCeilExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); if(firstChildDataType.isCoercibleTo(PDate.INSTANCE)) { return CeilDateExpression.create(children); } else if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE) { return CeilTimestampExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return CeilDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }
/** * @param timeUnit - unit of time to round up to. * Creates a {@link CeilDateExpression} 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 CeilDateExpression} with default multiplier of 1. */ public static Expression create(Expression expr, TimeUnit timeUnit) throws SQLException { return create(expr, timeUnit, 1); }
@Test public void testCeilDateExpressionWithMultiplier() throws Exception { Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE); Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.SECOND, 10); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ceilDateExpression.evaluate(null, ptr); Object result = ceilDateExpression.getDataType().toObject(ptr); assertTrue(result instanceof Date); Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2012-01-01 14:25:30"), resultDate); }
@Test public void testCeilDateExpression() throws Exception { LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE); Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.DAY); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ceilDateExpression.evaluate(null, ptr); Object result = ceilDateExpression.getDataType().toObject(ptr); assertTrue(result instanceof Date); Date resultDate = (Date)result; assertEquals(DateUtil.parseDate("2012-01-02 00:00:00"), resultDate); }
/** * @param timeUnit - unit of time to round up to * @param multiplier - determines the roll up window size. * Create a {@link CeilDateExpression}. */ 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 CeilDateExpression.create(expressions); }
/** * @param timeUnit - unit of time to round up to * @param multiplier - determines the roll up window size. * Create a {@link CeilDateExpression}. */ 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 CeilDateExpression.create(expressions); }
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); String timeUnit = (String)((LiteralExpression)children.get(1)).getValue(); if(TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) { return new CeilTimestampExpression(children); } // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); return CeilDateExpression.create(newChildren); }
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); String timeUnit = (String)((LiteralExpression)children.get(1)).getValue(); if(TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) { return new CeilTimestampExpression(children); } // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); return CeilDateExpression.create(newChildren); }
public static Expression getCeilExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); if(firstChildDataType.isCoercibleTo(PDate.INSTANCE)) { return CeilDateExpression.create(children); } else if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE) { return CeilTimestampExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return CeilDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }
public static Expression getCeilExpression(List<Expression> children) throws SQLException { final Expression firstChild = children.get(0); final PDataType firstChildDataType = firstChild.getDataType(); if(firstChildDataType.isCoercibleTo(PDate.INSTANCE)) { return CeilDateExpression.create(children); } else if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE) { return CeilTimestampExpression.create(children); } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) { return CeilDecimalExpression.create(children); } else { throw TypeMismatchException.newException(firstChildDataType, "1"); } }