use of org.apache.hadoop.hive.common.type.HiveChar in project hive by apache.
the class TestGenericUDFFloor method testChar.
@Test
public void testChar() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
HiveChar vc = new HiveChar("32300.004747", 12);
HiveCharWritable input = new HiveCharWritable(vc);
CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(32300L, res.get());
}
use of org.apache.hadoop.hive.common.type.HiveChar in project hive by apache.
the class TestVectorStringExpressions method testStringColCompareCharScalarFilter.
@Test
public // Test string column to CHAR literal comparison
void testStringColCompareCharScalarFilter() {
VectorizedRowBatch batch = makeStringBatch();
VectorExpression expr;
expr = new FilterStringGroupColEqualCharScalar(0, new HiveChar(new String(red2), 10));
expr.evaluate(batch);
// only red qualifies, and it's in entry 0
Assert.assertTrue(batch.size == 1);
Assert.assertTrue(batch.selected[0] == 0);
batch = makeStringBatch();
expr = new FilterStringGroupColLessCharScalar(0, new HiveChar(new String(red2), 8));
expr.evaluate(batch);
// only green qualifies, and it's in entry 1
Assert.assertTrue(batch.size == 1);
Assert.assertTrue(batch.selected[0] == 1);
batch = makeStringBatch();
expr = new FilterStringGroupColGreaterEqualCharScalar(0, new HiveChar(new String(green), 12));
expr.evaluate(batch);
// green and red qualify
Assert.assertTrue(batch.size == 2);
Assert.assertTrue(batch.selected[0] == 0);
Assert.assertTrue(batch.selected[1] == 1);
}
use of org.apache.hadoop.hive.common.type.HiveChar in project hive by apache.
the class TestVectorStringExpressions method testStringColCompareCharScalarProjection.
@Test
public void testStringColCompareCharScalarProjection() {
VectorizedRowBatch batch = makeStringBatch();
VectorExpression expr;
expr = new StringGroupColEqualCharScalar(0, new HiveChar(new String(red2), 8), 2);
expr.evaluate(batch);
Assert.assertEquals(3, batch.size);
LongColumnVector outVector = (LongColumnVector) batch.cols[2];
Assert.assertEquals(1, outVector.vector[0]);
Assert.assertEquals(0, outVector.vector[1]);
Assert.assertEquals(0, outVector.vector[2]);
batch = makeStringBatch();
expr = new StringGroupColEqualCharScalar(0, new HiveChar(new String(green), 10), 2);
expr.evaluate(batch);
Assert.assertEquals(3, batch.size);
outVector = (LongColumnVector) batch.cols[2];
Assert.assertEquals(0, outVector.vector[0]);
Assert.assertEquals(1, outVector.vector[1]);
Assert.assertEquals(0, outVector.vector[2]);
}
use of org.apache.hadoop.hive.common.type.HiveChar in project hive by apache.
the class TestGenericUDFCeil method testChar.
@Test
public void testChar() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
HiveChar vc = new HiveChar("-32300.004747", 12);
HiveCharWritable input = new HiveCharWritable(vc);
CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo) };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(-32300L, res.get());
}
use of org.apache.hadoop.hive.common.type.HiveChar in project hive by apache.
the class TestSearchArgumentImpl method testBuilderComplexTypes2.
@Test
public void testBuilderComplexTypes2() throws Exception {
SearchArgument sarg = SearchArgumentFactory.newBuilder().startAnd().lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("2005-3-12")).lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString()).equals("z", PredicateLeaf.Type.DECIMAL, new HiveDecimalWritable("1.0")).end().build();
assertEquals("leaf-0 = (LESS_THAN x 2005-03-12), " + "leaf-1 = (LESS_THAN_EQUALS y hi ), " + "leaf-2 = (EQUALS z 1), " + "expr = (and leaf-0 leaf-1 leaf-2)", sarg.toString());
sarg = SearchArgumentFactory.newBuilder().startNot().startOr().isNull("x", PredicateLeaf.Type.LONG).between("y", PredicateLeaf.Type.DECIMAL, new HiveDecimalWritable("10"), new HiveDecimalWritable("20.0")).in("z", PredicateLeaf.Type.LONG, 1L, 2L, 3L).nullSafeEquals("a", PredicateLeaf.Type.STRING, new HiveVarchar("stinger", 100).toString()).end().end().build();
assertEquals("leaf-0 = (IS_NULL x), " + "leaf-1 = (BETWEEN y 10 20), " + "leaf-2 = (IN z 1 2 3), " + "leaf-3 = (NULL_SAFE_EQUALS a stinger), " + "expr = (and (not leaf-0) (not leaf-1) (not leaf-2) (not leaf-3))", sarg.toString());
}
Aggregations