use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.longTypeInfo in project hive by apache.
the class ExprNodeGenericFuncDesc method newInstance.
/**
* Create a ExprNodeGenericFuncDesc based on the genericUDFClass and the
* children parameters. If the function has an explicit name, the
* newInstance method should be passed the function name in the funcText
* argument.
*
* @throws UDFArgumentException
*/
public static ExprNodeGenericFuncDesc newInstance(GenericUDF genericUDF, String funcText, List<ExprNodeDesc> children) throws UDFArgumentException {
ObjectInspector[] childrenOIs = new ObjectInspector[children.size()];
for (int i = 0; i < childrenOIs.length; i++) {
childrenOIs[i] = children.get(i).getWritableObjectInspector();
}
// Perform the check here instead of in GenericUDFBaseCompare to guarantee it is only run once per operator
if (genericUDF instanceof GenericUDFBaseCompare && children.size() == 2) {
TypeInfo oiTypeInfo0 = children.get(0).getTypeInfo();
TypeInfo oiTypeInfo1 = children.get(1).getTypeInfo();
SessionState ss = SessionState.get();
Configuration conf = (ss != null) ? ss.getConf() : new Configuration();
LogHelper console = new LogHelper(LOG);
// For now, if a bigint is going to be cast to a double throw an error or warning
if ((oiTypeInfo0.equals(TypeInfoFactory.stringTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.longTypeInfo)) || (oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.stringTypeInfo))) {
String error = StrictChecks.checkTypeSafety(conf);
if (error != null)
throw new UDFArgumentException(error);
console.printError("WARNING: Comparing a bigint and a string may result in a loss of precision.");
} else if ((oiTypeInfo0.equals(TypeInfoFactory.doubleTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.longTypeInfo)) || (oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.doubleTypeInfo))) {
String error = StrictChecks.checkTypeSafety(conf);
if (error != null)
throw new UDFArgumentException(error);
console.printError("WARNING: Comparing a bigint and a double may result in a loss of precision.");
}
}
ObjectInspector oi = genericUDF.initializeAndFoldConstants(childrenOIs);
String[] requiredJars = genericUDF.getRequiredJars();
String[] requiredFiles = genericUDF.getRequiredFiles();
SessionState ss = SessionState.get();
if (requiredJars != null) {
SessionState.ResourceType t = SessionState.find_resource_type("JAR");
try {
ss.add_resources(t, Arrays.asList(requiredJars));
} catch (Exception e) {
throw new UDFArgumentException(e);
}
}
if (requiredFiles != null) {
SessionState.ResourceType t = SessionState.find_resource_type("FILE");
try {
ss.add_resources(t, Arrays.asList(requiredFiles));
} catch (Exception e) {
throw new UDFArgumentException(e);
}
}
return new ExprNodeGenericFuncDesc(oi, genericUDF, funcText, children);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.longTypeInfo in project hive by apache.
the class TestMapJoinOperator method doTestLong.
public void doTestLong(long seed, TypeInfo numberTypeInfo, VectorMapJoinVariation vectorMapJoinVariation) throws Exception {
int rowCount = 10000;
HiveConf hiveConf = new HiveConf();
String[] bigTableColumnNames = new String[] { "number1" };
TypeInfo[] bigTableTypeInfos = new TypeInfo[] { TypeInfoFactory.longTypeInfo };
int[] bigTableKeyColumnNums = new int[] { 0 };
String[] smallTableValueColumnNames = new String[] { "sv1", "sv2" };
TypeInfo[] smallTableValueTypeInfos = new TypeInfo[] { TypeInfoFactory.dateTypeInfo, TypeInfoFactory.stringTypeInfo };
int[] bigTableRetainColumnNums = new int[] { 0 };
int[] smallTableRetainKeyColumnNums = new int[] {};
int[] smallTableRetainValueColumnNums = new int[] { 0, 1 };
SmallTableGenerationParameters smallTableGenerationParameters = new SmallTableGenerationParameters();
// ----------------------------------------------------------------------------------------------
MapJoinTestDescription testDesc = new MapJoinTestDescription(hiveConf, vectorMapJoinVariation, bigTableColumnNames, bigTableTypeInfos, bigTableKeyColumnNums, smallTableValueColumnNames, smallTableValueTypeInfos, bigTableRetainColumnNums, smallTableRetainKeyColumnNums, smallTableRetainValueColumnNums, smallTableGenerationParameters);
// Prepare data. Good for ANY implementation variation.
MapJoinTestData testData = new MapJoinTestData(rowCount, testDesc, seed, seed * 10);
executeTest(testDesc, testData);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.longTypeInfo in project hive by apache.
the class TestGenericUDFFloor method testString.
@Test
public void testString() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
Text input = new Text("32300.004747");
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector };
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.serde2.typeinfo.TypeInfoFactory.longTypeInfo in project hive by apache.
the class TestGenericUDFFloor method testShort.
@Test
public void testShort() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
ShortWritable input = new ShortWritable((short) 74);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector };
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(74L, res.get());
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.longTypeInfo in project hive by apache.
the class TestGenericUDFFloor method testFloat.
@Test
public void testFloat() throws HiveException {
GenericUDFFloor udf = new GenericUDFFloor();
FloatWritable input = new FloatWritable(-323.4747f);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
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(-324L, res.get());
}
Aggregations