Package org.apache.hadoop.hive.common.type

Examples of org.apache.hadoop.hive.common.type.HiveDecimal


    return doubleWritable;
  }

  @Override
  protected HiveDecimalWritable evaluate(HiveDecimal left, HiveDecimal right) {
    HiveDecimal dec = left.add(right);

    if (dec == null) {
      return null;
    }
View Full Code Here


    return longWritable;
  }

  @Override
  protected HiveDecimalWritable evaluate(HiveDecimalWritable input) {
    HiveDecimal bd = input.getHiveDecimal();
    decimalWritable.set(bd.setScale(0, HiveDecimal.ROUND_CEILING));
    return decimalWritable;
  }
View Full Code Here

    switch (inputType) {
    case VOID:
      return null;
    case DECIMAL:
      HiveDecimalWritable decimalWritable = (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input);
      HiveDecimal dec = RoundUtils.round(decimalWritable.getHiveDecimal(), scale);
      if (dec == null) {
        return null;
      }
      return new HiveDecimalWritable(dec);
    case BYTE:
View Full Code Here

          myagg.countNulls++;
        }
        else {
          try {

            HiveDecimal v = PrimitiveObjectInspectorUtils.getHiveDecimal(p, inputOI);

            //Update min counter if new value is less than min seen so far
            if (v.compareTo(myagg.min) < 0) {
              myagg.min = v;
            }

            //Update max counter if new value is greater than max seen so far
            if (v.compareTo(myagg.max) > 0) {
              myagg.max = v;
            }

            // Add value to NumDistinctValue Estimator
            myagg.numDV.addToEstimator(v);
View Full Code Here

      statsObj.getStatsData().getDecimalStats().setNumNulls(v);
    } else if (fName.equals("numdistinctvalues")) {
      long v = ((LongObjectInspector) oi).get(o);
      statsObj.getStatsData().getDecimalStats().setNumDVs(v);
    } else if (fName.equals("max")) {
      HiveDecimal d = ((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o);
      statsObj.getStatsData().getDecimalStats().setHighValue(convertToThriftDecimal(d));
    } else if (fName.equals("min")) {
      HiveDecimal d = ((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o);
      statsObj.getStatsData().getDecimalStats().setLowValue(convertToThriftDecimal(d));
    }
  }
View Full Code Here

    @Override
    void write(Object obj) throws IOException {
      super.write(obj);
      if (obj != null) {
        HiveDecimal decimal = ((HiveDecimalObjectInspector) inspector).
            getPrimitiveJavaObject(obj);
        if (decimal == null) {
          return;
        }
        SerializationUtils.writeBigInteger(valueStream,
            decimal.unscaledValue());
        scaleStream.write(decimal.scale());
        indexStatistics.updateDecimal(decimal);
      }
    }
View Full Code Here

        assertEquals (key, (Double) expected, (Double) arr[0]);
      } else if (arr[0] instanceof Long) {
        assertEquals (key, (Long) expected, (Long) arr[0]);
      } else if (arr[0] instanceof HiveDecimalWritable) {
        HiveDecimalWritable hdw = (HiveDecimalWritable) arr[0];
        HiveDecimal hd = hdw.getHiveDecimal();
        Decimal128 d128 = (Decimal128)expected;
        assertEquals (key, d128.toBigDecimal(), hd.bigDecimalValue());
      } else if (arr[0] instanceof HiveDecimal) {
          HiveDecimal hd = (HiveDecimal) arr[0];
          Decimal128 d128 = (Decimal128)expected;
          assertEquals (key, d128.toBigDecimal(), hd.bigDecimalValue());
      } else {
        Assert.fail("Unsupported result type: " + arr[0].getClass().getName());
      }
    }
View Full Code Here

    ObjectInspector inspector;
    synchronized (TestOrcFile.class) {
      inspector = OrcStruct.createObjectInspector(0, types);
    }
    HiveDecimal maxValue = HiveDecimal.create("10000000000000000000");
    Writer writer = OrcFile.createWriter(testFilePath,
                                         OrcFile.writerOptions(conf)
                                         .inspector(inspector)
                                         .stripeSize(1000)
                                         .compress(CompressionKind.NONE)
                                         .bufferSize(100)
                                         .blockPadding(false));
    OrcStruct row = new OrcStruct(3);
    OrcUnion union = new OrcUnion();
    row.setFieldValue(1, union);
    row.setFieldValue(0, new TimestampWritable(Timestamp.valueOf("2000-03-12 15:00:00")));
    HiveDecimal value = HiveDecimal.create("12345678.6547456");
    row.setFieldValue(2, new HiveDecimalWritable(value));
    union.set((byte) 0, new IntWritable(42));
    writer.addRow(row);
    row.setFieldValue(0, new TimestampWritable(Timestamp.valueOf("2000-03-20 12:00:00.123456789")));
    union.set((byte) 1, new Text("hello"));
View Full Code Here

          if (value == null) {
            dv.noNulls = false;
            dv.isNull[0] = true;
            dv.isRepeating = true;
          } else {
            HiveDecimal hd = (HiveDecimal)(value);
            dv.vector[0] = new Decimal128(hd.toString(), (short)hd.scale());
            dv.isRepeating = true;
            dv.isNull[0] = false;     
          }
        }
        break;
View Full Code Here

    } else if (outputOI instanceof WritableHiveDecimalObjectInspector) {
      DecimalColumnVector dcv = (DecimalColumnVector) colVec;
      if (value instanceof HiveDecimal) {
        dcv.vector[i].update(((HiveDecimal) value).bigDecimalValue());
      } else {
        HiveDecimal hd = ((WritableHiveDecimalObjectInspector) outputOI).getPrimitiveJavaObject(value);
        dcv.vector[i].update(hd.bigDecimalValue());
      }
    } else {
      throw new RuntimeException("Unhandled object type " + outputOI.getTypeName());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.common.type.HiveDecimal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.