public BigDecimal percentDiff(Var var) {
    BigDecimal d1 = new Var(Var.Type.DECIMAL).cast(this).decimalValue();
    BigDecimal d2 = new Var(Var.Type.DECIMAL).cast(var).decimalValue();
    if (d1 != null && d2 != null) {
      if (d1.compareTo(BigDecimal.ZERO) != 0) {
        return d1.subtract(d2).abs().multiply(new BigDecimal(100)).divide(d1, 2, RoundingMode.HALF_UP);
      }
    }
    return null;
  }
Calculate difference between values in percent
hplsql/src/main/java/org/apache/hive/hplsql/Var.java