You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by mm...@apache.org on 2016/04/19 12:13:06 UTC
[12/20] hive git commit: HIVE-9862 Vectorized execution corrupts
timestamp values (Matt McCline,
reviewed by Jason Dere) HIVE-13111: Fix timestamp / interval_day_time wrong
results with HIVE-9862 (Matt McCline, reviewed by Jason Dere)
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
index 43c7f3d..0ce1660 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java
@@ -53,20 +53,27 @@ import org.apache.hadoop.hive.ql.exec.vector.expressions.*;
import org.apache.hadoop.hive.ql.exec.vector.AggregateDefinition;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFAvgDecimal;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFAvgTimestamp;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCount;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCountMerge;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFCountStar;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFStdPopTimestamp;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFStdSampTimestamp;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFSumDecimal;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFVarPopTimestamp;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorUDAFVarSampTimestamp;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFAvgDouble;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFAvgLong;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxDecimal;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxDouble;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxLong;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxString;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMaxTimestamp;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinDecimal;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinDouble;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinLong;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinString;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFMinTimestamp;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdPopDecimal;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdPopDouble;
import org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.gen.VectorUDAFStdPopLong;
@@ -933,20 +940,16 @@ public class VectorizationContext {
case DATE:
return new ConstantVectorExpression(outCol, DateWritable.dateToDays((Date) constantValue));
case TIMESTAMP:
- return new ConstantVectorExpression(outCol, TimestampUtils.getTimeNanoSec((Timestamp) constantValue));
+ return new ConstantVectorExpression(outCol, (Timestamp) constantValue);
case INTERVAL_YEAR_MONTH:
return new ConstantVectorExpression(outCol,
((HiveIntervalYearMonth) constantValue).getTotalMonths());
case INTERVAL_DAY_TIME:
- return new ConstantVectorExpression(outCol,
- DateUtils.getIntervalDayTimeTotalNanos((HiveIntervalDayTime) constantValue));
+ return new ConstantVectorExpression(outCol, (HiveIntervalDayTime) constantValue);
case FLOAT_FAMILY:
return new ConstantVectorExpression(outCol, ((Number) constantValue).doubleValue());
case DECIMAL:
- VectorExpression ve = new ConstantVectorExpression(outCol, (HiveDecimal) constantValue);
- // Set type name with decimal precision, scale, etc.
- ve.setOutputType(typeName);
- return ve;
+ return new ConstantVectorExpression(outCol, (HiveDecimal) constantValue, typeName);
case STRING:
return new ConstantVectorExpression(outCol, ((String) constantValue).getBytes());
case CHAR:
@@ -1243,8 +1246,8 @@ public class VectorizationContext {
VectorExpression ve = getVectorExpressionForUdf(udf, udf.getClass(), childExpr, mode, returnType);
// Replace with the milliseconds conversion
- if (!udf.isIntToTimestampInSeconds() && ve instanceof CastLongToTimestampViaLongToLong) {
- ve = createVectorExpression(CastMillisecondsLongToTimestampViaLongToLong.class,
+ if (!udf.isIntToTimestampInSeconds() && ve instanceof CastLongToTimestamp) {
+ ve = createVectorExpression(CastMillisecondsLongToTimestamp.class,
childExpr, Mode.PROJECTION, returnType);
}
@@ -1529,13 +1532,13 @@ public class VectorizationContext {
expr = createVectorExpression(cl, childExpr.subList(0, 1), Mode.PROJECTION, returnType);
((ILongInExpr) expr).setInListValues(inVals);
} else if (isTimestampFamily(colType)) {
- cl = (mode == Mode.FILTER ? FilterLongColumnInList.class : LongColumnInList.class);
- long[] inVals = new long[childrenForInList.size()];
+ cl = (mode == Mode.FILTER ? FilterTimestampColumnInList.class : TimestampColumnInList.class);
+ Timestamp[] inVals = new Timestamp[childrenForInList.size()];
for (int i = 0; i != inVals.length; i++) {
inVals[i] = getTimestampScalar(childrenForInList.get(i));
}
expr = createVectorExpression(cl, childExpr.subList(0, 1), Mode.PROJECTION, returnType);
- ((ILongInExpr) expr).setInListValues(inVals);
+ ((ITimestampInExpr) expr).setInListValues(inVals);
} else if (isStringFamily(colType)) {
cl = (mode == Mode.FILTER ? FilterStringColumnInList.class : StringColumnInList.class);
byte[][] inVals = new byte[childrenForInList.size()][];
@@ -1835,7 +1838,7 @@ public class VectorizationContext {
if (isIntFamily(inputType)) {
return createVectorExpression(CastLongToDouble.class, childExpr, Mode.PROJECTION, returnType);
} else if (inputType.equals("timestamp")) {
- return createVectorExpression(CastTimestampToDoubleViaLongToDouble.class, childExpr, Mode.PROJECTION,
+ return createVectorExpression(CastTimestampToDouble.class, childExpr, Mode.PROJECTION,
returnType);
} else if (isFloatFamily(inputType)) {
@@ -1979,20 +1982,10 @@ public class VectorizationContext {
cl = FilterCharColumnBetween.class;
} else if (charTypePattern.matcher(colType).matches() && notKeywordPresent) {
cl = FilterCharColumnNotBetween.class;
- } else if (colType.equals("timestamp")) {
-
- // Get timestamp boundary values as longs instead of the expected strings
- long left = getTimestampScalar(childExpr.get(2));
- long right = getTimestampScalar(childExpr.get(3));
- childrenAfterNot = new ArrayList<ExprNodeDesc>();
- childrenAfterNot.add(colExpr);
- childrenAfterNot.add(new ExprNodeConstantDesc(left));
- childrenAfterNot.add(new ExprNodeConstantDesc(right));
- if (notKeywordPresent) {
- cl = FilterLongColumnNotBetween.class;
- } else {
- cl = FilterLongColumnBetween.class;
- }
+ } else if (colType.equals("timestamp") && !notKeywordPresent) {
+ cl = FilterTimestampColumnBetween.class;
+ } else if (colType.equals("timestamp") && notKeywordPresent) {
+ cl = FilterTimestampColumnNotBetween.class;
} else if (isDecimalFamily(colType) && !notKeywordPresent) {
cl = FilterDecimalColumnBetween.class;
} else if (isDecimalFamily(colType) && notKeywordPresent) {
@@ -2062,6 +2055,7 @@ public class VectorizationContext {
// Make vectorized operator
String normalizedName = getNormalizedName(resultTypeName);
+
VectorExpression ve = new VectorUDFAdaptor(expr, outputCol, normalizedName, argDescs);
// Set child expressions
@@ -2179,21 +2173,17 @@ public class VectorizationContext {
VectorExpression.Type type = VectorExpression.Type.getValue(t);
Object scalarValue = getScalarValue(constDesc);
switch (type) {
- case TIMESTAMP:
- return TimestampUtils.getTimeNanoSec((Timestamp) scalarValue);
case DATE:
return DateWritable.dateToDays((Date) scalarValue);
case INTERVAL_YEAR_MONTH:
return ((HiveIntervalYearMonth) scalarValue).getTotalMonths();
- case INTERVAL_DAY_TIME:
- return DateUtils.getIntervalDayTimeTotalNanos((HiveIntervalDayTime) scalarValue);
default:
return scalarValue;
}
}
- // Get a timestamp as a long in number of nanos, from a string constant or cast
- private long getTimestampScalar(ExprNodeDesc expr) throws HiveException {
+ // Get a timestamp from a string constant or cast
+ private Timestamp getTimestampScalar(ExprNodeDesc expr) throws HiveException {
if (expr instanceof ExprNodeGenericFuncDesc &&
((ExprNodeGenericFuncDesc) expr).getGenericUDF() instanceof GenericUDFTimestamp) {
return evaluateCastToTimestamp(expr);
@@ -2221,7 +2211,7 @@ public class VectorizationContext {
+ "Expecting string.");
}
- private long evaluateCastToTimestamp(ExprNodeDesc expr) throws HiveException {
+ private Timestamp evaluateCastToTimestamp(ExprNodeDesc expr) throws HiveException {
ExprNodeGenericFuncDesc expr2 = (ExprNodeGenericFuncDesc) expr;
ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(expr2);
ObjectInspector output = evaluator.initialize(null);
@@ -2232,7 +2222,7 @@ public class VectorizationContext {
throw new HiveException("Udf: failed to convert to timestamp");
}
Timestamp ts = (Timestamp) java;
- return TimestampUtils.getTimeNanoSec(ts);
+ return ts;
}
private Constructor<?> getConstructor(Class<?> cl) throws HiveException {
@@ -2321,7 +2311,7 @@ public class VectorizationContext {
}
}
- public static ColumnVector.Type getColumnVectorTypeFromTypeInfo(TypeInfo typeInfo) throws HiveException {
+ public static ColumnVector.Type getColumnVectorTypeFromTypeInfo(TypeInfo typeInfo) {
switch (typeInfo.getCategory()) {
case STRUCT:
return Type.STRUCT;
@@ -2342,11 +2332,15 @@ public class VectorizationContext {
case INT:
case LONG:
case DATE:
- case TIMESTAMP:
case INTERVAL_YEAR_MONTH:
- case INTERVAL_DAY_TIME:
return ColumnVector.Type.LONG;
+ case TIMESTAMP:
+ return ColumnVector.Type.TIMESTAMP;
+
+ case INTERVAL_DAY_TIME:
+ return ColumnVector.Type.INTERVAL_DAY_TIME;
+
case FLOAT:
case DOUBLE:
return ColumnVector.Type.DOUBLE;
@@ -2375,47 +2369,59 @@ public class VectorizationContext {
// TODO: And, investigate if different reduce-side versions are needed for var* and std*, or if map-side aggregate can be used.. Right now they are conservatively
// marked map-side (HASH).
static ArrayList<AggregateDefinition> aggregatesDefinition = new ArrayList<AggregateDefinition>() {{
- add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.INT_DATETIME_INTERVAL_FAMILY, null, VectorUDAFMinLong.class));
+ add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.INT_DATE_INTERVAL_YEAR_MONTH, null, VectorUDAFMinLong.class));
add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, null, VectorUDAFMinDouble.class));
add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.STRING_FAMILY, null, VectorUDAFMinString.class));
add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.DECIMAL, null, VectorUDAFMinDecimal.class));
- add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.INT_DATETIME_INTERVAL_FAMILY, null, VectorUDAFMaxLong.class));
+ add(new AggregateDefinition("min", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, null, VectorUDAFMinTimestamp.class));
+ add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.INT_DATE_INTERVAL_YEAR_MONTH, null, VectorUDAFMaxLong.class));
add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, null, VectorUDAFMaxDouble.class));
add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.STRING_FAMILY, null, VectorUDAFMaxString.class));
add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.DECIMAL, null, VectorUDAFMaxDecimal.class));
+ add(new AggregateDefinition("max", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, null, VectorUDAFMaxTimestamp.class));
add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.NONE, GroupByDesc.Mode.HASH, VectorUDAFCountStar.class));
- add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.INT_DATETIME_INTERVAL_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
+ add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.INT_DATE_INTERVAL_YEAR_MONTH, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.MERGEPARTIAL, VectorUDAFCountMerge.class));
add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.STRING_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
+ add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
+ add(new AggregateDefinition("count", VectorExpressionDescriptor.ArgumentType.INTERVAL_DAY_TIME, GroupByDesc.Mode.HASH, VectorUDAFCount.class));
add(new AggregateDefinition("sum", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, null, VectorUDAFSumLong.class));
add(new AggregateDefinition("sum", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, null, VectorUDAFSumDouble.class));
add(new AggregateDefinition("sum", VectorExpressionDescriptor.ArgumentType.DECIMAL, null, VectorUDAFSumDecimal.class));
- add(new AggregateDefinition("avg", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFAvgLong.class));
+ add(new AggregateDefinition("avg", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFAvgLong.class));
add(new AggregateDefinition("avg", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFAvgDouble.class));
add(new AggregateDefinition("avg", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFAvgDecimal.class));
- add(new AggregateDefinition("variance", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopLong.class));
- add(new AggregateDefinition("var_pop", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopLong.class));
+ add(new AggregateDefinition("avg", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFAvgTimestamp.class));
+ add(new AggregateDefinition("variance", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopLong.class));
+ add(new AggregateDefinition("var_pop", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopLong.class));
add(new AggregateDefinition("variance", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopDouble.class));
add(new AggregateDefinition("var_pop", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarPopDouble.class));
add(new AggregateDefinition("variance", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFVarPopDecimal.class));
add(new AggregateDefinition("var_pop", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFVarPopDecimal.class));
- add(new AggregateDefinition("var_samp", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarSampLong.class));
+ add(new AggregateDefinition("variance", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFVarPopTimestamp.class));
+ add(new AggregateDefinition("var_pop", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFVarPopTimestamp.class));
+ add(new AggregateDefinition("var_samp", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarSampLong.class));
add(new AggregateDefinition("var_samp" , VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFVarSampDouble.class));
add(new AggregateDefinition("var_samp" , VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFVarSampDecimal.class));
- add(new AggregateDefinition("std", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
- add(new AggregateDefinition("stddev", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
- add(new AggregateDefinition("stddev_pop", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
+ add(new AggregateDefinition("var_samp" , VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFVarSampTimestamp.class));
+ add(new AggregateDefinition("std", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
+ add(new AggregateDefinition("stddev", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
+ add(new AggregateDefinition("stddev_pop", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopLong.class));
add(new AggregateDefinition("std", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopDouble.class));
add(new AggregateDefinition("stddev", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopDouble.class));
add(new AggregateDefinition("stddev_pop", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdPopDouble.class));
add(new AggregateDefinition("std", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFStdPopDecimal.class));
add(new AggregateDefinition("stddev", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFStdPopDecimal.class));
add(new AggregateDefinition("stddev_pop", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFStdPopDecimal.class));
- add(new AggregateDefinition("stddev_samp", VectorExpressionDescriptor.ArgumentType.INT_TIMESTAMP_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdSampLong.class));
+ add(new AggregateDefinition("std", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFStdPopTimestamp.class));
+ add(new AggregateDefinition("stddev", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFStdPopTimestamp.class));
+ add(new AggregateDefinition("stddev_pop", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFStdPopTimestamp.class));
+ add(new AggregateDefinition("stddev_samp", VectorExpressionDescriptor.ArgumentType.INT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdSampLong.class));
add(new AggregateDefinition("stddev_samp", VectorExpressionDescriptor.ArgumentType.FLOAT_FAMILY, GroupByDesc.Mode.HASH, VectorUDAFStdSampDouble.class));
add(new AggregateDefinition("stddev_samp", VectorExpressionDescriptor.ArgumentType.DECIMAL, GroupByDesc.Mode.HASH, VectorUDAFStdSampDecimal.class));
+ add(new AggregateDefinition("stddev_samp", VectorExpressionDescriptor.ArgumentType.TIMESTAMP, GroupByDesc.Mode.HASH, VectorUDAFStdSampTimestamp.class));
}};
public VectorAggregateExpression getAggregatorExpression(AggregationDesc desc, boolean isReduce)
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java
index d258e2d..1482855 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java
@@ -138,11 +138,13 @@ public class VectorizedBatchUtil {
case SHORT:
case INT:
case LONG:
- case TIMESTAMP:
case DATE:
case INTERVAL_YEAR_MONTH:
- case INTERVAL_DAY_TIME:
return new LongColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
+ case TIMESTAMP:
+ return new TimestampColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
+ case INTERVAL_DAY_TIME:
+ return new IntervalDayTimeColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
case FLOAT:
case DOUBLE:
return new DoubleColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
@@ -390,13 +392,12 @@ public class VectorizedBatchUtil {
}
break;
case TIMESTAMP: {
- LongColumnVector lcv = (LongColumnVector) batch.cols[offset + colIndex];
+ TimestampColumnVector lcv = (TimestampColumnVector) batch.cols[offset + colIndex];
if (writableCol != null) {
- Timestamp t = ((TimestampWritable) writableCol).getTimestamp();
- lcv.vector[rowIndex] = TimestampUtils.getTimeNanoSec(t);
+ lcv.set(rowIndex, ((TimestampWritable) writableCol).getTimestamp());
lcv.isNull[rowIndex] = false;
} else {
- lcv.vector[rowIndex] = 1;
+ lcv.setNullValue(rowIndex);
setNullColIsNullValue(lcv, rowIndex);
}
}
@@ -414,14 +415,14 @@ public class VectorizedBatchUtil {
}
break;
case INTERVAL_DAY_TIME: {
- LongColumnVector lcv = (LongColumnVector) batch.cols[offset + colIndex];
+ IntervalDayTimeColumnVector icv = (IntervalDayTimeColumnVector) batch.cols[offset + colIndex];
if (writableCol != null) {
- HiveIntervalDayTime i = ((HiveIntervalDayTimeWritable) writableCol).getHiveIntervalDayTime();
- lcv.vector[rowIndex] = DateUtils.getIntervalDayTimeTotalNanos(i);
- lcv.isNull[rowIndex] = false;
+ HiveIntervalDayTime idt = ((HiveIntervalDayTimeWritable) writableCol).getHiveIntervalDayTime();
+ icv.set(rowIndex, idt);
+ icv.isNull[rowIndex] = false;
} else {
- lcv.vector[rowIndex] = 1;
- setNullColIsNullValue(lcv, rowIndex);
+ icv.setNullValue(rowIndex);
+ setNullColIsNullValue(icv, rowIndex);
}
}
break;
@@ -580,6 +581,10 @@ public class VectorizedBatchUtil {
return new DecimalColumnVector(decColVector.vector.length,
decColVector.precision,
decColVector.scale);
+ } else if (source instanceof TimestampColumnVector) {
+ return new TimestampColumnVector(((TimestampColumnVector) source).getLength());
+ } else if (source instanceof IntervalDayTimeColumnVector) {
+ return new IntervalDayTimeColumnVector(((IntervalDayTimeColumnVector) source).getLength());
} else if (source instanceof ListColumnVector) {
ListColumnVector src = (ListColumnVector) source;
ColumnVector child = cloneColumnVector(src.child);
@@ -623,7 +628,8 @@ public class VectorizedBatchUtil {
newBatch.cols[i].init();
}
}
- newBatch.projectedColumns = Arrays.copyOf(batch.projectedColumns, batch.projectedColumns.length);
+ newBatch.projectedColumns = Arrays.copyOf(batch.projectedColumns,
+ batch.projectedColumns.length);
newBatch.projectionSize = batch.projectionSize;
newBatch.reset();
return newBatch;
@@ -678,6 +684,13 @@ public class VectorizedBatchUtil {
}
} else if (colVector instanceof DecimalColumnVector) {
sb.append(((DecimalColumnVector) colVector).vector[index].toString());
+ } else if (colVector instanceof TimestampColumnVector) {
+ Timestamp timestamp = new Timestamp(0);
+ ((TimestampColumnVector) colVector).timestampUpdate(timestamp, index);
+ sb.append(timestamp.toString());
+ } else if (colVector instanceof IntervalDayTimeColumnVector) {
+ HiveIntervalDayTime intervalDayTime = ((IntervalDayTimeColumnVector) colVector).asScratchIntervalDayTime(index);
+ sb.append(intervalDayTime.toString());
} else {
sb.append("Unknown");
}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedRowBatchCtx.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedRowBatchCtx.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedRowBatchCtx.java
index efb06b2..014f097 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedRowBatchCtx.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedRowBatchCtx.java
@@ -375,13 +375,13 @@ public class VectorizedRowBatchCtx {
break;
case TIMESTAMP: {
- LongColumnVector lcv = (LongColumnVector) batch.cols[colIndex];
+ TimestampColumnVector lcv = (TimestampColumnVector) batch.cols[colIndex];
if (value == null) {
lcv.noNulls = false;
lcv.isNull[0] = true;
lcv.isRepeating = true;
- } else {
- lcv.fill(TimestampUtils.getTimeNanoSec((Timestamp) value));
+ } else {
+ lcv.fill((Timestamp) value);
lcv.isNull[0] = false;
}
}
@@ -400,14 +400,14 @@ public class VectorizedRowBatchCtx {
}
case INTERVAL_DAY_TIME: {
- LongColumnVector lcv = (LongColumnVector) batch.cols[colIndex];
+ IntervalDayTimeColumnVector icv = (IntervalDayTimeColumnVector) batch.cols[colIndex];
if (value == null) {
- lcv.noNulls = false;
- lcv.isNull[0] = true;
- lcv.isRepeating = true;
+ icv.noNulls = false;
+ icv.isNull[0] = true;
+ icv.isRepeating = true;
} else {
- lcv.fill(DateUtils.getIntervalDayTimeTotalNanos((HiveIntervalDayTime) value));
- lcv.isNull[0] = false;
+ icv.fill(((HiveIntervalDayTime) value));
+ icv.isNull[0] = false;
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDecimalToTimestamp.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDecimalToTimestamp.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDecimalToTimestamp.java
index a52cf19..6225ade 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDecimalToTimestamp.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDecimalToTimestamp.java
@@ -18,20 +18,23 @@
package org.apache.hadoop.hive.ql.exec.vector.expressions;
+import java.sql.Timestamp;
+
import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampUtils;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
/**
* Type cast decimal to timestamp. The decimal value is interpreted
* as NNNN.DDDDDDDDD where NNNN is a number of seconds and DDDDDDDDD
* is a number of nano-seconds.
*/
-public class CastDecimalToTimestamp extends FuncDecimalToLong {
+public class CastDecimalToTimestamp extends FuncDecimalToTimestamp {
private static final long serialVersionUID = 1L;
- private static transient HiveDecimal tenE9 = HiveDecimal.create(1000000000);
-
public CastDecimalToTimestamp(int inputColumn, int outputColumn) {
super(inputColumn, outputColumn);
}
@@ -40,13 +43,7 @@ public class CastDecimalToTimestamp extends FuncDecimalToLong {
}
@Override
- protected void func(LongColumnVector outV, DecimalColumnVector inV, int i) {
- HiveDecimal result = inV.vector[i].getHiveDecimal().multiply(tenE9);
- if (result == null) {
- outV.noNulls = false;
- outV.isNull[i] = true;
- } else {
- outV.vector[i] = result.longValue();
- }
+ protected void func(TimestampColumnVector outV, DecimalColumnVector inV, int i) {
+ outV.set(i, TimestampWritable.decimalToTimestamp(inV.vector[i].getHiveDecimal()));
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDoubleToTimestamp.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDoubleToTimestamp.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDoubleToTimestamp.java
new file mode 100644
index 0000000..31d2f78
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastDoubleToTimestamp.java
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+
+public class CastDoubleToTimestamp extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastDoubleToTimestamp(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastDoubleToTimestamp() {
+ super();
+ }
+
+ private void setDouble(TimestampColumnVector timestampColVector,
+ double[] vector, int elementNum) {
+ TimestampWritable.setTimestampFromDouble(
+ timestampColVector.getScratchTimestamp(), vector[elementNum]);
+ timestampColVector.setFromScratchTimestamp(elementNum);
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ DoubleColumnVector inputColVector = (DoubleColumnVector) batch.cols[colNum];
+ TimestampColumnVector outputColVector = (TimestampColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ double[] vector = inputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ setDouble(outputColVector, vector, 0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setDouble(outputColVector, vector, i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setDouble(outputColVector, vector, i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setDouble(outputColVector, vector, i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setDouble(outputColVector, vector, i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "timestamp";
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("double"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToDate.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToDate.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToDate.java
index 32cefea..ceefd61 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToDate.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToDate.java
@@ -63,62 +63,6 @@ public class CastLongToDate extends VectorExpression {
}
switch (inputTypes[0]) {
- case TIMESTAMP:
- if (inV.noNulls) {
- outV.noNulls = true;
- if (inV.isRepeating) {
- outV.isRepeating = true;
- date.setTime(inV.vector[0] / 1000000);
- outV.vector[0] = DateWritable.dateToDays(date);
- } else if (batch.selectedInUse) {
- for(int j = 0; j != n; j++) {
- int i = sel[j];
- date.setTime(inV.vector[i] / 1000000);
- outV.vector[i] = DateWritable.dateToDays(date);
- }
- outV.isRepeating = false;
- } else {
- for(int i = 0; i != n; i++) {
- date.setTime(inV.vector[i] / 1000000);
- outV.vector[i] = DateWritable.dateToDays(date);
- }
- outV.isRepeating = false;
- }
- } else {
-
- // Handle case with nulls. Don't do function if the value is null,
- // because the data may be undefined for a null value.
- outV.noNulls = false;
- if (inV.isRepeating) {
- outV.isRepeating = true;
- outV.isNull[0] = inV.isNull[0];
- if (!inV.isNull[0]) {
- date.setTime(inV.vector[0] / 1000000);
- outV.vector[0] = DateWritable.dateToDays(date);
- }
- } else if (batch.selectedInUse) {
- for(int j = 0; j != n; j++) {
- int i = sel[j];
- outV.isNull[i] = inV.isNull[i];
- if (!inV.isNull[i]) {
- date.setTime(inV.vector[i] / 1000000);
- outV.vector[i] = DateWritable.dateToDays(date);
- }
- }
- outV.isRepeating = false;
- } else {
- System.arraycopy(inV.isNull, 0, outV.isNull, 0, n);
- for(int i = 0; i != n; i++) {
- if (!inV.isNull[i]) {
- date.setTime(inV.vector[i] / 1000000);
- outV.vector[i] = DateWritable.dateToDays(date);
- }
- }
- outV.isRepeating = false;
- }
- }
- break;
-
case DATE:
inV.copySelected(batch.selectedInUse, batch.selected, batch.size, outV);
break;
@@ -155,7 +99,7 @@ public class CastLongToDate extends VectorExpression {
b.setMode(VectorExpressionDescriptor.Mode.PROJECTION)
.setNumArguments(1)
.setArgumentTypes(
- VectorExpressionDescriptor.ArgumentType.DATETIME_FAMILY)
+ VectorExpressionDescriptor.ArgumentType.DATE)
.setInputExpressionTypes(
VectorExpressionDescriptor.InputExpressionType.COLUMN);
return b.build();
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToTimestamp.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToTimestamp.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToTimestamp.java
new file mode 100644
index 0000000..a2ee52d
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastLongToTimestamp.java
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+
+public class CastLongToTimestamp extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastLongToTimestamp(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastLongToTimestamp() {
+ super();
+ }
+
+ private void setSeconds(TimestampColumnVector timestampColVector, long[] vector, int elementNum) {
+ TimestampWritable.setTimestampFromLong(
+ timestampColVector.getScratchTimestamp(), vector[elementNum],
+ /* intToTimestampInSeconds */ true);
+ timestampColVector.setFromScratchTimestamp(elementNum);
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ LongColumnVector inputColVector = (LongColumnVector) batch.cols[colNum];
+ TimestampColumnVector outputColVector = (TimestampColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ long[] vector = inputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ setSeconds(outputColVector, vector, 0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setSeconds(outputColVector, vector, i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setSeconds(outputColVector, vector, i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setSeconds(outputColVector, vector, i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setSeconds(outputColVector, vector, i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "timestamp";
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("long"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastMillisecondsLongToTimestamp.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastMillisecondsLongToTimestamp.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastMillisecondsLongToTimestamp.java
new file mode 100644
index 0000000..01c8810
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastMillisecondsLongToTimestamp.java
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+
+public class CastMillisecondsLongToTimestamp extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastMillisecondsLongToTimestamp(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastMillisecondsLongToTimestamp() {
+ super();
+ }
+
+ private void setMilliseconds(TimestampColumnVector timestampColVector, long[] vector, int elementNum) {
+ TimestampWritable.setTimestampFromLong(
+ timestampColVector.getScratchTimestamp(), vector[elementNum],
+ /* intToTimestampInSeconds */ false);
+ timestampColVector.setFromScratchTimestamp(elementNum);
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ LongColumnVector inputColVector = (LongColumnVector) batch.cols[colNum];
+ TimestampColumnVector outputColVector = (TimestampColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ long[] vector = inputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ setMilliseconds(outputColVector, vector, 0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setMilliseconds(outputColVector, vector, i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setMilliseconds(outputColVector, vector, i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ setMilliseconds(outputColVector, vector, i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ setMilliseconds(outputColVector, vector, i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "timestamp";
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("long"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastStringToIntervalDayTime.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastStringToIntervalDayTime.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastStringToIntervalDayTime.java
index 518d5d5..c8844c8 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastStringToIntervalDayTime.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastStringToIntervalDayTime.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hive.ql.exec.vector.expressions;
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.IntervalDayTimeColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor;
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.hadoop.hive.serde.serdeConstants;
@@ -55,7 +56,7 @@ public class CastStringToIntervalDayTime extends VectorExpression {
BytesColumnVector inV = (BytesColumnVector) batch.cols[inputColumn];
int[] sel = batch.selected;
int n = batch.size;
- LongColumnVector outV = (LongColumnVector) batch.cols[outputColumn];
+ IntervalDayTimeColumnVector outV = (IntervalDayTimeColumnVector) batch.cols[outputColumn];
if (n == 0) {
@@ -112,13 +113,13 @@ public class CastStringToIntervalDayTime extends VectorExpression {
}
}
- private void evaluate(LongColumnVector outV, BytesColumnVector inV, int i) {
+ private void evaluate(IntervalDayTimeColumnVector outV, BytesColumnVector inV, int i) {
try {
HiveIntervalDayTime interval = HiveIntervalDayTime.valueOf(
new String(inV.vector[i], inV.start[i], inV.length[i], "UTF-8"));
- outV.vector[i] = DateUtils.getIntervalDayTimeTotalNanos(interval);
+ outV.set(i, interval);
} catch (Exception e) {
- outV.vector[i] = 1;
+ outV.setNullValue(i);
outV.isNull[i] = true;
outV.noNulls = false;
}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToBoolean.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToBoolean.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToBoolean.java
new file mode 100644
index 0000000..b8a58cd
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToBoolean.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.MathExpr;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor;
+
+public class CastTimestampToBoolean extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastTimestampToBoolean(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastTimestampToBoolean() {
+ super();
+ }
+
+ private int toBool(TimestampColumnVector timestampColVector, int index) {
+ return (timestampColVector.getTime(index) != 0 ||
+ timestampColVector.getNanos(index) != 0) ? 1 : 0;
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ TimestampColumnVector inputColVector = (TimestampColumnVector) batch.cols[colNum];
+ LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ long[] outputVector = outputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ outputVector[0] = toBool(inputColVector, 0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = toBool(inputColVector, i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = toBool(inputColVector, i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = toBool(inputColVector, i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = toBool(inputColVector, i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "long";
+ }
+
+ public int getColNum() {
+ return colNum;
+ }
+
+ public void setColNum(int colNum) {
+ this.colNum = colNum;
+ }
+
+ public void setOutputColumn(int outputColumn) {
+ this.outputColumn = outputColumn;
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("timestamp"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDate.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDate.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDate.java
new file mode 100644
index 0000000..4e3e62c
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDate.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+
+/**
+ * To be used to cast timestamp to decimal.
+ */
+public class CastTimestampToDate extends FuncTimestampToLong {
+
+ private static final long serialVersionUID = 1L;
+
+ public CastTimestampToDate() {
+ super();
+ this.outputType = "date";
+ }
+
+ public CastTimestampToDate(int inputColumn, int outputColumn) {
+ super(inputColumn, outputColumn);
+ this.outputType = "date";
+ }
+
+ @Override
+ protected void func(LongColumnVector outV, TimestampColumnVector inV, int i) {
+
+ outV.vector[i] = DateWritable.millisToDays(inV.getTime(i));
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDecimal.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDecimal.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDecimal.java
index 0aedddc..e5bfb15 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDecimal.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDecimal.java
@@ -18,14 +18,14 @@
package org.apache.hadoop.hive.ql.exec.vector.expressions;
-import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
-import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
/**
* To be used to cast timestamp to decimal.
*/
-public class CastTimestampToDecimal extends FuncLongToDecimal {
+public class CastTimestampToDecimal extends FuncTimestampToDecimal {
private static final long serialVersionUID = 1L;
@@ -38,12 +38,7 @@ public class CastTimestampToDecimal extends FuncLongToDecimal {
}
@Override
- protected void func(DecimalColumnVector outV, LongColumnVector inV, int i) {
-
- // The resulting decimal value is 10e-9 * the input long value (i.e. seconds).
- //
- HiveDecimal result = HiveDecimal.create(inV.vector[i]);
- result = result.scaleByPowerOfTen(-9);
- outV.set(i, result);
+ protected void func(DecimalColumnVector outV, TimestampColumnVector inV, int i) {
+ outV.set(i, TimestampWritable.getHiveDecimal(inV.asScratchTimestamp(i)));
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDouble.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDouble.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDouble.java
new file mode 100644
index 0000000..a955d79
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToDouble.java
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+
+public class CastTimestampToDouble extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastTimestampToDouble(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastTimestampToDouble() {
+ super();
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ TimestampColumnVector inputColVector = (TimestampColumnVector) batch.cols[colNum];
+ DoubleColumnVector outputColVector = (DoubleColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ double[] outputVector = outputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ outputVector[0] = inputColVector.getDouble(0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = inputColVector.getDouble(i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = inputColVector.getDouble(i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = inputColVector.getDouble(i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = inputColVector.getDouble(i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "double";
+ }
+
+ public int getColNum() {
+ return colNum;
+ }
+
+ public void setColNum(int colNum) {
+ this.colNum = colNum;
+ }
+
+ public void setOutputColumn(int outputColumn) {
+ this.outputColumn = outputColumn;
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("timestamp"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToLong.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToLong.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToLong.java
new file mode 100644
index 0000000..ba2e823
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/CastTimestampToLong.java
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.MathExpr;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor;
+
+public class CastTimestampToLong extends VectorExpression {
+ private static final long serialVersionUID = 1L;
+
+ private int colNum;
+ private int outputColumn;
+
+ public CastTimestampToLong(int colNum, int outputColumn) {
+ this();
+ this.colNum = colNum;
+ this.outputColumn = outputColumn;
+ }
+
+ public CastTimestampToLong() {
+ super();
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ this.evaluateChildren(batch);
+ }
+
+ TimestampColumnVector inputColVector = (TimestampColumnVector) batch.cols[colNum];
+ LongColumnVector outputColVector = (LongColumnVector) batch.cols[outputColumn];
+ int[] sel = batch.selected;
+ boolean[] inputIsNull = inputColVector.isNull;
+ boolean[] outputIsNull = outputColVector.isNull;
+ outputColVector.noNulls = inputColVector.noNulls;
+ int n = batch.size;
+ long[] outputVector = outputColVector.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ if (inputColVector.isRepeating) {
+ //All must be selected otherwise size would be zero
+ //Repeating property will not change.
+ outputVector[0] = inputColVector.getTimestampAsLong(0);
+ // Even if there are no nulls, we always copy over entry 0. Simplifies code.
+ outputIsNull[0] = inputIsNull[0];
+ outputColVector.isRepeating = true;
+ } else if (inputColVector.noNulls) {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = inputColVector.getTimestampAsLong(i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = inputColVector.getTimestampAsLong(i);
+ }
+ }
+ outputColVector.isRepeating = false;
+ } else /* there are nulls */ {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ outputVector[i] = inputColVector.getTimestampAsLong(i);
+ outputIsNull[i] = inputIsNull[i];
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ outputVector[i] = inputColVector.getTimestampAsLong(i);
+ }
+ System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
+ }
+ outputColVector.isRepeating = false;
+ }
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "long";
+ }
+
+ public int getColNum() {
+ return colNum;
+ }
+
+ public void setColNum(int colNum) {
+ this.colNum = colNum;
+ }
+
+ public void setOutputColumn(int outputColumn) {
+ this.outputColumn = outputColumn;
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(1)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("timestamp"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java
index 8d75cf3..8a743f6 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java
@@ -18,10 +18,15 @@
package org.apache.hadoop.hive.ql.exec.vector.expressions;
+import java.sql.Timestamp;
+
import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.common.type.HiveChar;
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
import org.apache.hadoop.hive.common.type.HiveVarchar;
import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
/**
* Constant is represented as a vector with repeating values.
@@ -30,21 +35,16 @@ public class ConstantVectorExpression extends VectorExpression {
private static final long serialVersionUID = 1L;
- private static enum Type {
- LONG,
- DOUBLE,
- BYTES,
- DECIMAL
- }
-
private int outputColumn;
protected long longValue = 0;
private double doubleValue = 0;
private byte[] bytesValue = null;
private HiveDecimal decimalValue = null;
+ private Timestamp timestampValue = null;
+ private HiveIntervalDayTime intervalDayTimeValue = null;
private boolean isNullValue = false;
- private Type type;
+ private ColumnVector.Type type;
private int bytesValueLength = 0;
public ConstantVectorExpression() {
@@ -82,11 +82,22 @@ public class ConstantVectorExpression extends VectorExpression {
setBytesValue(value.getValue().getBytes());
}
- public ConstantVectorExpression(int outputColumn, HiveDecimal value) {
- this(outputColumn, "decimal");
+ // Include type name for precision/scale.
+ public ConstantVectorExpression(int outputColumn, HiveDecimal value, String typeName) {
+ this(outputColumn, typeName);
setDecimalValue(value);
}
+ public ConstantVectorExpression(int outputColumn, Timestamp value) {
+ this(outputColumn, "timestamp");
+ setTimestampValue(value);
+ }
+
+ public ConstantVectorExpression(int outputColumn, HiveIntervalDayTime value) {
+ this(outputColumn, "interval_day_time");
+ setIntervalDayTimeValue(value);
+ }
+
/*
* Support for null constant object
*/
@@ -140,6 +151,28 @@ public class ConstantVectorExpression extends VectorExpression {
}
}
+ private void evaluateTimestamp(VectorizedRowBatch vrg) {
+ TimestampColumnVector dcv = (TimestampColumnVector) vrg.cols[outputColumn];
+ dcv.isRepeating = true;
+ dcv.noNulls = !isNullValue;
+ if (!isNullValue) {
+ dcv.set(0, timestampValue);
+ } else {
+ dcv.isNull[0] = true;
+ }
+ }
+
+ private void evaluateIntervalDayTime(VectorizedRowBatch vrg) {
+ IntervalDayTimeColumnVector dcv = (IntervalDayTimeColumnVector) vrg.cols[outputColumn];
+ dcv.isRepeating = true;
+ dcv.noNulls = !isNullValue;
+ if (!isNullValue) {
+ dcv.set(0, intervalDayTimeValue);
+ } else {
+ dcv.isNull[0] = true;
+ }
+ }
+
@Override
public void evaluate(VectorizedRowBatch vrg) {
switch (type) {
@@ -155,6 +188,12 @@ public class ConstantVectorExpression extends VectorExpression {
case DECIMAL:
evaluateDecimal(vrg);
break;
+ case TIMESTAMP:
+ evaluateTimestamp(vrg);
+ break;
+ case INTERVAL_DAY_TIME:
+ evaluateIntervalDayTime(vrg);
+ break;
}
}
@@ -192,39 +231,40 @@ public class ConstantVectorExpression extends VectorExpression {
this.decimalValue = decimalValue;
}
- public String getTypeString() {
- return getOutputType();
+ public HiveDecimal getDecimalValue() {
+ return decimalValue;
}
- public void setTypeString(String typeString) {
- this.outputType = typeString;
- if (VectorizationContext.isStringFamily(typeString)) {
- this.type = Type.BYTES;
- } else if (VectorizationContext.isFloatFamily(typeString)) {
- this.type = Type.DOUBLE;
- } else if (VectorizationContext.isDecimalFamily(typeString)){
- this.type = Type.DECIMAL;
- } else {
- // everything else that does not belong to string, double, decimal is treated as long.
- this.type = Type.LONG;
- }
+ public void setTimestampValue(Timestamp timestampValue) {
+ this.timestampValue = timestampValue;
}
- public void setOutputColumn(int outputColumn) {
- this.outputColumn = outputColumn;
+ public Timestamp getTimestampValue() {
+ return timestampValue;
}
- public Type getType() {
- return type;
+ public void setIntervalDayTimeValue(HiveIntervalDayTime intervalDayTimeValue) {
+ this.intervalDayTimeValue = intervalDayTimeValue;
}
- public void setType(Type type) {
- this.type = type;
+ public HiveIntervalDayTime getIntervalDayTimeValue() {
+ return intervalDayTimeValue;
}
- @Override
- public void setOutputType(String type) {
- setTypeString(type);
+ public String getTypeString() {
+ return getOutputType();
+ }
+
+ private void setTypeString(String typeString) {
+ this.outputType = typeString;
+
+ String typeName = VectorizationContext.mapTypeNameSynonyms(outputType);
+ TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(typeName);
+ this.type = VectorizationContext.getColumnVectorTypeFromTypeInfo(typeInfo);
+ }
+
+ public void setOutputColumn(int outputColumn) {
+ this.outputColumn = outputColumn;
}
@Override
http://git-wip-us.apache.org/repos/asf/hive/blob/130293e5/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/DateColSubtractDateColumn.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/DateColSubtractDateColumn.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/DateColSubtractDateColumn.java
new file mode 100644
index 0000000..fafacce
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/DateColSubtractDateColumn.java
@@ -0,0 +1,185 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.vector.expressions;
+
+import java.sql.Timestamp;
+
+import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
+import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil;
+import org.apache.hadoop.hive.ql.exec.vector.*;
+import org.apache.hadoop.hive.ql.util.DateTimeMath;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+
+// A type date (LongColumnVector storing epoch days) minus a type date produces a
+// type interval_day_time (IntervalDayTimeColumnVector storing nanosecond interval in 2 longs).
+public class DateColSubtractDateColumn extends VectorExpression {
+
+ private static final long serialVersionUID = 1L;
+
+ private int colNum1;
+ private int colNum2;
+ private int outputColumn;
+ private Timestamp scratchTimestamp1;
+ private Timestamp scratchTimestamp2;
+ private DateTimeMath dtm = new DateTimeMath();
+
+ public DateColSubtractDateColumn(int colNum1, int colNum2, int outputColumn) {
+ this.colNum1 = colNum1;
+ this.colNum2 = colNum2;
+ this.outputColumn = outputColumn;
+ scratchTimestamp1 = new Timestamp(0);
+ scratchTimestamp2 = new Timestamp(0);
+ }
+
+ public DateColSubtractDateColumn() {
+ }
+
+ @Override
+ public void evaluate(VectorizedRowBatch batch) {
+
+ if (childExpressions != null) {
+ super.evaluateChildren(batch);
+ }
+
+ // Input #1 is type date (epochDays).
+ LongColumnVector inputColVector1 = (LongColumnVector) batch.cols[colNum1];
+
+ // Input #2 is type date (epochDays).
+ LongColumnVector inputColVector2 = (LongColumnVector) batch.cols[colNum2];
+
+ // Output is type interval_day_time.
+ IntervalDayTimeColumnVector outputColVector = (IntervalDayTimeColumnVector) batch.cols[outputColumn];
+
+ int[] sel = batch.selected;
+ int n = batch.size;
+ long[] vector1 = inputColVector1.vector;
+ long[] vector2 = inputColVector2.vector;
+
+ // return immediately if batch is empty
+ if (n == 0) {
+ return;
+ }
+
+ outputColVector.isRepeating =
+ inputColVector1.isRepeating && inputColVector2.isRepeating
+ || inputColVector1.isRepeating && !inputColVector1.noNulls && inputColVector1.isNull[0]
+ || inputColVector2.isRepeating && !inputColVector2.noNulls && inputColVector2.isNull[0];
+
+ // Handle nulls first
+ NullUtil.propagateNullsColCol(
+ inputColVector1, inputColVector2, outputColVector, sel, n, batch.selectedInUse);
+
+ HiveIntervalDayTime resultIntervalDayTime = outputColVector.getScratchIntervalDayTime();
+
+ /* Disregard nulls for processing. In other words,
+ * the arithmetic operation is performed even if one or
+ * more inputs are null. This is to improve speed by avoiding
+ * conditional checks in the inner loop.
+ */
+ if (inputColVector1.isRepeating && inputColVector2.isRepeating) {
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[0]));
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[0]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(0);
+ } else if (inputColVector1.isRepeating) {
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[0]));
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ }
+ } else if (inputColVector2.isRepeating) {
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[0]));
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ }
+ } else {
+ if (batch.selectedInUse) {
+ for(int j = 0; j != n; j++) {
+ int i = sel[j];
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[i]));
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ } else {
+ for(int i = 0; i != n; i++) {
+ scratchTimestamp1.setTime(DateWritable.daysToMillis((int) vector1[i]));
+ scratchTimestamp2.setTime(DateWritable.daysToMillis((int) vector2[i]));
+ dtm.subtract(scratchTimestamp1, scratchTimestamp2, outputColVector.getScratchIntervalDayTime());
+ outputColVector.setFromScratchIntervalDayTime(i);
+ }
+ }
+ }
+
+ /* For the case when the output can have null values, follow
+ * the convention that the data values must be 1 for long and
+ * NaN for double. This is to prevent possible later zero-divide errors
+ * in complex arithmetic expressions like col2 / (col1 - 1)
+ * in the case when some col1 entries are null.
+ */
+ NullUtil.setNullDataEntriesIntervalDayTime(outputColVector, batch.selectedInUse, sel, n);
+ }
+
+ @Override
+ public int getOutputColumn() {
+ return outputColumn;
+ }
+
+ @Override
+ public String getOutputType() {
+ return "timestamp";
+ }
+
+ @Override
+ public VectorExpressionDescriptor.Descriptor getDescriptor() {
+ return (new VectorExpressionDescriptor.Builder())
+ .setMode(
+ VectorExpressionDescriptor.Mode.PROJECTION)
+ .setNumArguments(2)
+ .setArgumentTypes(
+ VectorExpressionDescriptor.ArgumentType.getType("date"),
+ VectorExpressionDescriptor.ArgumentType.getType("date"))
+ .setInputExpressionTypes(
+ VectorExpressionDescriptor.InputExpressionType.COLUMN,
+ VectorExpressionDescriptor.InputExpressionType.COLUMN).build();
+ }
+}
+