use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo in project hive by apache.
the class TestGenericUDFOPMinus method testDateMinusIntervalDayTime.
@Test
public void testDateMinusIntervalDayTime() throws Exception {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
DateWritable left = new DateWritable(Date.valueOf("2001-01-01"));
HiveIntervalDayTimeWritable right = new HiveIntervalDayTimeWritable(HiveIntervalDayTime.valueOf("1 0:0:0.555"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDateObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalDayTimeObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2000-12-30 23:59:59.445"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo in project hive by apache.
the class TestGenericUDFOPMinus method testTimestampMinusIntervalYearMonth.
@Test
public void testTimestampMinusIntervalYearMonth() throws Exception {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
TimestampWritable left = new TimestampWritable(Timestamp.valueOf("2004-01-15 01:02:03.123456789"));
HiveIntervalYearMonthWritable right = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableTimestampObjectInspector, PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2001-11-15 01:02:03.123456789"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo in project hive by apache.
the class TestGenericUDFOPPlus method testIntervalYearMonthPlusTimestamp.
@Test
public void testIntervalYearMonthPlusTimestamp() throws Exception {
GenericUDFOPPlus udf = new GenericUDFOPPlus();
HiveIntervalYearMonthWritable left = new HiveIntervalYearMonthWritable(HiveIntervalYearMonth.valueOf("2-2"));
TimestampWritable right = new TimestampWritable(Timestamp.valueOf("2001-11-15 01:02:03.123456789"));
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveIntervalYearMonthObjectInspector, PrimitiveObjectInspectorFactory.writableTimestampObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.timestampTypeInfo, oi.getTypeInfo());
TimestampWritable res = (TimestampWritable) udf.evaluate(args);
Assert.assertEquals(Timestamp.valueOf("2004-01-15 01:02:03.123456789"), res.getTimestamp());
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo in project hive by apache.
the class MapJoinOneStringKeyBenchBase method doSetup.
public void doSetup(VectorMapJoinVariation vectorMapJoinVariation, MapJoinTestImplementation mapJoinImplementation) throws Exception {
HiveConf hiveConf = new HiveConf();
long seed = 2543;
// 100,000.
int rowCount = 100000;
String[] bigTableColumnNames = new String[] { "b1" };
TypeInfo[] bigTableTypeInfos = new TypeInfo[] { TypeInfoFactory.stringTypeInfo };
int[] bigTableKeyColumnNums = new int[] { 0 };
String[] smallTableValueColumnNames = new String[] { "sv1", "sv2" };
TypeInfo[] smallTableValueTypeInfos = new TypeInfo[] { TypeInfoFactory.dateTypeInfo, TypeInfoFactory.timestampTypeInfo };
int[] bigTableRetainColumnNums = new int[] { 0 };
int[] smallTableRetainKeyColumnNums = new int[] {};
int[] smallTableRetainValueColumnNums = new int[] { 0, 1 };
SmallTableGenerationParameters smallTableGenerationParameters = new SmallTableGenerationParameters();
smallTableGenerationParameters.setValueOption(ValueOption.ONLY_ONE);
setupMapJoin(hiveConf, seed, rowCount, vectorMapJoinVariation, mapJoinImplementation, bigTableColumnNames, bigTableTypeInfos, bigTableKeyColumnNums, smallTableValueColumnNames, smallTableValueTypeInfos, bigTableRetainColumnNums, smallTableRetainKeyColumnNums, smallTableRetainValueColumnNums, smallTableGenerationParameters);
}
use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo in project hive by apache.
the class TestVectorizationContext method testIfConditionalExprs.
/**
* Test that correct VectorExpression classes are chosen for the
* IF (expr1, expr2, expr3) conditional expression for integer, float,
* boolean, timestamp and string input types. expr1 is always an input column expression
* of type long. expr2 and expr3 can be column expressions or constants of other types
* but must have the same type.
*/
@Test
public void testIfConditionalExprs() throws HiveException {
ExprNodeColumnDesc col1Expr = new ExprNodeColumnDesc(Long.class, "col1", "table", false);
ExprNodeColumnDesc col2Expr = new ExprNodeColumnDesc(Long.class, "col2", "table", false);
ExprNodeColumnDesc col3Expr = new ExprNodeColumnDesc(Long.class, "col3", "table", false);
ExprNodeConstantDesc constDesc2 = new ExprNodeConstantDesc(new Integer(1));
ExprNodeConstantDesc constDesc3 = new ExprNodeConstantDesc(new Integer(2));
// long column/column IF
GenericUDFIf udf = new GenericUDFIf();
List<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>();
children1.add(col1Expr);
children1.add(col2Expr);
children1.add(col3Expr);
ExprNodeGenericFuncDesc exprDesc = new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, udf, children1);
List<String> columns = new ArrayList<String>();
columns.add("col0");
columns.add("col1");
columns.add("col2");
columns.add("col3");
VectorizationContext vc = new VectorizationContext("name", columns);
VectorExpression ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongColumnLongColumn);
// long column/scalar IF
children1.set(2, new ExprNodeConstantDesc(1L));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongColumnLongScalar);
// long scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(1L));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongScalarLongScalar);
// long scalar/column IF
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongScalarLongColumn);
// test for double type
col2Expr = new ExprNodeColumnDesc(Double.class, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(Double.class, "col3", "table", false);
// double column/column IF
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprDoubleColumnDoubleColumn);
// double column/scalar IF
children1.set(2, new ExprNodeConstantDesc(1D));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprDoubleColumnDoubleScalar);
// double scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(1D));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprDoubleScalarDoubleScalar);
// double scalar/column IF
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprDoubleScalarDoubleColumn);
// double scalar/long column IF
children1.set(2, new ExprNodeColumnDesc(Long.class, "col3", "table", false));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprDoubleScalarLongColumn);
// Additional combinations of (long,double)X(column,scalar) for each of the second
// and third arguments are omitted. We have coverage of all the source templates
// already.
// test for timestamp type
col2Expr = new ExprNodeColumnDesc(Timestamp.class, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(Timestamp.class, "col3", "table", false);
// timestamp column/column IF
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprTimestampColumnColumn);
// timestamp column/scalar IF where scalar is really a CAST of a constant to timestamp.
ExprNodeGenericFuncDesc f = new ExprNodeGenericFuncDesc();
f.setGenericUDF(new GenericUDFTimestamp());
f.setTypeInfo(TypeInfoFactory.timestampTypeInfo);
List<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
f.setChildren(children2);
children2.add(new ExprNodeConstantDesc("2013-11-05 00:00:00.000"));
children1.set(2, f);
ve = vc.getVectorExpression(exprDesc);
// We check for two different classes below because initially the result
// is IfExprLongColumnLongColumn but in the future if the system is enhanced
// with constant folding then the result will be IfExprLongColumnLongScalar.
assertTrue(IfExprTimestampColumnColumn.class == ve.getClass() || IfExprTimestampColumnScalar.class == ve.getClass());
// timestamp scalar/scalar
children1.set(1, f);
ve = vc.getVectorExpression(exprDesc);
assertTrue(IfExprTimestampColumnColumn.class == ve.getClass() || IfExprTimestampScalarScalar.class == ve.getClass());
// timestamp scalar/column
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(IfExprTimestampColumnColumn.class == ve.getClass() || IfExprTimestampScalarColumn.class == ve.getClass());
// test for boolean type
col2Expr = new ExprNodeColumnDesc(Boolean.class, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(Boolean.class, "col3", "table", false);
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongColumnLongColumn);
// column/scalar IF
children1.set(2, new ExprNodeConstantDesc(true));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongColumnLongScalar);
// scalar/scalar IF
children1.set(1, new ExprNodeConstantDesc(true));
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongScalarLongScalar);
// scalar/column IF
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprLongScalarLongColumn);
// test for string type
constDesc2 = new ExprNodeConstantDesc("Alpha");
constDesc3 = new ExprNodeConstantDesc("Bravo");
col2Expr = new ExprNodeColumnDesc(String.class, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(String.class, "col3", "table", false);
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnStringGroupColumn);
// column/scalar
children1.set(2, constDesc3);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnStringScalar);
// scalar/scalar
children1.set(1, constDesc2);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringScalarStringScalar);
// scalar/column
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringScalarStringGroupColumn);
// test for CHAR type
CharTypeInfo charTypeInfo = new CharTypeInfo(10);
constDesc2 = new ExprNodeConstantDesc(charTypeInfo, new HiveChar("Alpha", 10));
constDesc3 = new ExprNodeConstantDesc(charTypeInfo, new HiveChar("Bravo", 10));
col2Expr = new ExprNodeColumnDesc(charTypeInfo, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(charTypeInfo, "col3", "table", false);
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnStringGroupColumn);
// column/scalar
children1.set(2, constDesc3);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnCharScalar);
// scalar/scalar
children1.set(1, constDesc2);
// ve = vc.getVectorExpression(exprDesc);
// assertTrue(ve instanceof IfExprCharScalarCharScalar);
// scalar/column
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprCharScalarStringGroupColumn);
// test for VARCHAR type
VarcharTypeInfo varcharTypeInfo = new VarcharTypeInfo(10);
constDesc2 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Alpha", 10));
constDesc3 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Bravo", 10));
col2Expr = new ExprNodeColumnDesc(varcharTypeInfo, "col2", "table", false);
col3Expr = new ExprNodeColumnDesc(varcharTypeInfo, "col3", "table", false);
// column/column
children1.set(1, col2Expr);
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnStringGroupColumn);
// column/scalar
children1.set(2, constDesc3);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprStringGroupColumnVarCharScalar);
// scalar/scalar
children1.set(1, constDesc2);
// ve = vc.getVectorExpression(exprDesc);
// assertTrue(ve instanceof IfExprVarCharScalarVarCharScalar);
// scalar/column
children1.set(2, col3Expr);
ve = vc.getVectorExpression(exprDesc);
assertTrue(ve instanceof IfExprVarCharScalarStringGroupColumn);
}
Aggregations