@Override public int compareTo(FieldValue that){ if((this.getOpType() != that.getOpType()) || (this.getDataType() != that.getDataType())){ throw new ClassCastException(); } return compareToValue(that); }
private FieldValue evaluate(FieldValue left, FieldValue right){ DataType dataType = TypeUtil.getCommonDataType(left.getDataType(), right.getDataType()); Double result = Math.pow((left.asNumber()).doubleValue(), (right.asNumber()).doubleValue()); return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } };
private boolean equalsValue(Object value){ value = TypeUtil.parseOrCast(getDataType(), value); return (getValue()).equals(value); }
private FieldValue evaluate(FieldValue left, FieldValue right){ DataType dataType = TypeUtil.getCommonDataType(left.getDataType(), right.getDataType()); Integer result = ((left.asNumber()).doubleValue() > (right.asNumber()).doubleValue()) ? Numbers.INTEGER_ONE : Numbers.INTEGER_ZERO; return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } };
public int compareToString(String string){ Object value = TypeUtil.parse(getDataType(), string); return ((Comparable)getValue()).compareTo(value); }
public boolean equalsString(String string){ Object value = TypeUtil.parse(getDataType(), string); return (getValue()).equals(value); }
private int compareToValue(Object value){ value = TypeUtil.parseOrCast(getDataType(), value); return ((Comparable)getValue()).compareTo(value); }
@Override public boolean equals(Object object){ if(object instanceof FieldValue){ FieldValue that = (FieldValue)object; return (this.getOpType() == that.getOpType()) && (this.getDataType() == that.getDataType()) && (this.getValue()).equals(that.getValue()); } return false; }
private FieldValue evaluate(FieldValue value){ DataType dataType = value.getDataType(); Number result = evaluate(value.asNumber()); return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } }
@Override public int hashCode(){ return (31 * (getOpType().hashCode() ^ getDataType().hashCode())) + getValue().hashCode(); }
private FieldValue evaluate(FieldValue left, FieldValue right){ // "If one of the input fields of a simple arithmetic function is a missing value, then the result evaluates to missing value" if(Objects.equals(FieldValues.MISSING_VALUE, left) || Objects.equals(FieldValues.MISSING_VALUE, right)){ return FieldValues.MISSING_VALUE; } DataType dataType = TypeUtil.getCommonDataType(left.getDataType(), right.getDataType()); Number result; try { result = evaluate(left.asNumber(), right.asNumber()); } catch(ArithmeticException ae){ throw new UndefinedResultException() .initCause(ae); } return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result); } }
public FieldValue cast(DataType dataType, OpType opType){ boolean compatible = true; if(dataType == null){ dataType = getDataType(); } else if(dataType != null && !(dataType).equals(getDataType())){ compatible = false; } // End if if(opType == null){ opType = getOpType(); } else if(opType != null && !(opType).equals(getOpType())){ compatible = false; } // End if if(compatible){ return this; } return FieldValue.create(dataType, opType, getValue()); }
@Override protected FieldValue checkArgument(FieldValue argument, int index, String alias){ if(Objects.equals(FieldValues.MISSING_VALUE, argument)){ return argument; } DataType dataType = argument.getDataType(); switch(dataType){ case INTEGER: case FLOAT: case DOUBLE: break; default: if(alias != null){ throw new FunctionException(this, "Expected a numeric \'" + alias + "\' value at position " + index + ", got " + dataType.value() + " value"); } else { throw new FunctionException(this, "Expected a numeric value at position " + index + ", got " + dataType.value() + " value"); } } return argument; } }
@Override public FieldValue evaluate(List<FieldValue> arguments){ StorelessUnivariateStatistic statistic = createStatistic(); DataType dataType = null; for(int i = 0; i < arguments.size(); i++){ FieldValue value = getOptionalArgument(arguments, i); // "Missing values in the input to an aggregate function are simply ignored" if(Objects.equals(FieldValues.MISSING_VALUE, value)){ continue; } statistic.increment((value.asNumber()).doubleValue()); if(dataType != null){ dataType = TypeUtil.getCommonDataType(dataType, value.getDataType()); } else { dataType = value.getDataType(); } } // "If all inputs are missing, then the result evaluates to a missing value" if(statistic.getN() == 0){ return FieldValues.MISSING_VALUE; } Double result = statistic.getResult(); return FieldValueUtil.create(getResultDataType(dataType), OpType.CONTINUOUS, result); }
protected ToStringHelper toStringHelper(){ ToStringHelper helper = new ToStringHelper(this) .add("opType", getOpType()) .add("dataType", getDataType()) .add("value", getValue()); return helper; }
DataType dataType = value.getDataType();
public FieldValue cast(TypeInfo typeInfo){ DataType dataType = typeInfo.getDataType(); OpType opType = typeInfo.getOpType(); if((dataType).equals(getDataType()) && (opType).equals(getOpType())){ return this; } return FieldValue.create(typeInfo, getValue()); }