public DecimalConverter getDecimalConverter(int precision, int scale) { if (precision < 0) { return new LVBytesDecimalConverter(); } else if (precision <= 9) { return new DecimalIntConverter(scale); } else if (precision <= 18) { return new DecimalLongConverter(scale); } else { return new DecimalUnscaledConverter(precision, scale); } }
/** * Set the precision if it is decimal type */ public void setPrecision(int precision) { this.precision = precision; if (DataTypes.isDecimal(dataType)) { ((DecimalType) dataType).setPrecision(precision); } }
private void initComplexTypeChildren() { if (getDataType().isComplexType()) { StructField subFields = prepareSubFields(getFieldName(), getDataType()); if (DataTypes.isArrayType(getDataType()) || DataTypes.isMapType(getDataType())) { children = subFields.getChildren(); } else if (DataTypes.isStructType(getDataType())) { children = ((StructType) subFields.getDataType()).getFields(); } } }
/** * the method prepares and return the message mentioning the reason of badrecord * * @param columnName * @param dataType * @return */ public static String prepareFailureReason(String columnName, DataType dataType) { return "The value with column name " + columnName + " and column data type " + dataType .getName() + " is not a valid " + dataType + " type."; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + getName().hashCode(); result = prime * result + getElementType().hashCode(); return result; }
@Override public int getLength() { if (length == 0) { return dataType.getSizeInBytes(); } else { return length; } }
/** * create array type with specified element type */ public static ArrayType createArrayType(DataType elementType) { return new ArrayType(elementType); }
/** * create a decimal type object with specified precision and scale */ public static DecimalType createDecimalType(int precision, int scale) { return new DecimalType(precision, scale); }
/** * create map type with specified key type and value type */ public static MapType createMapType(DataType keyType, DataType valueType) { return new MapType(keyType, valueType); }
/** * create struct type with specified fields */ public static StructType createStructType(List<StructField> fields) { return new StructType(fields); }
private int[] minBytesForPrecision() { int[] data = new int[39]; for (int i = 0; i < data.length; i++) { data[i] = computeMinBytesForPrecision(i); } return data; }
public static boolean isMapType(DataType dataType) { return dataType.getId() == MAP_TYPE_ID; }
/** * Gives length in case of fixed schema other wise returns length * * @return */ public int getLength() { return dataType.getSizeInBytes(); }
/** * create a array type object with no child */ public static ArrayType createDefaultArrayType() { return new ArrayType(STRING); }
/** * create a decimal type object with default precision = 10 and scale = 2 */ public static DecimalType createDefaultDecimalType() { return new DecimalType(10, 2); }
/** * create a map type object with no child */ public static MapType createDefaultMapType() { return new MapType(STRING, STRING); }
@Override public int getLength() { return dataType.getSizeInBytes(); }