private String getFormat(final RecordField field) { final DataType dataType = field.getDataType(); switch (dataType.getFieldType()) { case DATE: return dateFormat; case TIME: return timeFormat; case TIMESTAMP: return timestampFormat; } return dataType.getFormat(); }
@Override public String toString() { if (getFormat() == null) { return getFieldType().toString(); } else { return getFieldType().toString() + ":" + getFormat(); } } }
public static boolean isArrayTypeCompatible(final Object value, final DataType elementDataType) { return value != null // Either an object array or a String to be converted to byte[] && (value instanceof Object[] || (value instanceof String && RecordFieldType.BYTE.getDataType().equals(elementDataType))); }
private FieldValue missingChild(final FieldValue parent) { final RecordField field = new RecordField(childName, RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.STRING.getDataType(), RecordFieldType.RECORD.getDataType())); return new StandardFieldValue(null, field, parent); }
@Override public Object[] getValues() { final Object[] values = new Object[schema.getFieldCount()]; int i = 0; for (final RecordField recordField : schema.getFields()) { Object value = getExplicitValue(recordField); if (value == null) { value = recordField.getDefaultValue(); } values[i++] = value; } return values; }
private boolean isFieldPresent(final RecordField field, final Record record) { final Set<String> rawFieldNames = record.getRawFieldNames(); if (rawFieldNames.contains(field.getFieldName())) { return true; } for (final String alias : field.getAliases()) { if (rawFieldNames.contains(alias)) { return true; } } return false; }
@Override public String getAsString(final String fieldName) { final Optional<DataType> dataTypeOption = schema.getDataType(fieldName); if (dataTypeOption.isPresent()) { return convertToString(getValue(fieldName), dataTypeOption.get().getFormat()); } return DataTypeUtils.toString(getValue(fieldName), (Supplier<DateFormat>) null); }
@Override public int hashCode() { return 31 + 41 * getFieldType().hashCode() + 41 * (getFormat() == null ? 0 : getFormat().hashCode()); }
private String concat(final String fieldPrefix, final RecordField field) { return fieldPrefix + "/" + field.getFieldName(); } }
@Override public Record next() throws IOException { if (count >= maxRecords) { return null; } final Record record = original.next(); if (record != null) { count++; } return record; } };
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { if (schemaIdentifier.getName().isPresent()) { return retrieveSchemaByName(schemaIdentifier); } else { return retrieveSchemaByIdAndVersion(schemaIdentifier); } }
@Override public String getAsString(final RecordField field, final String format) { return convertToString(getValue(field), format); }
@Override public RecordSchema getSchema() throws IOException { return original.getSchema(); }
@Override public String toString() { return RecordFieldType.RECORD.toString(); } }
private RecordFieldType(final String simpleName, final String defaultFormat) { this.simpleName = simpleName; this.defaultFormat = defaultFormat; this.defaultDataType = new DataType(this, defaultFormat); }
@Override public SchemaIdentifier build() { return new StandardSchemaIdentifier(name, identifier, version, branch); } }
@Override public Record next() throws IOException { if (pushback != null) { final Record record = pushback; pushback = null; return record; } return original.next(); }
@Override public String getAsString(final String fieldName, final String format) { return convertToString(getValue(fieldName), format); }
@Override public RecordSchema getSchema() throws IOException { return original.getSchema(); }