use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector in project hive by apache.
the class TestGenericUDFStringToMap method initGenericUDFWithNoDelimiters.
private void initGenericUDFWithNoDelimiters(GenericUDFStringToMap udf) throws UDFArgumentException {
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] arguments = { valueOI0 };
udf.initialize(arguments);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector in project hive by apache.
the class TestGenericUDFTrunc method testTimestampToDateWithYearFormat.
public void testTimestampToDateWithYearFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("YYYY"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector in project hive by apache.
the class TestGenericUDFTrunc method testStringToDateWithYearFormat.
public void testStringToDateWithYearFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("YEAR"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new Text("2014-01-01"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-01-14"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-01-31"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-02-02"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-02-28"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-03"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-28"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-29"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new Text("2014-01-01 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-01-14 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-01-31 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-02-02 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2014-02-28 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-03 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-28 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new Text("2016-02-29 10:30:45"));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector in project hive by apache.
the class TestGenericUDFTrunc method testDateWritableToDateWithQuarterFormat.
public void testDateWritableToDateWithQuarterFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("Q"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-01")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-14")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-01-31")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-02-02")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2014-02-28")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-03")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-28")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-02-29")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-05-11")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-07-01")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new DateWritable(Date.valueOf("2016-12-31")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
}
use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector in project hive by apache.
the class TestGenericUDFTrunc method testTimestampToDateWithQuarterFormat.
public void testTimestampToDateWithQuarterFormat() throws HiveException {
GenericUDFTrunc udf = new GenericUDFTrunc();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
ObjectInspector[] initArgs = { valueOI0, valueOI1 };
DeferredObject valueObjFmt = new DeferredJavaObject(new Text("Q"));
DeferredObject valueObj0;
DeferredObject[] evalArgs;
// test date string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-05-11 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-07-01 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-12-31 00:00:00")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
// test timestamp string
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-14 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-01-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-02 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2014-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2014-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-03 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-28 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-02-29 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-01-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-05-11 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-04-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-07-01 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-07-01", udf, initArgs, evalArgs);
valueObj0 = new DeferredJavaObject(new TimestampWritable(Timestamp.valueOf("2016-12-31 10:30:45")));
evalArgs = new DeferredObject[] { valueObj0, valueObjFmt };
runAndVerify("2016-10-01", udf, initArgs, evalArgs);
}
Aggregations