/*
 * Copyright (c) 2009.  The Apache Software Foundation
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.expreval.expr.betweenstmt;

import org.apache.expreval.client.ResultMissingColumnException;
import org.apache.expreval.expr.ExpressionType;
import org.apache.expreval.expr.node.GenericValue;
import org.apache.hadoop.hbase.hbql.client.HBqlException;
import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;

public class DateBetweenStmt extends GenericBetweenStmt {

    public DateBetweenStmt(final GenericValue expr, final boolean not, final GenericValue lower, final GenericValue upper) {
        super(ExpressionType.DATEBETWEEN, not, expr, lower, upper);
    }

    public Boolean getValue(final HConnectionImpl connection,
                            final Object object) throws HBqlException, ResultMissingColumnException {

        final long dateval = (Long)this.getExprArg(0).getValue(connection, object);
        final boolean retval = dateval >= (Long)this.getExprArg(1).getValue(connection, object)
                               && dateval <= (Long)this.getExprArg(2).getValue(connection, object);

        return (this.isNot()) ? !retval : retval;
    }
}
@@ -1090,104 +1090,509 @@
 che.
-hadoop.hbase.hbql.client.HBqlException;%0Aimport org.apache.hadoop.hbase.hbql.impl.HConnectionImpl
+expreval.expr.var.DelegateColumn;%0Aimport org.apache.expreval.expr.var.GenericColumn;%0Aimport org.apache.hadoop.hbase.filter.CompareFilter;%0Aimport org.apache.hadoop.hbase.filter.Filter;%0Aimport org.apache.hadoop.hbase.hbql.client.HBqlException;%0Aimport org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;%0Aimport org.apache.hadoop.hbase.hbql.io.IO;%0Aimport org.apache.hadoop.hbase.hbql.mapping.FieldType;%0A%0Aimport java.io.DataInput;%0Aimport java.io.DataOutput;%0Aimport java.io.IOException;%0Aimport java.util.Date
 ;%0A%0Ap
@@ -2350,10 +2350,1845 @@
 l;%0A    %7D
+%0A%0A    public Filter getFilter() throws HBqlException %7B%0A%0A        this.validateArgsForBetween();%0A%0A        final GenericColumn%3C? extends GenericValue%3E column = ((DelegateColumn)this.getExprArg(0)).getTypedColumn();%0A        final Long lowerVal = (Long)this.getConstantValue(1);%0A        final Long upperVal = (Long)this.getConstantValue(2);%0A%0A        return this.newSingleColumnValueFilter(column.getColumnAttrib(),%0A                                               CompareFilter.CompareOp.EQUAL,%0A                                               new DateComparable(lowerVal, upperVal));%0A    %7D%0A%0A    private static class DateComparable extends GenericComparable%3CLong%3E %7B%0A%0A        public DateComparable() %7B%0A        %7D%0A%0A        public DateComparable(final Long lowerValue, final Long upperValue) %7B%0A            this.setLowerValue(lowerValue);%0A            this.setUpperValue(upperValue);%0A        %7D%0A%0A        public int compareTo(final byte%5B%5D bytes) %7B%0A            try %7B%0A                Date dateValue = (Date)IO.getSerialization().getScalarFromBytes(FieldType.DateType, bytes);%0A                long val = dateValue.getTime();%0A                final long lowerVal = this.getLowerValue();%0A                final long upperVal = this.getUpperValue();%0A                return (val %3E= lowerVal && val %3C= upperVal) ? 0 : 1;%0A            %7D%0A            catch (HBqlException e) %7B%0A                e.printStackTrace();%0A                return 0;%0A            %7D%0A        %7D%0A%0A        public void write(final DataOutput dataOutput) throws IOException %7B%0A            dataOutput.writeLong(this.getLowerValue());%0A            dataOutput.writeLong(this.getUpperValue());%0A        %7D%0A%0A        public void readFields(final DataInput dataInput) throws IOException %7B%0A            this.setLowerValue(dataInput.readLong());%0A            this.setUpperValue(dataInput.readLong());%0A        %7D%0A    %7D
 %0A%7D

Support for date between server filter