/** * Adds fields to <tt>recordFields</tt> list. * @param recordFields - record fields are added to this list. * @param field - the field * @param fieldName - field name * @param fieldSchema - field schema * @param dataType - data type * @param nullable - is nullable? */ private static void addFieldToList(final List<RecordField> recordFields, final Field field, final String fieldName, final Schema fieldSchema, final DataType dataType, final boolean nullable) { if (field.defaultVal() == JsonProperties.NULL_VALUE) { recordFields.add(new RecordField(fieldName, dataType, field.aliases(), nullable)); } else { Object defaultValue = field.defaultVal(); if (fieldSchema.getType() == Schema.Type.ARRAY && !DataTypeUtils.isArrayTypeCompatible(defaultValue, ((ArrayDataType) dataType).getElementType())) { defaultValue = defaultValue instanceof List ? ((List<?>) defaultValue).toArray() : new Object[0]; } recordFields.add(new RecordField(fieldName, dataType, defaultValue, field.aliases(), nullable)); } }
public static boolean isCompatibleDataType(final Object value, final DataType dataType) { switch (dataType.getFieldType()) { case ARRAY: return isArrayTypeCompatible(value, ((ArrayDataType) dataType).getElementType()); case BIGINT: return isBigIntTypeCompatible(value);
/** * Adds fields to <tt>recordFields</tt> list. * @param recordFields - record fields are added to this list. * @param field - the field * @param fieldName - field name * @param fieldSchema - field schema * @param dataType - data type * @param nullable - is nullable? */ private static void addFieldToList(final List<RecordField> recordFields, final Field field, final String fieldName, final Schema fieldSchema, final DataType dataType, final boolean nullable) { if (field.defaultVal() == JsonProperties.NULL_VALUE) { recordFields.add(new RecordField(fieldName, dataType, field.aliases(), nullable)); } else { Object defaultValue = field.defaultVal(); if (fieldSchema.getType() == Schema.Type.ARRAY && !DataTypeUtils.isArrayTypeCompatible(defaultValue, ((ArrayDataType) dataType).getElementType())) { defaultValue = defaultValue instanceof List ? ((List<?>) defaultValue).toArray() : new Object[0]; } recordFields.add(new RecordField(fieldName, dataType, defaultValue, field.aliases(), nullable)); } }
public static boolean isCompatibleDataType(final Object value, final DataType dataType) { switch (dataType.getFieldType()) { case ARRAY: return isArrayTypeCompatible(value, ((ArrayDataType) dataType).getElementType()); case BIGINT: return isBigIntTypeCompatible(value);