@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof DataType)) { return false; } final DataType other = (DataType) obj; return getFieldType().equals(other.getFieldType()) && Objects.equals(getFormat(), other.getFormat()); }
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(); }
private static Long getLongFromTimestamp(final Object rawValue, final Schema fieldSchema, final String fieldName) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); Timestamp t = DataTypeUtils.toTimestamp(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); return t.getTime(); }
@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); }
final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); final Date date = DataTypeUtils.toDate(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); final Duration duration = Duration.between(new Date(0L).toInstant(), new Date(date.getTime()).toInstant()); return (int) days; } else if (LOGICAL_TYPE_TIME_MILLIS.equals(logicalType.getName())) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); final Time time = DataTypeUtils.toTime(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); final Date date = new Date(time.getTime()); return duration.toMillis() * 1000L; } else if (LOGICAL_TYPE_TIMESTAMP_MILLIS.equals(logicalType.getName())) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); Timestamp t = DataTypeUtils.toTimestamp(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); return getLongFromTimestamp(rawValue, fieldSchema, fieldName);
break; case DATE: Date d = record.getAsDate(fieldName, field.getDataType().getFormat()); if(d != null) { org.apache.hadoop.hive.common.type.Date hiveDate = new org.apache.hadoop.hive.common.type.Date(); Timestamp ts = DataTypeUtils.toTimestamp(record.getValue(fieldName), () -> DataTypeUtils.getDateFormat(field.getDataType().getFormat()), fieldName); if(ts != null) {
return isCharacterTypeCompatible(value); case DATE: return isDateTypeCompatible(value, dataType.getFormat()); case DOUBLE: return isDoubleTypeCompatible(value); return isShortTypeCompatible(value); case TIME: return isTimeTypeCompatible(value, dataType.getFormat()); case TIMESTAMP: return isTimestampTypeCompatible(value, dataType.getFormat()); case STRING: return isStringTypeCompatible(value);
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof DataType)) { return false; } final DataType other = (DataType) obj; return getFieldType().equals(other.getFieldType()) && Objects.equals(getFormat(), other.getFormat()); }
private static Long getLongFromTimestamp(final Object rawValue, final Schema fieldSchema, final String fieldName) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); Timestamp t = DataTypeUtils.toTimestamp(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); return t.getTime(); }
@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); }
final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); final Date date = DataTypeUtils.toDate(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); final Duration duration = Duration.between(new Date(0L).toInstant(), new Date(date.getTime()).toInstant()); return (int) days; } else if (LOGICAL_TYPE_TIME_MILLIS.equals(logicalType.getName())) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); final Time time = DataTypeUtils.toTime(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); final Date date = new Date(time.getTime()); return duration.toMillis() * 1000L; } else if (LOGICAL_TYPE_TIMESTAMP_MILLIS.equals(logicalType.getName())) { final String format = AvroTypeUtil.determineDataType(fieldSchema).getFormat(); Timestamp t = DataTypeUtils.toTimestamp(rawValue, () -> DataTypeUtils.getDateFormat(format), fieldName); return getLongFromTimestamp(rawValue, fieldSchema, fieldName);
return isCharacterTypeCompatible(value); case DATE: return isDateTypeCompatible(value, dataType.getFormat()); case DOUBLE: return isDoubleTypeCompatible(value); return isShortTypeCompatible(value); case TIME: return isTimeTypeCompatible(value, dataType.getFormat()); case TIMESTAMP: return isTimestampTypeCompatible(value, dataType.getFormat()); case STRING: return isStringTypeCompatible(value);