use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFToUnixTimestamp method testString.
public void testString() throws HiveException {
GenericUDFToUnixTimeStamp udf1 = new GenericUDFToUnixTimeStamp();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf1.initialize(arguments);
String val = "2001-01-01 01:02:03";
runAndVerify(udf1, new Text(val), new LongWritable(Timestamp.valueOf(val).getTime() / 1000));
// test null values
runAndVerify(udf1, null, null);
// Try 2-arg version
GenericUDFToUnixTimeStamp udf2 = new GenericUDFToUnixTimeStamp();
ObjectInspector[] args2 = { valueOI, valueOI };
udf2.initialize(args2);
val = "2001-01-01";
String format = "yyyy-MM-dd";
runAndVerify(udf2, new Text(val), new Text(format), new LongWritable(Date.valueOf(val).getTime() / 1000));
// test null values
runAndVerify(udf2, null, null, null);
runAndVerify(udf2, null, new Text(format), null);
runAndVerify(udf2, new Text(val), null, null);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFTrim method testTrim.
public void testTrim() throws HiveException {
GenericUDFTrim udf = new GenericUDFTrim();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
runAndVerify(" Hello World! ", "Hello World!", udf);
runAndVerify("Hello World! ", "Hello World!", udf);
runAndVerify(" Hello World!", "Hello World!", udf);
runAndVerify("Hello World!", "Hello World!", udf);
runAndVerify(" ", "", udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFRpad method testRpad.
public void testRpad() throws HiveException {
GenericUDFRpad udf = new GenericUDFRpad();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 };
udf.initialize(arguments);
runAndVerify("hi", 5, "??", "hi???", udf);
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("hi", 5, "??", "hi???", udf);
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("hi", 3, "", null, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFSha2 method testSha200Str.
public void testSha200Str() throws HiveException {
GenericUDFSha2 udf = new GenericUDFSha2();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
IntWritable lenWr = new IntWritable(200);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runAndVerifyStr("ABC", lenWr, null, udf);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.
the class TestGenericUDFSha2 method testSha512Str.
public void testSha512Str() throws HiveException {
GenericUDFSha2 udf = new GenericUDFSha2();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
IntWritable lenWr = new IntWritable(512);
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
ObjectInspector[] arguments = { valueOI0, valueOI1 };
udf.initialize(arguments);
runAndVerifyStr("ABC", lenWr, "397118fdac8d83ad98813c50759c85b8c47565d8268bf10da483153b747a74743a58a90e85aa9f705ce6984ffc128db567489817e4092d050d8a1cc596ddc119", udf);
runAndVerifyStr("", lenWr, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", udf);
// null
runAndVerifyStr(null, lenWr, null, udf);
}
Aggregations