+1
On Dec 10, 2013 6:26 PM, "James Taylor" <notifications@github.com> wrote:

> In
> src/main/java/com/salesforce/phoenix/expression/function/CeilTimestampExpression.java:
>
> > -            tempPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
> > -            childType.coerceBytes(tempPtr, childType, child.getColumnModifier(), null);
> > -            Timestamp value = (Timestamp) childType.toObject(tempPtr);
> > -            if (value.getNanos() > 0) {
> > -                value = new Timestamp(value.getTime()+getRoundUpAmount());
> > -                byte[] b = childType.toBytes(value, child.getColumnModifier());
> > -                ptr.set(b);
> > +        // If divBy is 0 this means <time unit> or <multiplier> was null
> > +        if (divBy != 0 && children.get(0).evaluate(tuple, ptr)) {
> > +            Timestamp ts = (Timestamp)PDataType.TIMESTAMP.toObject(ptr, children.get(0).getColumnModifier());
> > +            Timestamp roundedTs;
> > +
> > +            if(divBy == 1 && ts.getNanos() > 0) {
> > +                roundedTs = new Timestamp(roundTime(ts.getTime() + 1));
> > +            } else {
> > +                roundedTs = new Timestamp(roundTime(ts.getTime()));
>
> Instead of creating a couple of extra Timestamp objects, move this as the
> first line in your if statement and just return true, like this:
>
>         if(divBy > 1) {
>             return true; // As in this case, we've already got the correct value in ptr
>         }
>
> Also, another good optimization would be to check the last four bytes
> being non zero without creating a Timestamp object. You could do this like
> this:
>
> int nanos = PDataType.INTEGER.getCodec().decodeInt(ptr.getBuffer(), ptr.getOffset()+PDataType.LONG.getMaxLength());
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/forcedotcom/phoenix/pull/623/files#r8255892>
> .
>