org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveDecimalObjectInspector Java Examples
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveDecimalObjectInspector.
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: TestParquetDecimalScaling.java From presto with Apache License 2.0 | 6 votes |
public ObjectInspector getParquetObjectInspector() { if (!forceFixedLengthArray && precision > 0 && precision < 10) { return javaIntObjectInspector; } if (!forceFixedLengthArray && precision >= 10 && precision < 18) { return javaLongObjectInspector; } if (precision > 38 || precision < 0) { throw new IllegalArgumentException("Scale cannot be greater than 38 or less than 0"); } return new JavaHiveDecimalObjectInspector(new DecimalTypeInfo(precision, scale)); }
Example #2
Source File: AbstractTestParquetReader.java From presto with Apache License 2.0 | 5 votes |
@Test public void testParquetLongDecimalWriteToPrestoDecimalWithNonMatchingScale() throws Exception { tester.testRoundTrip( new JavaHiveDecimalObjectInspector(new DecimalTypeInfo(38, 10)), ImmutableList.of(HiveDecimal.create(100 * longTenToNth(10), 10)), ImmutableList.of(new SqlDecimal(BigInteger.valueOf(100 * longTenToNth(9)), 38, 9)), createDecimalType(38, 9)); }
Example #3
Source File: CobolNumberField.java From Cobol-to-Hive with Apache License 2.0 | 4 votes |
@Override public Object deserialize(byte[] rowBytes) throws CobolSerdeException { byte[] temp = transcodeField(super.getBytes(rowBytes)); String s1 = new String(temp); if (this.compType > 0) { if (this.compType == 3) { s1 = unpackData(super.getBytes(rowBytes), this.decimalLocation); }else if(this.compType == 4){ s1 = getBinary(super.getBytes(rowBytes), this.decimalLocation); } } //} else if (this.decimalLocation > 0) { else { //Now calling unpackSign on all numeric fields for which compType resolves to 0. // //The function will check to see if the least significant byte has been overpunched with a sign and //return a negative number if a negative sign is found. s1 = unpackSign(super.getBytes(rowBytes), this.decimalLocation); } // else if (this.decimalLocation > 0) { // s1 = s1.substring(0, this.length * this.divideFactor // - this.decimalLocation) // + "." // + s1.substring(this.length * this.divideFactor // - this.decimalLocation); // } // System.out.println(name + "\t - " + s1 + "\t:" + offset + "\t@" // + length); try { switch (((PrimitiveTypeInfo) this.typeInfo).getPrimitiveCategory()) { case LONG: return Long.parseLong(s1.trim()); case SHORT: return Short.parseShort(s1.trim()); case INT: return Integer.parseInt(s1.trim()); case BYTE: return Byte.parseByte(s1.trim()); case FLOAT: return Float.parseFloat(s1.trim()); case DOUBLE: return Double.parseDouble(s1.trim()); case DECIMAL: BigDecimal bd = new BigDecimal(s1); HiveDecimal dec = HiveDecimal.create(bd); JavaHiveDecimalObjectInspector oi = (JavaHiveDecimalObjectInspector) PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector((DecimalTypeInfo) this.typeInfo); return oi.set(null, dec); } } catch (Exception e) { return null; // if cannot be converted make it null } return null; }