public RecordField(final String fieldName, final DataType dataType, final Object defaultValue, final Set<String> aliases, final boolean nullable) { if (defaultValue != null && !DataTypeUtils.isCompatibleDataType(defaultValue, dataType)) { throw new IllegalArgumentException("Cannot set the default value for field [" + fieldName + "] to [" + defaultValue + "] because that is not a valid value for Data Type [" + dataType + "]"); } this.fieldName = Objects.requireNonNull(fieldName); this.dataType = Objects.requireNonNull(dataType); // If aliases is the empty set, don't bother with the expense of wrapping in an unmodifiableSet. Objects.requireNonNull(aliases); if ((Set<?>) aliases == Collections.EMPTY_SET) { this.aliases = aliases; } else { this.aliases = Collections.unmodifiableSet(aliases); } this.defaultValue = defaultValue; this.nullable = nullable; }
private static boolean isCompatibleDataType(final Object value, final DataType dataType) { if (value == null) { return false; } switch (dataType.getFieldType()) { case RECORD: if (value instanceof GenericRecord || value instanceof SpecificRecord) { return true; } break; case STRING: if (value instanceof Utf8) { return true; } break; case ARRAY: if (value instanceof Array || value instanceof List || value instanceof ByteBuffer) { return true; } break; case MAP: if (value instanceof Map) { return true; } } return DataTypeUtils.isCompatibleDataType(value, dataType); }
public static DataType chooseDataType(final Object value, final ChoiceDataType choiceType) { for (final DataType subType : choiceType.getPossibleSubTypes()) { if (isCompatibleDataType(value, subType)) { if (subType.getFieldType() == RecordFieldType.CHOICE) { return chooseDataType(value, (ChoiceDataType) subType); } return subType; } } return null; }
if (subSchema.getLogicalType() != null && DataTypeUtils.isCompatibleDataType(originalValue, desiredDataType)) { return convertedValue;
if (DataTypeUtils.isCompatibleDataType(possibleRecord, possibleDataType)) { return possibleRecord;
case CHAR: case SHORT: if (DataTypeUtils.isCompatibleDataType(trimmed, dataType)) { return DataTypeUtils.convertType(trimmed, dataType, LAZY_DATE_FORMAT, LAZY_TIME_FORMAT, LAZY_TIMESTAMP_FORMAT, fieldName);
private Map<String, Object> checkTypes(final Map<String, Object> values, final RecordSchema schema) { for (final RecordField field : schema.getFields()) { Object value = getExplicitValue(field, values); if (value == null) { if (field.isNullable() || field.getDefaultValue() != null) { continue; } throw new SchemaValidationException("Field " + field.getFieldName() + " cannot be null"); } if (!DataTypeUtils.isCompatibleDataType(value, field.getDataType())) { throw new SchemaValidationException("Field " + field.getFieldName() + " has a value of " + value + ", which cannot be coerced into the appropriate data type of " + field.getDataType()); } } return values; }
if (!DataTypeUtils.isCompatibleDataType(rawValue, dataType)) { result.addValidationError(new StandardValidationError(concat(fieldPrefix, field), rawValue, ValidationErrorType.INVALID_FIELD, "Value is of type " + rawValue.getClass().getName() + " but was expected to be of type " + dataType));
if (!isCompatibleDataType(childValue, childField.getDataType())) { return false;
public RecordField(final String fieldName, final DataType dataType, final Object defaultValue, final Set<String> aliases, final boolean nullable) { if (defaultValue != null && !DataTypeUtils.isCompatibleDataType(defaultValue, dataType)) { throw new IllegalArgumentException("Cannot set the default value for field [" + fieldName + "] to [" + defaultValue + "] because that is not a valid value for Data Type [" + dataType + "]"); } this.fieldName = Objects.requireNonNull(fieldName); this.dataType = Objects.requireNonNull(dataType); // If aliases is the empty set, don't bother with the expense of wrapping in an unmodifiableSet. Objects.requireNonNull(aliases); if ((Set<?>) aliases == Collections.EMPTY_SET) { this.aliases = aliases; } else { this.aliases = Collections.unmodifiableSet(aliases); } this.defaultValue = defaultValue; this.nullable = nullable; }
private static boolean isCompatibleDataType(final Object value, final DataType dataType) { if (value == null) { return false; } switch (dataType.getFieldType()) { case RECORD: if (value instanceof GenericRecord || value instanceof SpecificRecord) { return true; } break; case STRING: if (value instanceof Utf8) { return true; } break; case ARRAY: if (value instanceof Array || value instanceof List || value instanceof ByteBuffer) { return true; } break; case MAP: if (value instanceof Map) { return true; } } return DataTypeUtils.isCompatibleDataType(value, dataType); }
public static DataType chooseDataType(final Object value, final ChoiceDataType choiceType) { for (final DataType subType : choiceType.getPossibleSubTypes()) { if (isCompatibleDataType(value, subType)) { if (subType.getFieldType() == RecordFieldType.CHOICE) { return chooseDataType(value, (ChoiceDataType) subType); } return subType; } } return null; }
if (subSchema.getLogicalType() != null && DataTypeUtils.isCompatibleDataType(originalValue, desiredDataType)) { return convertedValue;
private Map<String, Object> checkTypes(final Map<String, Object> values, final RecordSchema schema) { for (final RecordField field : schema.getFields()) { Object value = getExplicitValue(field, values); if (value == null) { if (field.isNullable() || field.getDefaultValue() != null) { continue; } throw new SchemaValidationException("Field " + field.getFieldName() + " cannot be null"); } if (!DataTypeUtils.isCompatibleDataType(value, field.getDataType())) { throw new SchemaValidationException("Field " + field.getFieldName() + " has a value of " + value + ", which cannot be coerced into the appropriate data type of " + field.getDataType()); } } return values; }
if (!DataTypeUtils.isCompatibleDataType(rawValue, dataType)) { result.addValidationError(new StandardValidationError(concat(fieldPrefix, field), rawValue, ValidationErrorType.INVALID_FIELD, "Value is of type " + rawValue.getClass().getName() + " but was expected to be of type " + dataType));
if (!isCompatibleDataType(childValue, childField.getDataType())) { return false;