hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khorg...@apache.org
Subject svn commit: r1619005 [6/9] - in /hive/trunk: ./ accumulo-handler/ accumulo-handler/src/ accumulo-handler/src/java/ accumulo-handler/src/java/org/ accumulo-handler/src/java/org/apache/ accumulo-handler/src/java/org/apache/hadoop/ accumulo-handler/src/ja...
Date Tue, 19 Aug 2014 22:41:13 GMT
Added: hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/mr/TestHiveAccumuloTypes.java
URL: http://svn.apache.org/viewvc/hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/mr/TestHiveAccumuloTypes.java?rev=1619005&view=auto
==============================================================================
--- hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/mr/TestHiveAccumuloTypes.java (added)
+++ hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/mr/TestHiveAccumuloTypes.java Tue Aug 19 22:41:10 2014
@@ -0,0 +1,826 @@
+/*
+ * 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.hadoop.hive.accumulo.mr;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.mock.MockInstance;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.accumulo.AccumuloHiveConstants;
+import org.apache.hadoop.hive.accumulo.AccumuloHiveRow;
+import org.apache.hadoop.hive.accumulo.serde.AccumuloSerDeParameters;
+import org.apache.hadoop.hive.common.type.HiveChar;
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.common.type.HiveVarchar;
+import org.apache.hadoop.hive.serde.serdeConstants;
+import org.apache.hadoop.hive.serde2.ByteStream;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef;
+import org.apache.hadoop.hive.serde2.lazy.LazyBoolean;
+import org.apache.hadoop.hive.serde2.lazy.LazyByte;
+import org.apache.hadoop.hive.serde2.lazy.LazyDate;
+import org.apache.hadoop.hive.serde2.lazy.LazyDouble;
+import org.apache.hadoop.hive.serde2.lazy.LazyFactory;
+import org.apache.hadoop.hive.serde2.lazy.LazyFloat;
+import org.apache.hadoop.hive.serde2.lazy.LazyHiveChar;
+import org.apache.hadoop.hive.serde2.lazy.LazyHiveDecimal;
+import org.apache.hadoop.hive.serde2.lazy.LazyHiveVarchar;
+import org.apache.hadoop.hive.serde2.lazy.LazyInteger;
+import org.apache.hadoop.hive.serde2.lazy.LazyLong;
+import org.apache.hadoop.hive.serde2.lazy.LazyShort;
+import org.apache.hadoop.hive.serde2.lazy.LazyString;
+import org.apache.hadoop.hive.serde2.lazy.LazyTimestamp;
+import org.apache.hadoop.hive.serde2.lazy.LazyUtils;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyBooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyByteObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyDateObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyDoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyFloatObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveCharObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveDecimalObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyHiveVarcharObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyIntObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyLongObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyPrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyShortObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyStringObjectInspector;
+import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyTimestampObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaBooleanObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaByteObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaDateObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaDoubleObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaFloatObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveCharObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveDecimalObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveVarcharObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaIntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaLongObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaShortObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaStringObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaTimestampObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.FileInputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.RecordReader;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+/**
+ *
+ */
+public class TestHiveAccumuloTypes {
+
+  @Rule
+  public TestName test = new TestName();
+
+  @Test
+  public void testBinaryTypes() throws Exception {
+    final String tableName = test.getMethodName(), user = "root", pass = "";
+
+    MockInstance mockInstance = new MockInstance(test.getMethodName());
+    Connector conn = mockInstance.getConnector(user, new PasswordToken(pass));
+    HiveAccumuloTableInputFormat inputformat = new HiveAccumuloTableInputFormat();
+    JobConf conf = new JobConf();
+
+    conf.set(AccumuloSerDeParameters.TABLE_NAME, tableName);
+    conf.set(AccumuloSerDeParameters.USE_MOCK_INSTANCE, "true");
+    conf.set(AccumuloSerDeParameters.INSTANCE_NAME, test.getMethodName());
+    conf.set(AccumuloSerDeParameters.USER_NAME, user);
+    conf.set(AccumuloSerDeParameters.USER_PASS, pass);
+    conf.set(AccumuloSerDeParameters.ZOOKEEPERS, "localhost:2181"); // not used for mock, but
+                                                                    // required by input format.
+
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, AccumuloHiveConstants.ROWID
+        + ",cf:string,cf:boolean,cf:tinyint,cf:smallint,cf:int,cf:bigint"
+        + ",cf:float,cf:double,cf:decimal,cf:date,cf:timestamp,cf:char,cf:varchar");
+    conf.set(
+        serdeConstants.LIST_COLUMNS,
+        "string,string,boolean,tinyint,smallint,int,bigint,float,double,decimal,date,timestamp,char(4),varchar(7)");
+    conf.set(
+        serdeConstants.LIST_COLUMN_TYPES,
+        "string,string,boolean,tinyint,smallint,int,bigint,float,double,decimal,date,timestamp,char(4),varchar(7)");
+    conf.set(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE, "binary");
+
+    conn.tableOperations().create(tableName);
+    BatchWriterConfig writerConf = new BatchWriterConfig();
+    BatchWriter writer = conn.createBatchWriter(tableName, writerConf);
+
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    DataOutputStream out = new DataOutputStream(baos);
+
+    String cf = "cf";
+    byte[] cfBytes = cf.getBytes();
+
+    Mutation m = new Mutation("row1");
+
+    // string
+    String stringValue = "string";
+    JavaStringObjectInspector stringOI = (JavaStringObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.STRING_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, stringOI.create(stringValue), stringOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "string".getBytes(), baos.toByteArray());
+
+    // boolean
+    boolean booleanValue = true;
+    baos.reset();
+    JavaBooleanObjectInspector booleanOI = (JavaBooleanObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BOOLEAN_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, booleanOI.create(booleanValue), booleanOI);
+    m.put(cfBytes, "boolean".getBytes(), baos.toByteArray());
+
+    // tinyint
+    byte tinyintValue = -127;
+    baos.reset();
+    JavaByteObjectInspector byteOI = (JavaByteObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TINYINT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, tinyintValue, byteOI);
+    m.put(cfBytes, "tinyint".getBytes(), baos.toByteArray());
+
+    // smallint
+    short smallintValue = Short.MAX_VALUE;
+    baos.reset();
+    JavaShortObjectInspector shortOI = (JavaShortObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.SMALLINT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, smallintValue, shortOI);
+    m.put(cfBytes, "smallint".getBytes(), baos.toByteArray());
+
+    // int
+    int intValue = Integer.MAX_VALUE;
+    baos.reset();
+    JavaIntObjectInspector intOI = (JavaIntObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.INT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, intValue, intOI);
+    m.put(cfBytes, "int".getBytes(), baos.toByteArray());
+
+    // bigint
+    long bigintValue = Long.MAX_VALUE;
+    baos.reset();
+    JavaLongObjectInspector longOI = (JavaLongObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BIGINT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, bigintValue, longOI);
+    m.put(cfBytes, "bigint".getBytes(), baos.toByteArray());
+
+    // float
+    float floatValue = Float.MAX_VALUE;
+    baos.reset();
+    JavaFloatObjectInspector floatOI = (JavaFloatObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.FLOAT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, floatValue, floatOI);
+    m.put(cfBytes, "float".getBytes(), baos.toByteArray());
+
+    // double
+    double doubleValue = Double.MAX_VALUE;
+    baos.reset();
+    JavaDoubleObjectInspector doubleOI = (JavaDoubleObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.DOUBLE_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, doubleValue, doubleOI);
+    m.put(cfBytes, "double".getBytes(), baos.toByteArray());
+
+    // decimal
+    baos.reset();
+    HiveDecimal decimalValue = HiveDecimal.create(65536l);
+    HiveDecimalWritable decimalWritable = new HiveDecimalWritable(decimalValue);
+    decimalWritable.write(out);
+    m.put(cfBytes, "decimal".getBytes(), baos.toByteArray());
+
+    // date
+    baos.reset();
+    Date now = new Date(System.currentTimeMillis());
+    DateWritable dateWritable = new DateWritable(now);
+    Date dateValue = dateWritable.get();
+    dateWritable.write(out);
+    m.put(cfBytes, "date".getBytes(), baos.toByteArray());
+
+    // tiemestamp
+    baos.reset();
+    Timestamp timestampValue = new Timestamp(now.getTime());
+    ByteStream.Output output = new ByteStream.Output();
+    TimestampWritable timestampWritable = new TimestampWritable(new Timestamp(now.getTime()));
+    timestampWritable.write(output);
+    output.close();
+    m.put(cfBytes, "timestamp".getBytes(), output.toByteArray());
+
+    // char
+    baos.reset();
+    HiveChar charValue = new HiveChar("char", 4);
+    JavaHiveCharObjectInspector charOI = (JavaHiveCharObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(new CharTypeInfo(4));
+    LazyUtils.writePrimitiveUTF8(baos, charOI.create(charValue), charOI, false, (byte) 0, null);
+    m.put(cfBytes, "char".getBytes(), baos.toByteArray());
+
+    baos.reset();
+    HiveVarchar varcharValue = new HiveVarchar("varchar", 7);
+    JavaHiveVarcharObjectInspector varcharOI = (JavaHiveVarcharObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(new VarcharTypeInfo(7));
+    LazyUtils.writePrimitiveUTF8(baos, varcharOI.create(varcharValue), varcharOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "varchar".getBytes(), baos.toByteArray());
+
+    writer.addMutation(m);
+
+    writer.close();
+
+    for (Entry<Key,Value> e : conn.createScanner(tableName, new Authorizations())) {
+      System.out.println(e);
+    }
+
+    // Create the RecordReader
+    FileInputFormat.addInputPath(conf, new Path("unused"));
+    InputSplit[] splits = inputformat.getSplits(conf, 0);
+    assertEquals(splits.length, 1);
+    RecordReader<Text,AccumuloHiveRow> reader = inputformat.getRecordReader(splits[0], conf, null);
+
+    Text key = reader.createKey();
+    AccumuloHiveRow value = reader.createValue();
+
+    reader.next(key, value);
+
+    Assert.assertEquals(13, value.getTuples().size());
+
+    ByteArrayRef byteRef = new ByteArrayRef();
+
+    // string
+    Text cfText = new Text(cf), cqHolder = new Text();
+    cqHolder.set("string");
+    byte[] valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyStringObjectInspector lazyStringOI = LazyPrimitiveObjectInspectorFactory
+        .getLazyStringObjectInspector(false, (byte) 0);
+    LazyString lazyString = (LazyString) LazyFactory.createLazyObject(lazyStringOI);
+    lazyString.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(stringValue, lazyString.getWritableObject().toString());
+
+    // boolean
+    cqHolder.set("boolean");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyBooleanObjectInspector lazyBooleanOI = (LazyBooleanObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BOOLEAN_TYPE_NAME));
+    LazyBoolean lazyBoolean = (LazyBoolean) LazyFactory
+        .createLazyPrimitiveBinaryClass(lazyBooleanOI);
+    lazyBoolean.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(booleanValue, lazyBoolean.getWritableObject().get());
+
+    // tinyint
+    cqHolder.set("tinyint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyByteObjectInspector lazyByteOI = (LazyByteObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TINYINT_TYPE_NAME));
+    LazyByte lazyByte = (LazyByte) LazyFactory.createLazyPrimitiveBinaryClass(lazyByteOI);
+    lazyByte.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(tinyintValue, lazyByte.getWritableObject().get());
+
+    // smallint
+    cqHolder.set("smallint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyShortObjectInspector lazyShortOI = (LazyShortObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.SMALLINT_TYPE_NAME));
+    LazyShort lazyShort = (LazyShort) LazyFactory.createLazyPrimitiveBinaryClass(lazyShortOI);
+    lazyShort.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(smallintValue, lazyShort.getWritableObject().get());
+
+    // int
+    cqHolder.set("int");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyIntObjectInspector lazyIntOI = (LazyIntObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory.getPrimitiveTypeInfo(serdeConstants.INT_TYPE_NAME));
+    LazyInteger lazyInt = (LazyInteger) LazyFactory.createLazyPrimitiveBinaryClass(lazyIntOI);
+    lazyInt.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(intValue, lazyInt.getWritableObject().get());
+
+    // bigint
+    cqHolder.set("bigint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyLongObjectInspector lazyLongOI = (LazyLongObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BIGINT_TYPE_NAME));
+    LazyLong lazyLong = (LazyLong) LazyFactory.createLazyPrimitiveBinaryClass(lazyLongOI);
+    lazyLong.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(bigintValue, lazyLong.getWritableObject().get());
+
+    // float
+    cqHolder.set("float");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyFloatObjectInspector lazyFloatOI = (LazyFloatObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.FLOAT_TYPE_NAME));
+    LazyFloat lazyFloat = (LazyFloat) LazyFactory.createLazyPrimitiveBinaryClass(lazyFloatOI);
+    lazyFloat.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(floatValue, lazyFloat.getWritableObject().get(), 0);
+
+    // double
+    cqHolder.set("double");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyDoubleObjectInspector lazyDoubleOI = (LazyDoubleObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.DOUBLE_TYPE_NAME));
+    LazyDouble lazyDouble = (LazyDouble) LazyFactory.createLazyPrimitiveBinaryClass(lazyDoubleOI);
+    lazyDouble.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(doubleValue, lazyDouble.getWritableObject().get(), 0);
+
+    // decimal
+    cqHolder.set("decimal");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    ByteArrayInputStream bais = new ByteArrayInputStream(valueBytes);
+    DataInputStream in = new DataInputStream(bais);
+    decimalWritable.readFields(in);
+
+    Assert.assertEquals(decimalValue, decimalWritable.getHiveDecimal());
+
+    // date
+    cqHolder.set("date");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    bais = new ByteArrayInputStream(valueBytes);
+    in = new DataInputStream(bais);
+    dateWritable.readFields(in);
+
+    Assert.assertEquals(dateValue, dateWritable.get());
+
+    // timestamp
+    cqHolder.set("timestamp");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    bais = new ByteArrayInputStream(valueBytes);
+    in = new DataInputStream(bais);
+    timestampWritable.readFields(in);
+
+    Assert.assertEquals(timestampValue, timestampWritable.getTimestamp());
+
+    // char
+    cqHolder.set("char");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyHiveCharObjectInspector lazyCharOI = (LazyHiveCharObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(new CharTypeInfo(4));
+    LazyHiveChar lazyChar = (LazyHiveChar) LazyFactory.createLazyObject(lazyCharOI);
+    lazyChar.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(charValue, lazyChar.getWritableObject().getHiveChar());
+
+    // varchar
+    cqHolder.set("varchar");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyHiveVarcharObjectInspector lazyVarcharOI = (LazyHiveVarcharObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(new VarcharTypeInfo(7));
+    LazyHiveVarchar lazyVarchar = (LazyHiveVarchar) LazyFactory.createLazyObject(lazyVarcharOI);
+    lazyVarchar.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(varcharValue.toString(), lazyVarchar.getWritableObject().getHiveVarchar()
+        .toString());
+  }
+
+  @Test
+  public void testUtf8Types() throws Exception {
+    final String tableName = test.getMethodName(), user = "root", pass = "";
+
+    MockInstance mockInstance = new MockInstance(test.getMethodName());
+    Connector conn = mockInstance.getConnector(user, new PasswordToken(pass));
+    HiveAccumuloTableInputFormat inputformat = new HiveAccumuloTableInputFormat();
+    JobConf conf = new JobConf();
+
+    conf.set(AccumuloSerDeParameters.TABLE_NAME, tableName);
+    conf.set(AccumuloSerDeParameters.USE_MOCK_INSTANCE, "true");
+    conf.set(AccumuloSerDeParameters.INSTANCE_NAME, test.getMethodName());
+    conf.set(AccumuloSerDeParameters.USER_NAME, user);
+    conf.set(AccumuloSerDeParameters.USER_PASS, pass);
+    conf.set(AccumuloSerDeParameters.ZOOKEEPERS, "localhost:2181"); // not used for mock, but
+                                                                    // required by input format.
+
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, AccumuloHiveConstants.ROWID
+        + ",cf:string,cf:boolean,cf:tinyint,cf:smallint,cf:int,cf:bigint"
+        + ",cf:float,cf:double,cf:decimal,cf:date,cf:timestamp,cf:char,cf:varchar");
+    conf.set(
+        serdeConstants.LIST_COLUMNS,
+        "string,string,boolean,tinyint,smallint,int,bigint,float,double,decimal,date,timestamp,char(4),varchar(7)");
+    conf.set(
+        serdeConstants.LIST_COLUMN_TYPES,
+        "string,string,boolean,tinyint,smallint,int,bigint,float,double,decimal,date,timestamp,char(4),varchar(7)");
+
+    conn.tableOperations().create(tableName);
+    BatchWriterConfig writerConf = new BatchWriterConfig();
+    BatchWriter writer = conn.createBatchWriter(tableName, writerConf);
+
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+    String cf = "cf";
+    byte[] cfBytes = cf.getBytes();
+    ByteArrayRef byteRef = new ByteArrayRef();
+
+    Mutation m = new Mutation("row1");
+
+    // string
+    String stringValue = "string";
+    baos.reset();
+    JavaStringObjectInspector stringOI = (JavaStringObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.STRING_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, stringOI.create(stringValue), stringOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "string".getBytes(), baos.toByteArray());
+
+    // boolean
+    boolean booleanValue = true;
+    baos.reset();
+    JavaBooleanObjectInspector booleanOI = (JavaBooleanObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BOOLEAN_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, booleanOI.create(booleanValue), booleanOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "boolean".getBytes(), baos.toByteArray());
+
+    // tinyint
+    byte tinyintValue = -127;
+    baos.reset();
+    JavaByteObjectInspector byteOI = (JavaByteObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TINYINT_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, tinyintValue, byteOI, false, (byte) 0, null);
+    m.put(cfBytes, "tinyint".getBytes(), baos.toByteArray());
+
+    // smallint
+    short smallintValue = Short.MAX_VALUE;
+    baos.reset();
+    JavaShortObjectInspector shortOI = (JavaShortObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.SMALLINT_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, smallintValue, shortOI, false, (byte) 0, null);
+    m.put(cfBytes, "smallint".getBytes(), baos.toByteArray());
+
+    // int
+    int intValue = Integer.MAX_VALUE;
+    baos.reset();
+    JavaIntObjectInspector intOI = (JavaIntObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.INT_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, intValue, intOI, false, (byte) 0, null);
+    m.put(cfBytes, "int".getBytes(), baos.toByteArray());
+
+    // bigint
+    long bigintValue = Long.MAX_VALUE;
+    baos.reset();
+    JavaLongObjectInspector longOI = (JavaLongObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BIGINT_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, bigintValue, longOI, false, (byte) 0, null);
+    m.put(cfBytes, "bigint".getBytes(), baos.toByteArray());
+
+    // float
+    float floatValue = Float.MAX_VALUE;
+    baos.reset();
+    JavaFloatObjectInspector floatOI = (JavaFloatObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.FLOAT_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, floatValue, floatOI, false, (byte) 0, null);
+    m.put(cfBytes, "float".getBytes(), baos.toByteArray());
+
+    // double
+    double doubleValue = Double.MAX_VALUE;
+    baos.reset();
+    JavaDoubleObjectInspector doubleOI = (JavaDoubleObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.DOUBLE_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, doubleValue, doubleOI, false, (byte) 0, null);
+    m.put(cfBytes, "double".getBytes(), baos.toByteArray());
+
+    // decimal
+    HiveDecimal decimalValue = HiveDecimal.create("1.23");
+    baos.reset();
+    JavaHiveDecimalObjectInspector decimalOI = (JavaHiveDecimalObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(new DecimalTypeInfo(5, 2));
+    LazyUtils.writePrimitiveUTF8(baos, decimalOI.create(decimalValue), decimalOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "decimal".getBytes(), baos.toByteArray());
+
+    // date
+    Date now = new Date(System.currentTimeMillis());
+    DateWritable dateWritable = new DateWritable(now);
+    Date dateValue = dateWritable.get();
+    baos.reset();
+    JavaDateObjectInspector dateOI = (JavaDateObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.DATE_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, dateOI.create(dateValue), dateOI, false, (byte) 0, null);
+    m.put(cfBytes, "date".getBytes(), baos.toByteArray());
+
+    // timestamp
+    Timestamp timestampValue = new Timestamp(now.getTime());
+    baos.reset();
+    JavaTimestampObjectInspector timestampOI = (JavaTimestampObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TIMESTAMP_TYPE_NAME));
+    LazyUtils.writePrimitiveUTF8(baos, timestampOI.create(timestampValue), timestampOI, false,
+        (byte) 0, null);
+    m.put(cfBytes, "timestamp".getBytes(), baos.toByteArray());
+
+    // char
+    baos.reset();
+    HiveChar charValue = new HiveChar("char", 4);
+    JavaHiveCharObjectInspector charOI = (JavaHiveCharObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(new CharTypeInfo(4));
+    LazyUtils.writePrimitiveUTF8(baos, charOI.create(charValue), charOI, false, (byte) 0, null);
+    m.put(cfBytes, "char".getBytes(), baos.toByteArray());
+
+    // varchar
+    baos.reset();
+    HiveVarchar varcharValue = new HiveVarchar("varchar", 7);
+    JavaHiveVarcharObjectInspector varcharOI = (JavaHiveVarcharObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(new VarcharTypeInfo(7));
+    LazyUtils.writePrimitiveUTF8(baos, varcharOI.create(varcharValue), varcharOI, false, (byte) 0,
+        null);
+    m.put(cfBytes, "varchar".getBytes(), baos.toByteArray());
+
+    writer.addMutation(m);
+
+    writer.close();
+
+    for (Entry<Key,Value> e : conn.createScanner(tableName, new Authorizations())) {
+      System.out.println(e);
+    }
+
+    // Create the RecordReader
+    FileInputFormat.addInputPath(conf, new Path("unused"));
+    InputSplit[] splits = inputformat.getSplits(conf, 0);
+    assertEquals(splits.length, 1);
+    RecordReader<Text,AccumuloHiveRow> reader = inputformat.getRecordReader(splits[0], conf, null);
+
+    Text key = reader.createKey();
+    AccumuloHiveRow value = reader.createValue();
+
+    reader.next(key, value);
+
+    Assert.assertEquals(13, value.getTuples().size());
+
+    // string
+    Text cfText = new Text(cf), cqHolder = new Text();
+    cqHolder.set("string");
+    byte[] valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyStringObjectInspector lazyStringOI = LazyPrimitiveObjectInspectorFactory
+        .getLazyStringObjectInspector(false, (byte) 0);
+    LazyString lazyString = (LazyString) LazyFactory.createLazyObject(lazyStringOI);
+    lazyString.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(new Text(stringValue), lazyString.getWritableObject());
+
+    // boolean
+    cqHolder.set("boolean");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyBooleanObjectInspector lazyBooleanOI = (LazyBooleanObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BOOLEAN_TYPE_NAME));
+    LazyBoolean lazyBoolean = (LazyBoolean) LazyFactory.createLazyObject(lazyBooleanOI);
+    lazyBoolean.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(booleanValue, lazyBoolean.getWritableObject().get());
+
+    // tinyint
+    cqHolder.set("tinyint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyByteObjectInspector lazyByteOI = (LazyByteObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TINYINT_TYPE_NAME));
+    LazyByte lazyByte = (LazyByte) LazyFactory.createLazyObject(lazyByteOI);
+    lazyByte.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(tinyintValue, lazyByte.getWritableObject().get());
+
+    // smallint
+    cqHolder.set("smallint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyShortObjectInspector lazyShortOI = (LazyShortObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.SMALLINT_TYPE_NAME));
+    LazyShort lazyShort = (LazyShort) LazyFactory.createLazyObject(lazyShortOI);
+    lazyShort.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(smallintValue, lazyShort.getWritableObject().get());
+
+    // int
+    cqHolder.set("int");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyIntObjectInspector lazyIntOI = (LazyIntObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory.getPrimitiveTypeInfo(serdeConstants.INT_TYPE_NAME));
+    LazyInteger lazyInt = (LazyInteger) LazyFactory.createLazyObject(lazyIntOI);
+    lazyInt.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(intValue, lazyInt.getWritableObject().get());
+
+    // bigint
+    cqHolder.set("bigint");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyLongObjectInspector lazyLongOI = (LazyLongObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.BIGINT_TYPE_NAME));
+    LazyLong lazyLong = (LazyLong) LazyFactory.createLazyObject(lazyLongOI);
+    lazyLong.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(bigintValue, lazyLong.getWritableObject().get());
+
+    // float
+    cqHolder.set("float");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyFloatObjectInspector lazyFloatOI = (LazyFloatObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.FLOAT_TYPE_NAME));
+    LazyFloat lazyFloat = (LazyFloat) LazyFactory.createLazyObject(lazyFloatOI);
+    lazyFloat.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(floatValue, lazyFloat.getWritableObject().get(), 0);
+
+    // double
+    cqHolder.set("double");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyDoubleObjectInspector lazyDoubleOI = (LazyDoubleObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.DOUBLE_TYPE_NAME));
+    LazyDouble lazyDouble = (LazyDouble) LazyFactory.createLazyObject(lazyDoubleOI);
+    lazyDouble.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(doubleValue, lazyDouble.getWritableObject().get(), 0);
+
+    // decimal
+    cqHolder.set("decimal");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyHiveDecimalObjectInspector lazyDecimalOI = (LazyHiveDecimalObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(new DecimalTypeInfo(5, 2));
+    LazyHiveDecimal lazyDecimal = (LazyHiveDecimal) LazyFactory.createLazyObject(lazyDecimalOI);
+    lazyDecimal.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(decimalValue, lazyDecimal.getWritableObject().getHiveDecimal());
+
+    // date
+    cqHolder.set("date");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyDateObjectInspector lazyDateOI = (LazyDateObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory.getPrimitiveTypeInfo(serdeConstants.DATE_TYPE_NAME));
+    LazyDate lazyDate = (LazyDate) LazyFactory.createLazyObject(lazyDateOI);
+    lazyDate.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(dateValue, lazyDate.getWritableObject().get());
+
+    // timestamp
+    cqHolder.set("timestamp");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyTimestampObjectInspector lazyTimestampOI = (LazyTimestampObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.TIMESTAMP_TYPE_NAME));
+    LazyTimestamp lazyTimestamp = (LazyTimestamp) LazyFactory.createLazyObject(lazyTimestampOI);
+    lazyTimestamp.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(timestampValue, lazyTimestamp.getWritableObject().getTimestamp());
+
+    // char
+    cqHolder.set("char");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyHiveCharObjectInspector lazyCharOI = (LazyHiveCharObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(new CharTypeInfo(4));
+    LazyHiveChar lazyChar = (LazyHiveChar) LazyFactory.createLazyObject(lazyCharOI);
+    lazyChar.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(charValue, lazyChar.getWritableObject().getHiveChar());
+
+    // varchar
+    cqHolder.set("varchar");
+    valueBytes = value.getValue(cfText, cqHolder);
+    Assert.assertNotNull(valueBytes);
+
+    byteRef.setData(valueBytes);
+    LazyHiveVarcharObjectInspector lazyVarcharOI = (LazyHiveVarcharObjectInspector) LazyPrimitiveObjectInspectorFactory
+        .getLazyObjectInspector(new VarcharTypeInfo(7));
+    LazyHiveVarchar lazyVarchar = (LazyHiveVarchar) LazyFactory.createLazyObject(lazyVarcharOI);
+    lazyVarchar.init(byteRef, 0, valueBytes.length);
+
+    Assert.assertEquals(varcharValue.toString(), lazyVarchar.getWritableObject().getHiveVarchar()
+        .toString());
+  }
+}

Added: hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/predicate/TestAccumuloPredicateHandler.java
URL: http://svn.apache.org/viewvc/hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/predicate/TestAccumuloPredicateHandler.java?rev=1619005&view=auto
==============================================================================
--- hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/predicate/TestAccumuloPredicateHandler.java (added)
+++ hive/trunk/accumulo-handler/src/test/org/apache/hadoop/hive/accumulo/predicate/TestAccumuloPredicateHandler.java Tue Aug 19 22:41:10 2014
@@ -0,0 +1,809 @@
+package org.apache.hadoop.hive.accumulo.predicate;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.hadoop.hive.accumulo.columns.ColumnEncoding;
+import org.apache.hadoop.hive.accumulo.columns.ColumnMapper;
+import org.apache.hadoop.hive.accumulo.predicate.compare.CompareOp;
+import org.apache.hadoop.hive.accumulo.predicate.compare.DoubleCompare;
+import org.apache.hadoop.hive.accumulo.predicate.compare.Equal;
+import org.apache.hadoop.hive.accumulo.predicate.compare.GreaterThan;
+import org.apache.hadoop.hive.accumulo.predicate.compare.GreaterThanOrEqual;
+import org.apache.hadoop.hive.accumulo.predicate.compare.IntCompare;
+import org.apache.hadoop.hive.accumulo.predicate.compare.LessThan;
+import org.apache.hadoop.hive.accumulo.predicate.compare.LessThanOrEqual;
+import org.apache.hadoop.hive.accumulo.predicate.compare.LongCompare;
+import org.apache.hadoop.hive.accumulo.predicate.compare.NotEqual;
+import org.apache.hadoop.hive.accumulo.predicate.compare.PrimitiveComparison;
+import org.apache.hadoop.hive.accumulo.predicate.compare.StringCompare;
+import org.apache.hadoop.hive.accumulo.serde.AccumuloSerDeParameters;
+import org.apache.hadoop.hive.accumulo.serde.TooManyAccumuloColumnsException;
+import org.apache.hadoop.hive.ql.exec.FunctionRegistry;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.index.IndexSearchCondition;
+import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.ql.plan.TableScanDesc;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqual;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrLessThan;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPGreaterThan;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPNotNull;
+import org.apache.hadoop.hive.serde.serdeConstants;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.lazy.LazyUtils;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaIntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
+
+public class TestAccumuloPredicateHandler {
+  @SuppressWarnings("unused")
+  private static final Logger log = Logger.getLogger(TestAccumuloPredicateHandler.class);
+
+  private AccumuloPredicateHandler handler = AccumuloPredicateHandler.getInstance();
+  private JobConf conf;
+  private ColumnMapper columnMapper;
+
+  @Before
+  public void setup() throws TooManyAccumuloColumnsException {
+    FunctionRegistry.getFunctionNames();
+    conf = new JobConf();
+    List<String> columnNames = Arrays.asList("field1", "rid");
+    List<TypeInfo> columnTypes = Arrays.<TypeInfo> asList(TypeInfoFactory.stringTypeInfo,
+        TypeInfoFactory.stringTypeInfo);
+    conf.set(serdeConstants.LIST_COLUMNS, Joiner.on(',').join(columnNames));
+    conf.set(serdeConstants.LIST_COLUMN_TYPES, "string,string");
+
+    String columnMappingStr = "cf:f1,:rowID";
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, columnMappingStr);
+    columnMapper = new ColumnMapper(columnMappingStr, ColumnEncoding.STRING.getName(), columnNames,
+        columnTypes);
+  }
+
+  @Test
+  public void testGetRowIDSearchCondition() {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "hi");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqual(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
+    assertEquals(sConditions.size(), 1);
+  }
+
+  @Test()
+  public void testRangeEqual() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqual(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(ranges.size(), 1);
+    Range range = ranges.iterator().next();
+    assertTrue(range.isStartKeyInclusive());
+    assertFalse(range.isEndKeyInclusive());
+    assertTrue(range.contains(new Key(new Text("aaa"))));
+    assertTrue(range.afterEndKey(new Key(new Text("aab"))));
+    assertTrue(range.beforeStartKey(new Key(new Text("aa"))));
+  }
+
+  @Test()
+  public void testRangeGreaterThan() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPGreaterThan(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(ranges.size(), 1);
+    Range range = ranges.iterator().next();
+    assertTrue(range.isStartKeyInclusive());
+    assertFalse(range.isEndKeyInclusive());
+    assertFalse(range.contains(new Key(new Text("aaa"))));
+    assertFalse(range.afterEndKey(new Key(new Text("ccccc"))));
+    assertTrue(range.contains(new Key(new Text("aab"))));
+    assertTrue(range.beforeStartKey(new Key(new Text("aa"))));
+    assertTrue(range.beforeStartKey(new Key(new Text("aaa"))));
+  }
+
+  @Test
+  public void rangeGreaterThanOrEqual() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrGreaterThan(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(ranges.size(), 1);
+    Range range = ranges.iterator().next();
+    assertTrue(range.isStartKeyInclusive());
+    assertFalse(range.isEndKeyInclusive());
+    assertTrue(range.contains(new Key(new Text("aaa"))));
+    assertFalse(range.afterEndKey(new Key(new Text("ccccc"))));
+    assertTrue(range.contains(new Key(new Text("aab"))));
+    assertTrue(range.beforeStartKey(new Key(new Text("aa"))));
+  }
+
+  @Test
+  public void rangeLessThan() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPLessThan(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(ranges.size(), 1);
+    Range range = ranges.iterator().next();
+    assertTrue(range.isStartKeyInclusive());
+    assertFalse(range.isEndKeyInclusive());
+    assertFalse(range.contains(new Key(new Text("aaa"))));
+    assertTrue(range.afterEndKey(new Key(new Text("ccccc"))));
+    assertTrue(range.contains(new Key(new Text("aa"))));
+    assertTrue(range.afterEndKey(new Key(new Text("aab"))));
+    assertTrue(range.afterEndKey(new Key(new Text("aaa"))));
+  }
+
+  @Test
+  public void rangeLessThanOrEqual() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(ranges.size(), 1);
+    Range range = ranges.iterator().next();
+    assertTrue(range.isStartKeyInclusive());
+    assertFalse(range.isEndKeyInclusive());
+    assertTrue(range.contains(new Key(new Text("aaa"))));
+    assertTrue(range.afterEndKey(new Key(new Text("ccccc"))));
+    assertTrue(range.contains(new Key(new Text("aa"))));
+    assertTrue(range.afterEndKey(new Key(new Text("aab"))));
+    assertFalse(range.afterEndKey(new Key(new Text("aaa"))));
+  }
+
+  @Test
+  public void testDisjointRanges() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children);
+    assertNotNull(node);
+
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "bbb");
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPGreaterThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
+
+    // Impossible to get ranges for row <= 'aaa' and row >= 'bbb'
+    assertEquals(0, ranges.size());
+  }
+
+  @Test
+  public void testMultipleRanges() throws SerDeException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrGreaterThan(), children);
+    assertNotNull(node);
+
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "bbb");
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPLessThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    List<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(1, ranges.size());
+    Range range = ranges.get(0);
+    assertEquals(new Range(new Key("aaa"), true, new Key("bbb"), false), range);
+  }
+
+  @Test
+  public void testPushdownTuple() throws SerDeException, NoSuchPrimitiveComparisonException,
+      NoSuchCompareOpException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "field1", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, 5);
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqual(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
+    assertEquals(sConditions.size(), 1);
+    IndexSearchCondition sc = sConditions.get(0);
+    PushdownTuple tuple = new PushdownTuple(sConditions.get(0), handler.getPrimitiveComparison(sc
+        .getColumnDesc().getTypeString(), sc), handler.getCompareOp(sc.getComparisonOp(), sc));
+    byte[] expectedVal = new byte[4];
+    ByteBuffer.wrap(expectedVal).putInt(5);
+    assertArrayEquals(tuple.getConstVal(), expectedVal);
+    assertEquals(tuple.getcOpt().getClass(), Equal.class);
+    assertEquals(tuple.getpCompare().getClass(), IntCompare.class);
+  }
+
+  @Test(expected = NoSuchPrimitiveComparisonException.class)
+  public void testPushdownColumnTypeNotSupported() throws SerDeException,
+      NoSuchPrimitiveComparisonException, NoSuchCompareOpException {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.floatTypeInfo, "field1", null,
+        false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.floatTypeInfo, 5.5f);
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqual(), children);
+    assertNotNull(node);
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+    List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
+    assertEquals(sConditions.size(), 1);
+    IndexSearchCondition sc = sConditions.get(0);
+
+    handler.getPrimitiveComparison(sc.getColumnDesc().getTypeString(), sc);
+  }
+
+  @Test
+  public void testPushdownComparisonOptNotSupported() {
+    try {
+      ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "field1", null,
+          false);
+      List<ExprNodeDesc> children = Lists.newArrayList();
+      children.add(column);
+      ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+          new GenericUDFOPNotNull(), children);
+      assertNotNull(node);
+      String filterExpr = Utilities.serializeExpression(node);
+      conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+      List<IndexSearchCondition> sConditions = handler.getSearchConditions(conf);
+      assertEquals(sConditions.size(), 1);
+      IndexSearchCondition sc = sConditions.get(0);
+      new PushdownTuple(sc, handler.getPrimitiveComparison(sc.getColumnDesc().getTypeString(), sc),
+          handler.getCompareOp(sc.getComparisonOp(), sc));
+      fail("Should fail: compare op not registered for index analyzer. Should leave undesirable residual predicate");
+    } catch (RuntimeException e) {
+      assertTrue(e.getMessage().contains("Unexpected residual predicate: field1 is not null"));
+    } catch (Exception e) {
+      fail(StringUtils.stringifyException(e));
+    }
+  }
+
+  @Test
+  public void testIteratorIgnoreRowIDFields() {
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children);
+    assertNotNull(node);
+
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "bbb");
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPGreaterThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+    try {
+      List<IteratorSetting> iterators = handler.getIterators(conf, columnMapper);
+      assertEquals(iterators.size(), 0);
+    } catch (SerDeException e) {
+      StringUtils.stringifyException(e);
+    }
+  }
+
+  @Test
+  public void testIgnoreIteratorPushdown() throws TooManyAccumuloColumnsException {
+    // Override what's placed in the Configuration by setup()
+    conf = new JobConf();
+    List<String> columnNames = Arrays.asList("field1", "field2", "rid");
+    List<TypeInfo> columnTypes = Arrays.<TypeInfo> asList(TypeInfoFactory.stringTypeInfo,
+        TypeInfoFactory.intTypeInfo, TypeInfoFactory.stringTypeInfo);
+    conf.set(serdeConstants.LIST_COLUMNS, Joiner.on(',').join(columnNames));
+    conf.set(serdeConstants.LIST_COLUMN_TYPES, "string,int,string");
+
+    String columnMappingStr = "cf:f1,cf:f2,:rowID";
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, columnMappingStr);
+    columnMapper = new ColumnMapper(columnMappingStr, ColumnEncoding.STRING.getName(), columnNames,
+        columnTypes);
+
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "field1", null,
+        false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children);
+    assertNotNull(node);
+
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "field2", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, 5);
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPGreaterThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+    conf.setBoolean(AccumuloSerDeParameters.ITERATOR_PUSHDOWN_KEY, false);
+    try {
+      List<IteratorSetting> iterators = handler.getIterators(conf, columnMapper);
+      assertEquals(iterators.size(), 0);
+    } catch (Exception e) {
+      fail(StringUtils.stringifyException(e));
+    }
+  }
+
+  @Test
+  public void testCreateIteratorSettings() throws Exception {
+    // Override what's placed in the Configuration by setup()
+    conf = new JobConf();
+    List<String> columnNames = Arrays.asList("field1", "field2", "rid");
+    List<TypeInfo> columnTypes = Arrays.<TypeInfo> asList(TypeInfoFactory.stringTypeInfo,
+        TypeInfoFactory.intTypeInfo, TypeInfoFactory.stringTypeInfo);
+    conf.set(serdeConstants.LIST_COLUMNS, Joiner.on(',').join(columnNames));
+    conf.set(serdeConstants.LIST_COLUMN_TYPES, "string,int,string");
+    String columnMappingStr = "cf:f1,cf:f2,:rowID";
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, columnMappingStr);
+    columnMapper = new ColumnMapper(columnMappingStr, ColumnEncoding.STRING.getName(), columnNames,
+        columnTypes);
+
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "field1", null,
+        false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children);
+    assertNotNull(node);
+
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "field2", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, 5);
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPGreaterThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+    List<IteratorSetting> iterators = handler.getIterators(conf, columnMapper);
+    assertEquals(iterators.size(), 2);
+    IteratorSetting is1 = iterators.get(0);
+    IteratorSetting is2 = iterators.get(1);
+
+    boolean foundQual = false;
+    boolean foundPCompare = false;
+    boolean foundCOpt = false;
+    boolean foundConst = false;
+    for (Map.Entry<String,String> option : is1.getOptions().entrySet()) {
+      String optKey = option.getKey();
+      if (optKey.equals(PrimitiveComparisonFilter.COLUMN)) {
+        foundQual = true;
+        assertEquals(option.getValue(), "cf:f1");
+      } else if (optKey.equals(PrimitiveComparisonFilter.CONST_VAL)) {
+        foundConst = true;
+        assertEquals(option.getValue(), new String(Base64.encodeBase64("aaa".getBytes())));
+      } else if (optKey.equals(PrimitiveComparisonFilter.COMPARE_OPT_CLASS)) {
+        foundCOpt = true;
+        assertEquals(option.getValue(), LessThanOrEqual.class.getName());
+      } else if (optKey.equals(PrimitiveComparisonFilter.P_COMPARE_CLASS)) {
+        foundPCompare = true;
+        assertEquals(option.getValue(), StringCompare.class.getName());
+      }
+
+    }
+    assertTrue(foundConst & foundCOpt & foundPCompare & foundQual);
+
+    foundQual = false;
+    foundPCompare = false;
+    foundCOpt = false;
+    foundConst = false;
+    for (Map.Entry<String,String> option : is2.getOptions().entrySet()) {
+      String optKey = option.getKey();
+      if (optKey.equals(PrimitiveComparisonFilter.COLUMN)) {
+        foundQual = true;
+        assertEquals(option.getValue(), "cf:f2");
+      } else if (optKey.equals(PrimitiveComparisonFilter.CONST_VAL)) {
+        foundConst = true;
+        byte[] intVal = new byte[4];
+        ByteBuffer.wrap(intVal).putInt(5);
+        assertEquals(option.getValue(), new String(Base64.encodeBase64(intVal)));
+      } else if (optKey.equals(PrimitiveComparisonFilter.COMPARE_OPT_CLASS)) {
+        foundCOpt = true;
+        assertEquals(option.getValue(), GreaterThan.class.getName());
+      } else if (optKey.equals(PrimitiveComparisonFilter.P_COMPARE_CLASS)) {
+        foundPCompare = true;
+        assertEquals(option.getValue(), IntCompare.class.getName());
+      }
+
+    }
+    assertTrue(foundConst & foundCOpt & foundPCompare & foundQual);
+  }
+
+  @Test
+  public void testBasicOptLookup() throws NoSuchCompareOpException {
+    boolean foundEqual = false;
+    boolean foundNotEqual = false;
+    boolean foundGreaterThanOrEqual = false;
+    boolean foundGreaterThan = false;
+    boolean foundLessThanOrEqual = false;
+    boolean foundLessThan = false;
+    for (String opt : handler.cOpKeyset()) {
+      Class<? extends CompareOp> compOpt = handler.getCompareOpClass(opt);
+      if (compOpt.getName().equals(Equal.class.getName())) {
+        foundEqual = true;
+      } else if (compOpt.getName().equals(NotEqual.class.getName())) {
+        foundNotEqual = true;
+      } else if (compOpt.getName().equals(GreaterThan.class.getName())) {
+        foundGreaterThan = true;
+      } else if (compOpt.getName().equals(GreaterThanOrEqual.class.getName())) {
+        foundGreaterThanOrEqual = true;
+      } else if (compOpt.getName().equals(LessThan.class.getName())) {
+        foundLessThan = true;
+      } else if (compOpt.getName().equals(LessThanOrEqual.class.getName())) {
+        foundLessThanOrEqual = true;
+      }
+    }
+    assertTrue("Did not find Equal comparison op", foundEqual);
+    assertTrue("Did not find NotEqual comparison op", foundNotEqual);
+    assertTrue("Did not find GreaterThan comparison op", foundGreaterThan);
+    assertTrue("Did not find GreaterThanOrEqual comparison op", foundGreaterThanOrEqual);
+    assertTrue("Did not find LessThan comparison op", foundLessThan);
+    assertTrue("Did not find LessThanOrEqual comparison op", foundLessThanOrEqual);
+  }
+
+  @Test(expected = NoSuchCompareOpException.class)
+  public void testNoOptFound() throws NoSuchCompareOpException {
+    handler.getCompareOpClass("blah");
+  }
+
+  @Test
+  public void testPrimitiveComparsionLookup() throws NoSuchPrimitiveComparisonException {
+    boolean foundLong = false;
+    boolean foundString = false;
+    boolean foundInt = false;
+    boolean foundDouble = false;
+    for (String type : handler.pComparisonKeyset()) {
+      Class<? extends PrimitiveComparison> pCompare = handler.getPrimitiveComparisonClass(type);
+      if (pCompare.getName().equals(DoubleCompare.class.getName())) {
+        foundDouble = true;
+      } else if (pCompare.getName().equals(LongCompare.class.getName())) {
+        foundLong = true;
+      } else if (pCompare.getName().equals(IntCompare.class.getName())) {
+        foundInt = true;
+      } else if (pCompare.getName().equals(StringCompare.class.getName())) {
+        foundString = true;
+      }
+    }
+    assertTrue("Did not find DoubleCompare op", foundDouble);
+    assertTrue("Did not find LongCompare op", foundLong);
+    assertTrue("Did not find IntCompare op", foundInt);
+    assertTrue("Did not find StringCompare op", foundString);
+  }
+
+  @Test
+  public void testRowRangeIntersection() throws SerDeException {
+    // rowId >= 'f'
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "f");
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(column);
+    children.add(constant);
+    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrGreaterThan(), children);
+    assertNotNull(node);
+
+    // rowId <= 'm'
+    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null,
+        false);
+    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "m");
+    List<ExprNodeDesc> children2 = Lists.newArrayList();
+    children2.add(column2);
+    children2.add(constant2);
+    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPEqualOrLessThan(), children2);
+    assertNotNull(node2);
+
+    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
+    bothFilters.add(node);
+    bothFilters.add(node2);
+    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPAnd(), bothFilters);
+
+    String filterExpr = Utilities.serializeExpression(both);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    // Should make ['f', 'm\0')
+    List<Range> ranges = handler.getRanges(conf, columnMapper);
+    assertEquals(1, ranges.size());
+    assertEquals(new Range(new Key("f"), true, new Key("m\0"), false), ranges.get(0));
+  }
+
+  @Test
+  public void testRowRangeGeneration() throws SerDeException {
+    List<String> columnNames = Arrays.asList("key", "column");
+    List<TypeInfo> columnTypes = Arrays.<TypeInfo> asList(TypeInfoFactory.stringTypeInfo,
+        TypeInfoFactory.stringTypeInfo);
+    conf.set(serdeConstants.LIST_COLUMNS, Joiner.on(',').join(columnNames));
+    conf.set(serdeConstants.LIST_COLUMN_TYPES, "string,string");
+
+    String columnMappingStr = ":rowID,cf:f1";
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, columnMappingStr);
+    columnMapper = new ColumnMapper(columnMappingStr, ColumnEncoding.STRING.getName(), columnNames,
+        columnTypes);
+
+    // 100 < key
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "key", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, 100);
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(constant);
+    children.add(column);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPLessThan(), children);
+    assertNotNull(node);
+
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    // Should make (100, +inf)
+    List<Range> ranges = handler.getRanges(conf, columnMapper);
+    Assert.assertEquals(1, ranges.size());
+    Assert.assertEquals(new Range(new Text("100"), false, null, false), ranges.get(0));
+  }
+
+  @Test
+  public void testBinaryRangeGeneration() throws Exception {
+    List<String> columnNames = Arrays.asList("key", "column");
+    List<TypeInfo> columnTypes = Arrays.<TypeInfo> asList(TypeInfoFactory.intTypeInfo,
+        TypeInfoFactory.stringTypeInfo);
+    conf.set(serdeConstants.LIST_COLUMNS, Joiner.on(',').join(columnNames));
+    conf.set(serdeConstants.LIST_COLUMN_TYPES, "int,string");
+
+    String columnMappingStr = ":rowID#b,cf:f1";
+    conf.set(AccumuloSerDeParameters.COLUMN_MAPPINGS, columnMappingStr);
+    columnMapper = new ColumnMapper(columnMappingStr, ColumnEncoding.STRING.getName(), columnNames,
+        columnTypes);
+
+    int intValue = 100;
+
+    // Make binary integer value in the bytearray
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    JavaIntObjectInspector intOI = (JavaIntObjectInspector) PrimitiveObjectInspectorFactory
+        .getPrimitiveJavaObjectInspector(TypeInfoFactory
+            .getPrimitiveTypeInfo(serdeConstants.INT_TYPE_NAME));
+    LazyUtils.writePrimitive(baos, intValue, intOI);
+
+    // 100 < key
+    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.intTypeInfo, "key", null, false);
+    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, intValue);
+    List<ExprNodeDesc> children = Lists.newArrayList();
+    children.add(constant);
+    children.add(column);
+    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo,
+        new GenericUDFOPLessThan(), children);
+    assertNotNull(node);
+
+    String filterExpr = Utilities.serializeExpression(node);
+    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
+
+    // Should make (100, +inf)
+    List<Range> ranges = handler.getRanges(conf, columnMapper);
+    Assert.assertEquals(1, ranges.size());
+    Assert.assertEquals(new Range(new Text(baos.toByteArray()), false, null, false), ranges.get(0));
+  }
+
+  @Test
+  public void testNullRangeGeneratorOutput() throws SerDeException {
+    // The AccumuloRangeGenerator produces an Object (due to the limitations of the
+    // traversal interface) which requires interpretation of that Object into Ranges.
+    // Changes in the return object from the AccumuloRangeGenerator must also represent
+    // a change in the AccumuloPredicateHandler.
+    AccumuloPredicateHandler mockHandler = Mockito.mock(AccumuloPredicateHandler.class);
+    ExprNodeDesc root = Mockito.mock(ExprNodeDesc.class);
+    String hiveRowIdColumnName = "rid";
+
+    Mockito.when(mockHandler.getRanges(conf, columnMapper)).thenCallRealMethod();
+    Mockito.when(mockHandler.generateRanges(columnMapper, hiveRowIdColumnName, root)).thenReturn(null);
+    Mockito.when(mockHandler.getExpression(conf)).thenReturn(root);
+
+    // A null result from AccumuloRangeGenerator is all ranges
+    Assert.assertEquals(Arrays.asList(new Range()), mockHandler.getRanges(conf, columnMapper));
+  }
+
+  @Test
+  public void testEmptyListRangeGeneratorOutput() throws SerDeException {
+    // The AccumuloRangeGenerator produces an Object (due to the limitations of the
+    // traversal interface) which requires interpretation of that Object into Ranges.
+    // Changes in the return object from the AccumuloRangeGenerator must also represent
+    // a change in the AccumuloPredicateHandler.
+    AccumuloPredicateHandler mockHandler = Mockito.mock(AccumuloPredicateHandler.class);
+    ExprNodeDesc root = Mockito.mock(ExprNodeDesc.class);
+    String hiveRowIdColumnName = "rid";
+
+    Mockito.when(mockHandler.getRanges(conf, columnMapper)).thenCallRealMethod();
+    Mockito.when(mockHandler.generateRanges(columnMapper, hiveRowIdColumnName, root)).thenReturn(Collections.emptyList());
+    Mockito.when(mockHandler.getExpression(conf)).thenReturn(root);
+
+    // A null result from AccumuloRangeGenerator is all ranges
+    Assert.assertEquals(Collections.emptyList(), mockHandler.getRanges(conf, columnMapper));
+  }
+
+  @Test
+  public void testSingleRangeGeneratorOutput() throws SerDeException {
+    // The AccumuloRangeGenerator produces an Object (due to the limitations of the
+    // traversal interface) which requires interpretation of that Object into Ranges.
+    // Changes in the return object from the AccumuloRangeGenerator must also represent
+    // a change in the AccumuloPredicateHandler.
+    AccumuloPredicateHandler mockHandler = Mockito.mock(AccumuloPredicateHandler.class);
+    ExprNodeDesc root = Mockito.mock(ExprNodeDesc.class);
+    String hiveRowIdColumnName = "rid";
+    Range r = new Range("a");
+
+    Mockito.when(mockHandler.getRanges(conf, columnMapper)).thenCallRealMethod();
+    Mockito.when(mockHandler.generateRanges(columnMapper, hiveRowIdColumnName, root)).thenReturn(r);
+    Mockito.when(mockHandler.getExpression(conf)).thenReturn(root);
+
+    // A null result from AccumuloRangeGenerator is all ranges
+    Assert.assertEquals(Collections.singletonList(r), mockHandler.getRanges(conf, columnMapper));
+  }
+
+  @Test
+  public void testManyRangesGeneratorOutput() throws SerDeException {
+    // The AccumuloRangeGenerator produces an Object (due to the limitations of the
+    // traversal interface) which requires interpretation of that Object into Ranges.
+    // Changes in the return object from the AccumuloRangeGenerator must also represent
+    // a change in the AccumuloPredicateHandler.
+    AccumuloPredicateHandler mockHandler = Mockito.mock(AccumuloPredicateHandler.class);
+    ExprNodeDesc root = Mockito.mock(ExprNodeDesc.class);
+    String hiveRowIdColumnName = "rid";
+    Range r1 = new Range("a"), r2 = new Range("z");
+
+    Mockito.when(mockHandler.getRanges(conf, columnMapper)).thenCallRealMethod();
+    Mockito.when(mockHandler.generateRanges(columnMapper, hiveRowIdColumnName, root)).thenReturn(Arrays.asList(r1, r2));
+    Mockito.when(mockHandler.getExpression(conf)).thenReturn(root);
+
+    // A null result from AccumuloRangeGenerator is all ranges
+    Assert.assertEquals(Arrays.asList(r1, r2), mockHandler.getRanges(conf, columnMapper));
+  }
+}



Mime
View raw message