Examples of HiveDecimalWritable


Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

    if (writable == null) {
      return null;
    }

    HiveDecimal dec = enforcePrecisionScale(writable.getHiveDecimal(), precision, scale);
    return dec == null ? null : new HiveDecimalWritable(dec);
  }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

        TimestampWritable t2 = ((TimestampObjectInspector) poi2)
            .getPrimitiveWritableObject(o2);
        return t1.compareTo(t2);
      }
      case DECIMAL: {
        HiveDecimalWritable t1 = ((HiveDecimalObjectInspector) poi1)
            .getPrimitiveWritableObject(o1);
        HiveDecimalWritable t2 = ((HiveDecimalObjectInspector) poi2)
            .getPrimitiveWritableObject(o2);
        return t1.compareTo(t2);
      }
      default: {
        throw new RuntimeException("Unknown type: "
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

    super(oi);

    DecimalTypeInfo typeInfo = (DecimalTypeInfo) oi.getTypeInfo();
    this.precision = typeInfo.precision();
    this.scale = typeInfo.scale();
    data = new HiveDecimalWritable();
  }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

    data = new HiveDecimalWritable();
  }

  LazyBinaryHiveDecimal(LazyBinaryHiveDecimal copy) {
    super(copy);
    data = new HiveDecimalWritable(copy.data);
  }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

  @Override
  public void init(ByteArrayRef bytes, int start, int length) {
    data.setFromBytes(bytes.getData(), start, length);
    HiveDecimal dec = data.getHiveDecimal(precision, scale);
    data = dec == null ? null : new HiveDecimalWritable(dec);
  }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

        return t;

      case DECIMAL: {
        // See serialization of decimal for explanation (below)

        HiveDecimalWritable bdw = (reuse == null ? new HiveDecimalWritable() :
          (HiveDecimalWritable) reuse);

        int b = buffer.read(invert) - 1;
        assert (b == 1 || b == -1 || b == 0);
        boolean positive = b != -1;

        int factor = buffer.read(invert) ^ 0x80;
        for (int i = 0; i < 3; i++) {
          factor = (factor << 8) + (buffer.read(invert) & 0xff);
        }

        if (!positive) {
          factor = -factor;
        }

        int start = buffer.tell();
        int length = 0;

        do {
          b = buffer.read(positive ? invert : !invert);
          assert(b != 1);

          if (b == 0) {
            // end of digits
            break;
          }

          length++;
        } while (true);

        if(decimalBuffer == null || decimalBuffer.length < length) {
          decimalBuffer = new byte[length];
        }

        buffer.seek(start);
        for (int i = 0; i < length; ++i) {
          decimalBuffer[i] = buffer.read(positive ? invert : !invert);
        }

        // read the null byte again
        buffer.read(positive ? invert : !invert);

        String digits = new String(decimalBuffer, 0, length, decimalCharSet);
        BigInteger bi = new BigInteger(digits);
        HiveDecimal bd = HiveDecimal.create(bi).scaleByPowerOfTen(factor-length);

        if (!positive) {
          bd = bd.negate();
        }

        bdw.set(bd);
        return bdw;
      }

      default: {
        throw new RuntimeException("Unrecognized type: "
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

    public VectorUDAFAvgDecimal() {
      super();
      partialResult = new Object[2];
      resultCount = new LongWritable();
      resultSum = new HiveDecimalWritable();
      partialResult[0] = resultCount;
      partialResult[1] = resultSum;
      scratch = new Decimal128FastBuffer();

    }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

          public void assignObjectValue(Object val, int destIndex) throws HiveException {
              if (val == null) {
                assignNull(destIndex);
              }
              else {
                HiveDecimalWritable hdw = (HiveDecimalWritable) val;
                assignDecimal(hdw, destIndex);
              }
            }
          }.init(outputBatch, (DecimalColumnVector) destCol);
          break;
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

  @Test
  public void testLongMinusDecimal() throws HiveException {
    GenericUDFOPMinus udf = new GenericUDFOPMinus();

    LongWritable left = new LongWritable(104);
    HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
    ObjectInspector[] inputOIs = {
        PrimitiveObjectInspectorFactory.writableLongObjectInspector,
        PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(9, 4))
    };
    DeferredObject[] args = {
        new DeferredJavaObject(left),
        new DeferredJavaObject(right),
    };

    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(24,4), oi.getTypeInfo());
    HiveDecimalWritable res = (HiveDecimalWritable) udf.evaluate(args);
    Assert.assertEquals(HiveDecimal.create("-130.97"), res.getHiveDecimal());
  }
View Full Code Here

Examples of org.apache.hadoop.hive.serde2.io.HiveDecimalWritable

  @Test
  public void testDouleMinusDecimal() throws HiveException {
    GenericUDFOPMinus udf = new GenericUDFOPMinus();

    DoubleWritable left = new DoubleWritable(74.52);
    HiveDecimalWritable right = new HiveDecimalWritable(HiveDecimal.create("234.97"));
    ObjectInspector[] inputOIs = {
        PrimitiveObjectInspectorFactory.writableDoubleObjectInspector,
        PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(5, 2))
    };
    DeferredObject[] args = {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.