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

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


    this.precision = (short) precision;
    this.scale = (short) scale;
    final int len = size;
    vector = new Decimal128[len];
    for (int i = 0; i < len; i++) {
      vector[i] = new Decimal128(0, this.scale);
    }
  }
View Full Code Here


      index = 0;
    }
    if (!noNulls && isNull[index]) {
      return NullWritable.get();
    } else {
      Decimal128 dec = vector[index];
      writableObj.set(HiveDecimal.create(dec.toBigDecimal()));
      return writableObj;
    }
  }
View Full Code Here

  private transient Decimal128 tmp = null;
  private static transient Decimal128 tenE9 = new Decimal128(1000000000);

  public CastDecimalToTimestamp(int inputColumn, int outputColumn) {
    super(inputColumn, outputColumn);
    tmp = new Decimal128(0);
  }
View Full Code Here

  }

  public CastDecimalToTimestamp() {

    // initialize local field after deserialization
    tmp = new Decimal128(0);
  }
View Full Code Here

    }

    private void doTestFastStreamForHiveDecimal(String valueString) {
      Decimal128FastBuffer scratch = new Decimal128FastBuffer();
      BigDecimal value = new BigDecimal(valueString);
      Decimal128 dec = new Decimal128();
      dec.update(value);

      HiveDecimalWritable witness = new HiveDecimalWritable();
      witness.set(HiveDecimal.create(value));

      int bufferUsed = dec.fastSerializeForHiveDecimal(scratch);
      HiveDecimalWritable hdw = new HiveDecimalWritable();
      hdw.set(scratch.getBytes(bufferUsed), dec.getScale());

      HiveDecimal hd = hdw.getHiveDecimal();

      BigDecimal readValue = hd.bigDecimalValue();

      assertEquals(value, readValue);

      // Now test fastUpdate from the same serialized HiveDecimal
      Decimal128 decRead = new Decimal128().fastUpdateFromInternalStorage(
              witness.getInternalStorage(), (short) witness.getScale());

      assertEquals(dec, decRead);

      // Test fastUpdate from it's own (not fully compacted) serialized output
      Decimal128 decReadSelf = new Decimal128().fastUpdateFromInternalStorage(
              hdw.getInternalStorage(), (short) hdw.getScale());
      assertEquals(dec, decReadSelf);
    }
View Full Code Here

              int[] pos = new int[] {1, 0, 0, 0, 0};
              int[] neg = new int[] {0xff, 0, 0, 0, 0};

              pos[i+1] = neg[i+1] = value;

              doTestDecimalWithBoundsCheck(new Decimal128().update32(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update32(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update64(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update64(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update96(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update96(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update128(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update128(neg, 0));
          }
      }
    }
View Full Code Here

      Decimal128FastBuffer scratch = new Decimal128FastBuffer();
      String[] vs = new String[] {
          "-4033.445769230769",
          "6984454.211097692"};

      Decimal128 d = new Decimal128(0L, (short) 14);
      for (String s:vs) {
        Decimal128 p = new Decimal128(s, (short) 14);
        d.addDestructive(p, (short) (short) 14);
      }

      int bufferUsed = d.fastSerializeForHiveDecimal(scratch);
      HiveDecimalWritable hdw = new HiveDecimalWritable();
View Full Code Here

    ExprNodeDesc child = childExpr.get(0);
    String inputType = childExpr.get(0).getTypeString();
    if (child instanceof ExprNodeConstantDesc) {
      // Return a constant vector expression
      Object constantValue = ((ExprNodeConstantDesc) child).getValue();
      Decimal128 decimalValue = castConstantToDecimal(constantValue, child.getTypeInfo());
      return getConstantVectorExpression(decimalValue, returnType, Mode.PROJECTION);
    }
    if (isIntFamily(inputType)) {
      return createVectorExpression(CastLongToDecimal.class, childExpr, Mode.PROJECTION, returnType);
    } else if (isFloatFamily(inputType)) {
View Full Code Here

  }

  private Decimal128 castConstantToDecimal(Object scalar, TypeInfo type) throws HiveException {
    PrimitiveTypeInfo ptinfo = (PrimitiveTypeInfo) type;
    String typename = type.getTypeName();
    Decimal128 d = new Decimal128();
    int scale = HiveDecimalUtils.getScaleForType(ptinfo);
    switch (ptinfo.getPrimitiveCategory()) {
      case FLOAT:
        float floatVal = ((Float) scalar).floatValue();
        d.update(floatVal, (short) scale);
        break;
      case DOUBLE:
        double doubleVal = ((Double) scalar).doubleValue();
        d.update(doubleVal, (short) scale);
        break;
      case BYTE:
        byte byteVal = ((Byte) scalar).byteValue();
        d.update(byteVal, (short) scale);
        break;
      case SHORT:
        short shortVal = ((Short) scalar).shortValue();
        d.update(shortVal, (short) scale);
        break;
      case INT:
        int intVal = ((Integer) scalar).intValue();
        d.update(intVal, (short) scale);
        break;
      case LONG:
        long longVal = ((Long) scalar).longValue();
        d.update(longVal, (short) scale);
        break;
      case DECIMAL:
        HiveDecimal decimalVal = (HiveDecimal) scalar;
        d.update(decimalVal.unscaledValue(), (short) scale);
        break;
      default:
        throw new HiveException("Unsupported type "+typename+" for cast to Decimal128");
    }
    return d;
View Full Code Here

      } else {
        return 0;
      }
    } else if (decimalTypePattern.matcher(constDesc.getTypeString()).matches()) {
      HiveDecimal hd = (HiveDecimal) constDesc.getValue();
      Decimal128 dvalue = new Decimal128();
      dvalue.update(hd.unscaledValue(), (short) hd.scale());
      return dvalue;
    } else {
      return constDesc.getValue();
    }
  }
View Full Code Here

TOP

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

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.