@Test public void evaluateConstant(){ Constant emptyString = new Constant() .setDataType(DataType.STRING); assertEquals("", evaluate(emptyString)); emptyString.setMissing(true); assertEquals(null, evaluate(emptyString)); Constant stringThree = new Constant("3") .setDataType(DataType.STRING); assertEquals("3", evaluate(stringThree)); stringThree.setMissing(true); assertEquals(null, evaluate(stringThree)); Constant integerThree = new Constant("3") .setDataType(DataType.INTEGER); assertEquals(3, evaluate(integerThree)); integerThree.setMissing(true); assertEquals(null, evaluate(integerThree)); Constant floatThree = new Constant("3") .setDataType(DataType.FLOAT); assertEquals(3f, evaluate(floatThree)); floatThree.setMissing(true); assertEquals(null, evaluate(floatThree)); Constant doubleThree = new Constant("3") .setDataType(DataType.DOUBLE); assertEquals(3d, evaluate(doubleThree)); doubleThree.setMissing(true); assertEquals(null, evaluate(doubleThree)); }
static public FieldValue evaluateConstant(Constant constant){ boolean missing = constant.isMissing(); if(missing){ return FieldValues.MISSING_VALUE; } Object value = constant.getValue(); DataType dataType = constant.getDataType(); if(dataType != null){ if(isEmptyContent(value)){ switch(dataType){ case STRING: return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, ""); default: return FieldValues.MISSING_VALUE; } } } else { if(isEmptyContent(value)){ return FieldValues.MISSING_VALUE; } dataType = TypeUtil.getConstantDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValueUtil.create(dataType, opType, value); }
ExpressionUtil { static public FieldValue evaluateConstant(Constant constant){ boolean missing = constant.isMissing(); if(missing){ return FieldValues.MISSING_VALUE; } Object value = constant.getValue(); DataType dataType = constant.getDataType(); if(dataType != null){ if(isEmptyContent(value)){ switch(dataType){ case STRING: return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, ""); default: return FieldValues.MISSING_VALUE; } } } else { if(isEmptyContent(value)){ return FieldValues.MISSING_VALUE; } dataType = TypeUtil.getConstantDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValueUtil.create(dataType, opType, value); } }
ExpressionUtil { static public FieldValue evaluateConstant(Constant constant){ boolean missing = constant.isMissing(); if(missing){ return FieldValues.MISSING_VALUE; } Object value = constant.getValue(); DataType dataType = constant.getDataType(); if(dataType != null){ if(isEmptyContent(value)){ switch(dataType){ case STRING: return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, ""); default: return FieldValues.MISSING_VALUE; } } } else { if(isEmptyContent(value)){ return FieldValues.MISSING_VALUE; } dataType = TypeUtil.getConstantDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValueUtil.create(dataType, opType, value); } private  ExpressionUtil(); }
ExpressionUtil { static public FieldValue evaluateConstant(Constant constant){ boolean missing = constant.isMissing(); if(missing){ return FieldValues.MISSING_VALUE; } Object value = constant.getValue(); DataType dataType = constant.getDataType(); if(dataType != null){ if(isEmptyContent(value)){ switch(dataType){ case STRING: return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, ""); default: return FieldValues.MISSING_VALUE; } } } else { if(isEmptyContent(value)){ return FieldValues.MISSING_VALUE; } dataType = TypeUtil.getConstantDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValueUtil.create(dataType, opType, value); } private  ExpressionUtil(); static FieldName ensureField(E hasField); static Expression ensureExpression(E hasExpression); static FieldValue evaluateExpressionContainer(E hasExpression, EvaluationContext context); static FieldValue evaluateTypedExpressionContainer(E hasTypedExpression, EvaluationContext context); static FieldValue evaluate(DerivedField derivedField, EvaluationContext context); static FieldValue evaluate(DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context); static FieldValue evaluate(Expression expression, EvaluationContext context); static FieldValue evaluateConstant(Constant constant); static FieldValue evaluateFieldRef(FieldRef fieldRef, EvaluationContext context); static FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context); static FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context); static FieldValue evaluateDiscretize(Discretize discretize, EvaluationContext context); static FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context); static FieldValue evaluateTextIndex(TextIndex textIndex, EvaluationContext context); static FieldValue evaluateApply(Apply apply, EvaluationContext context); @SuppressWarnings ( value = {"unchecked"} ) static FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context); static FieldValue evaluateJavaExpression(JavaExpression javaExpression, EvaluationContext context); static boolean isEmptyContent(Object value); }
ExpressionUtil { static public FieldValue evaluateConstant(Constant constant){ boolean missing = constant.isMissing(); if(missing){ return FieldValues.MISSING_VALUE; } Object value = constant.getValue(); DataType dataType = constant.getDataType(); if(dataType != null){ if(isEmptyContent(value)){ switch(dataType){ case STRING: return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, ""); default: return FieldValues.MISSING_VALUE; } } } else { if(isEmptyContent(value)){ return FieldValues.MISSING_VALUE; } dataType = TypeUtil.getConstantDataType(value); } OpType opType = TypeUtil.getOpType(dataType); return FieldValueUtil.create(dataType, opType, value); } private  ExpressionUtil(); static FieldName ensureField(E hasField); static Expression ensureExpression(E hasExpression); static FieldValue evaluateExpressionContainer(E hasExpression, EvaluationContext context); static FieldValue evaluateTypedExpressionContainer(E hasTypedExpression, EvaluationContext context); static FieldValue evaluate(DerivedField derivedField, EvaluationContext context); static FieldValue evaluate(DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context); static FieldValue evaluate(Expression expression, EvaluationContext context); static FieldValue evaluateConstant(Constant constant); static FieldValue evaluateFieldRef(FieldRef fieldRef, EvaluationContext context); static FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context); static FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context); static FieldValue evaluateDiscretize(Discretize discretize, EvaluationContext context); static FieldValue evaluateMapValues(MapValues mapValues, EvaluationContext context); static FieldValue evaluateTextIndex(TextIndex textIndex, EvaluationContext context); static FieldValue evaluateApply(Apply apply, EvaluationContext context); @SuppressWarnings ( value = {"unchecked"} ) static FieldValue evaluateAggregate(Aggregate aggregate, EvaluationContext context); static FieldValue evaluateJavaExpression(JavaExpression javaExpression, EvaluationContext context); static boolean isEmptyContent(Object value);  }