org.apache.hadoop.hive.serde2.lazy.LazyDouble Java Examples

The following examples show how to use org.apache.hadoop.hive.serde2.lazy.LazyDouble. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveDynamoDBTypeTest.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
@Test
public void testDouble() {
  double val = TEST_DOUBLE;
  String valString = Double.toString(val);
  HiveDynamoDBType ddType = HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(DOUBLE_OBJECT_INSPECTOR);
  AttributeValue expectedAV = new AttributeValue().withN(valString);
  AttributeValue actualAV = ddType.getDynamoDBData(val, DOUBLE_OBJECT_INSPECTOR, false);
  assertEquals(expectedAV, actualAV);
  Object actualDouble = ddType.getHiveData(actualAV, DOUBLE_OBJECT_INSPECTOR);
  assertEquals(val, actualDouble);

  LazyDouble ld = new LazyDouble(LAZY_DOUBLE_OBJECT_INSPECTOR);
  initLazyObject(ld, valString.getBytes(), 0, valString.length());
  actualAV = ddType.getDynamoDBData(ld, LAZY_DOUBLE_OBJECT_INSPECTOR, false);
  actualDouble = ddType.getHiveData(actualAV, DOUBLE_OBJECT_INSPECTOR);
  assertEquals(val, actualDouble);
}
 
Example #2
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
public static double asJavaDouble(@Nullable final Object o) {
    if (o == null) {
        throw new IllegalArgumentException();
    }
    if (o instanceof Double) {
        return ((Double) o).doubleValue();
    }
    if (o instanceof LazyDouble) {
        DoubleWritable d = ((LazyDouble) o).getWritableObject();
        return d.get();
    }
    if (o instanceof DoubleWritable) {
        return ((DoubleWritable) o).get();
    }
    String s = o.toString();
    return Double.parseDouble(s);
}
 
Example #3
Source File: HiveRCSchemaUtil.java    From spork with Apache License 2.0 5 votes vote down vote up
/**
    * Converts from a hive type to a pig type
    * 
    * @param value
    *            Object hive type
    * @return Object pig type
    */
   public static Object extractPigTypeFromHiveType(Object value) {

if (value instanceof org.apache.hadoop.hive.serde2.lazy.LazyArray) {
    value = parseLazyArrayToPigArray((org.apache.hadoop.hive.serde2.lazy.LazyArray) value);
} else if (value instanceof org.apache.hadoop.hive.serde2.lazy.LazyMap) {
    value = parseLazyMapToPigMap((org.apache.hadoop.hive.serde2.lazy.LazyMap) value);
} else {

    if (value instanceof LazyString) {
	value = ((LazyString) value).getWritableObject().toString();
    } else if (value instanceof LazyInteger) {
	value = ((LazyInteger) value).getWritableObject().get();
    } else if (value instanceof LazyLong) {
	value = ((LazyLong) value).getWritableObject().get();
    } else if (value instanceof LazyFloat) {
	value = ((LazyFloat) value).getWritableObject().get();
    } else if (value instanceof LazyDouble) {
	value = ((LazyDouble) value).getWritableObject().get();
    } else if (value instanceof LazyBoolean) {
	boolean boolvalue = ((LazyBoolean) value).getWritableObject()
		.get();
	value = (boolvalue) ? 1 : 0;
    } else if (value instanceof LazyByte) {
	value = (int) ((LazyByte) value).getWritableObject().get();
    } else if (value instanceof LazyShort) {
	value = ((LazyShort) value).getWritableObject().get();
    }

}

return value;
   }