public static ConstantVectorExpression createStruct(int outputColumnNum, Object value, TypeInfo outputTypeInfo) throws HiveException { ConstantVectorExpression result = new ConstantVectorExpression(outputColumnNum, outputTypeInfo); result.setStructValue(value); return result; }
@Override public void processBatch(VectorizedRowBatch batch) throws HiveException { if (!groupingSetsPresent) { doProcessBatch(batch, false, null); return; } // We drive the doProcessBatch logic with the same batch but different // grouping set id and null variation. // PERFORMANCE NOTE: We do not try to reuse columns and generate the KeyWrappers anew... final int size = groupingSets.length; for (int i = 0; i < size; i++) { // NOTE: We are overwriting the constant vector value... groupingSetsDummyVectorExpression.setLongValue(groupingSets[i]); groupingSetsDummyVectorExpression.evaluate(batch); doProcessBatch(batch, (i == 0), allGroupingSetsOverrideIsNulls[i]); } }
private void evaluateColumn(ColumnVector colVector) { switch (type) { case LONG: evaluateLong(colVector); break; case DOUBLE: evaluateDouble(colVector); break; case BYTES: evaluateBytes(colVector); break; case DECIMAL: evaluateDecimal(colVector); break; case TIMESTAMP: evaluateTimestamp(colVector); break; case INTERVAL_DAY_TIME: evaluateIntervalDayTime(colVector); break; case STRUCT: evaluateStruct(colVector); break; case VOID: evaluateVoid(colVector); break; default: throw new RuntimeException("Unexpected column vector type " + type); } }
@Override public void evaluate(VectorizedRowBatch vrg) { switch (type) { case LONG: evaluateLong(vrg); break; case DOUBLE: evaluateDouble(vrg); break; case BYTES: evaluateBytes(vrg); break; case DECIMAL: evaluateDecimal(vrg); break; case TIMESTAMP: evaluateTimestamp(vrg); break; case INTERVAL_DAY_TIME: evaluateIntervalDayTime(vrg); break; } }
@Override public void evaluate(VectorizedRowBatch vrg) { switch (type) { case LONG: evaluateLong(vrg); break; case DOUBLE: evaluateDouble(vrg); break; case BYTES: evaluateBytes(vrg); break; case DECIMAL: evaluateDecimal(vrg); break; } }
public ConstantVectorExpression(int outputColumnNum, byte[] value, TypeInfo outputTypeInfo) throws HiveException { this(outputColumnNum, outputTypeInfo); setBytesValue(value); }
@Test public void testConstantExpression() throws Exception { ConstantVectorExpression longCve = new ConstantVectorExpression(0, 17, TypeInfoFactory.longTypeInfo); ConstantVectorExpression doubleCve = new ConstantVectorExpression(1, 17.34, TypeInfoFactory.doubleTypeInfo); String str = "alpha"; ConstantVectorExpression bytesCve = new ConstantVectorExpression(2, str.getBytes(), TypeInfoFactory.stringTypeInfo); HiveDecimal decVal = HiveDecimal.create("25.8"); ConstantVectorExpression decimalCve = new ConstantVectorExpression(3, decVal, TypeInfoFactory.decimalTypeInfo); ConstantVectorExpression nullCve = new ConstantVectorExpression(4, TypeInfoFactory.stringTypeInfo, true); vrg.cols[4] = bcvn; longCve.evaluate(vrg); doubleCve.evaluate(vrg); bytesCve.evaluate(vrg); decimalCve.evaluate(vrg); nullCve.evaluate(vrg); assertTrue(lcv.isRepeating); assertTrue(dcv.isRepeating); bytesCve.evaluate(vrg); assertTrue(bcv.length[0] == alphaBytes.length); assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length)); decimalCve.evaluate(vrg); assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
return new ConstantVectorExpression(outputColumnNum, outputTypeInfo, true); case BOOLEAN: if (((Boolean) constantValue).booleanValue()) { return new ConstantVectorExpression(outputColumnNum, 1, outputTypeInfo); } else { return new ConstantVectorExpression(outputColumnNum, 0, outputTypeInfo); case INT: case LONG: return new ConstantVectorExpression( outputColumnNum, ((Number) constantValue).longValue(), outputTypeInfo); case FLOAT: case DOUBLE: return new ConstantVectorExpression( outputColumnNum, ((Number) constantValue).doubleValue(), outputTypeInfo); case DATE: return new ConstantVectorExpression( outputColumnNum, DateWritableV2.dateToDays((Date) constantValue), outputTypeInfo); case TIMESTAMP: return new ConstantVectorExpression( outputColumnNum, ((org.apache.hadoop.hive.common.type.Timestamp) constantValue).toSqlTimestamp(), outputTypeInfo); case DECIMAL: return new ConstantVectorExpression( outputColumnNum, (HiveDecimal) constantValue, outputTypeInfo); case STRING: return new ConstantVectorExpression(
return new ConstantVectorExpression(outCol, typeName, true); return new ConstantVectorExpression(outCol, 1); } else { return new ConstantVectorExpression(outCol, 0); return new ConstantVectorExpression(outCol, ((Number) constantValue).longValue()); case DATE: return new ConstantVectorExpression(outCol, DateWritable.dateToDays((Date) constantValue)); case TIMESTAMP: 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, (HiveIntervalDayTime) constantValue); case FLOAT_FAMILY: return new ConstantVectorExpression(outCol, ((Number) constantValue).doubleValue()); case DECIMAL: return new ConstantVectorExpression(outCol, (HiveDecimal) constantValue, typeName); case STRING: return new ConstantVectorExpression(outCol, ((String) constantValue).getBytes()); case CHAR: return new ConstantVectorExpression(outCol, ((HiveChar) constantValue), typeName); case VARCHAR: return new ConstantVectorExpression(outCol, ((HiveVarchar) constantValue), typeName); default: throw new HiveException("Unsupported constant type: " + typeName + ", object class " + constantValue.getClass().getSimpleName());
return new ConstantVectorExpression(outCol, typeInfo, true); return new ConstantVectorExpression(outCol, 1, typeInfo); } else { return new ConstantVectorExpression(outCol, 0, typeInfo); return ConstantVectorExpression.create(outCol, constantValue, typeInfo);
public ConstantVectorExpression(int outputColumnNum, HiveDecimal value, TypeInfo outputTypeInfo) throws HiveException { this(outputColumnNum, outputTypeInfo); setDecimalValue(value); }
@Override protected void initializeOp(Configuration hconf) throws HiveException { super.initializeOp(hconf); try { heartbeatInterval = HiveConf.getIntVar(hconf, HiveConf.ConfVars.HIVESENDHEARTBEAT); conditionEvaluator.init(hconf); } catch (Throwable e) { throw new HiveException(e); } if (conditionEvaluator instanceof ConstantVectorExpression) { ConstantVectorExpression cve = (ConstantVectorExpression) this.conditionEvaluator; if (cve.getLongValue() == 1) { filterMode = 1; } else { filterMode = -1; } } temporarySelected = new int [VectorizedRowBatch.DEFAULT_SIZE]; }
public ConstantVectorExpression(int outputColumn, byte[] value) { this(outputColumn, "string"); setBytesValue(value); }
return new ConstantVectorExpression(outCol, typeName, true); return new ConstantVectorExpression(outCol, 1); } else { return new ConstantVectorExpression(outCol, 0); return new ConstantVectorExpression(outCol, ((Number) constantValue).longValue()); case DATE: return new ConstantVectorExpression(outCol, DateWritable.dateToDays((Date) constantValue)); case TIMESTAMP: return new ConstantVectorExpression(outCol, TimestampUtils.getTimeNanoSec((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)); case FLOAT_FAMILY: return new ConstantVectorExpression(outCol, ((Number) constantValue).doubleValue()); case DECIMAL: VectorExpression ve = new ConstantVectorExpression(outCol, (HiveDecimal) constantValue); return new ConstantVectorExpression(outCol, ((String) constantValue).getBytes()); case CHAR: return new ConstantVectorExpression(outCol, ((HiveChar) constantValue)); case VARCHAR: return new ConstantVectorExpression(outCol, ((HiveVarchar) constantValue)); default: throw new HiveException("Unsupported constant type: " + typeName + ", object class " + constantValue.getClass().getSimpleName());
public ConstantVectorExpression(int outputColumn, HiveDecimal value, String typeName) { this(outputColumn, typeName); setDecimalValue(value); }
@Override protected void initializeOp(Configuration hconf) throws HiveException { super.initializeOp(hconf); VectorExpression.doTransientInit(predicateExpression); try { heartbeatInterval = HiveConf.getIntVar(hconf, HiveConf.ConfVars.HIVESENDHEARTBEAT); predicateExpression.init(hconf); } catch (Throwable e) { throw new HiveException(e); } if (predicateExpression instanceof ConstantVectorExpression) { ConstantVectorExpression cve = (ConstantVectorExpression) this.predicateExpression; if (cve.getLongValue() == 1) { filterMode = 1; } else { filterMode = -1; } } temporarySelected = new int [VectorizedRowBatch.DEFAULT_SIZE]; }
public ConstantVectorExpression(int outputColumnNum, HiveVarchar value, TypeInfo outputTypeInfo) throws HiveException { this(outputColumnNum, outputTypeInfo); setBytesValue(value.getValue().getBytes()); }
@Override public void processBatch(VectorizedRowBatch batch) throws HiveException { if (!groupingSetsPresent) { doProcessBatch(batch, false, null); return; } // We drive the doProcessBatch logic with the same batch but different // grouping set id and null variation. // PERFORMANCE NOTE: We do not try to reuse columns and generate the KeyWrappers anew... final int size = groupingSets.length; for (int i = 0; i < size; i++) { // NOTE: We are overwriting the constant vector value... groupingSetsDummyVectorExpression.setLongValue(groupingSets[i]); groupingSetsDummyVectorExpression.evaluate(batch); doProcessBatch(batch, (i == 0), allGroupingSetsOverrideIsNulls[i]); } }
public ConstantVectorExpression(int outputColumn, HiveDecimal value) { this(outputColumn, "decimal"); setDecimalValue(value); }
@Override protected Collection<Future<?>> initializeOp(Configuration hconf) throws HiveException { Collection<Future<?>> result = super.initializeOp(hconf); try { heartbeatInterval = HiveConf.getIntVar(hconf, HiveConf.ConfVars.HIVESENDHEARTBEAT); } catch (Throwable e) { throw new HiveException(e); } if (conditionEvaluator instanceof ConstantVectorExpression) { ConstantVectorExpression cve = (ConstantVectorExpression) this.conditionEvaluator; if (cve.getLongValue() == 1) { filterMode = 1; } else { filterMode = -1; } } temporarySelected = new int [VectorizedRowBatch.DEFAULT_SIZE]; return result; }