org.apache.nifi.serialization.record.DataType类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.apache.nifi.serialization.record.DataType类的一些代码示例,展示了DataType类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataType类的具体详情如下:
包路径:org.apache.nifi.serialization.record.DataType
类名称:DataType

DataType介绍

暂无

代码示例

代码示例来源:origin: apache/nifi

public static boolean isRecord(final DataType dataType, final Object value) {
    if (dataType.getFieldType() == RecordFieldType.RECORD) {
      return true;
    }

    if (value == null) {
      return false;
    }

    if (value instanceof Record) {
      return true;
    }

    return false;
  }
}

代码示例来源:origin: apache/nifi

@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());
}

代码示例来源:origin: apache/nifi

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)));
}

代码示例来源:origin: apache/nifi

throw new IllegalArgumentException("Field type is null");
RecordFieldType dataType = rawDataType.getFieldType();
  if (RecordFieldType.BYTE.getDataType().equals(arrayDataType.getElementType())) {
    return "BINARY";

代码示例来源:origin: apache/nifi

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();
}

代码示例来源:origin: apache/nifi

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) {
log.error("Unknown type found: " + fieldTypeInfo + "for field of type: " + field.getDataType().toString());
return null;

代码示例来源:origin: apache/nifi

recordMap.put(fieldName, convertRecordArrayToJavaArray((Object[])fieldValue, ((ArrayDataType) fieldDataType).getElementType()));
} else {
  throw new IllegalTypeConversionException("Cannot convert value [" + fieldValue + "] of type " + fieldDataType.toString()
      + " to Map for field " + fieldName + " because the type is not supported");

代码示例来源:origin: apache/nifi

RecordFieldType fieldType = dataType.getFieldType();
if (RecordFieldType.INT.equals(fieldType)
    || RecordFieldType.LONG.equals(fieldType)
  if (RecordFieldType.BYTE.getDataType().equals(arrayDataType.getElementType())) {
    return TypeInfoFactory.getPrimitiveTypeInfo("binary");

代码示例来源:origin: apache/nifi

@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);
}

代码示例来源:origin: org.apache.nifi/nifi-record

recordMap.put(fieldName, convertRecordArrayToJavaArray((Object[])fieldValue, ((ArrayDataType) fieldDataType).getElementType()));
} else {
  throw new IllegalTypeConversionException("Cannot convert value [" + fieldValue + "] of type " + fieldDataType.toString()
      + " to Map for field " + fieldName + " because the type is not supported");

代码示例来源:origin: apache/nifi

public static boolean isScalarValue(final DataType dataType, final Object value) {
  final RecordFieldType fieldType = dataType.getFieldType();
  final RecordFieldType chosenType;
  if (fieldType == RecordFieldType.CHOICE) {
    final ChoiceDataType choiceDataType = (ChoiceDataType) dataType;
    final DataType chosenDataType = chooseDataType(value, choiceDataType);
    if (chosenDataType == null) {
      return false;
    }
    chosenType = chosenDataType.getFieldType();
  } else {
    chosenType = fieldType;
  }
  switch (chosenType) {
    case ARRAY:
    case MAP:
    case RECORD:
      return false;
  }
  return true;
}

代码示例来源:origin: apache/nifi

@Override
public int hashCode() {
  return 31 + 41 * getFieldType().hashCode() + 41 * (getFormat() == null ? 0 : getFormat().hashCode());
}

代码示例来源:origin: apache/nifi

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);

代码示例来源:origin: apache/nifi

@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null) {
    return false;
  }
  if (getClass() != obj.getClass()) {
    return false;
  }
  RecordField other = (RecordField) obj;
  return dataType.equals(other.getDataType()) && fieldName.equals(other.getFieldName()) && aliases.equals(other.getAliases()) && Objects.equals(defaultValue, other.defaultValue)
    && nullable == other.nullable;
}

代码示例来源:origin: apache/nifi

protected Object convert(final DataType fieldType, final Object rawValue, final String fieldName) {
  if (fieldType == null) {
    return rawValue;
  }
  if (rawValue == null) {
    return null;
  }
  // If string is empty then return an empty string if field type is STRING. If field type is
  // anything else, we can't really convert it so return null
  final boolean fieldEmpty = rawValue instanceof String && ((String) rawValue).isEmpty();
  if (fieldEmpty && fieldType.getFieldType() != RecordFieldType.STRING) {
    return null;
  }
  return DataTypeUtils.convertType(rawValue, fieldType, fieldName);
}

代码示例来源:origin: apache/nifi

@Override
  public String toString() {
    if (getFormat() == null) {
      return getFieldType().toString();
    } else {
      return getFieldType().toString() + ":" + getFormat();
    }
  }
}

代码示例来源:origin: org.apache.nifi/nifi-avro-record-utils

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();
}

代码示例来源:origin: apache/nifi

@Override
public boolean equals(final Object obj) {
  if (obj == this) {
    return true;
  }
  if (obj == null) {
    return false;
  }
  if (!(obj instanceof MapDataType)) {
    return false;
  }
  final MapDataType other = (MapDataType) obj;
  return getValueType().equals(other.getValueType()) && Objects.equals(valueType, other.valueType);
}

代码示例来源:origin: apache/nifi

private Object parseStringForType(String data, String fieldName, DataType dataType) {
  switch (dataType.getFieldType()) {
    case BOOLEAN:
    case BYTE:
    case CHAR:
    case DOUBLE:
    case FLOAT:
    case INT:
    case LONG:
    case SHORT:
    case STRING:
    case DATE:
    case TIME:
    case TIMESTAMP: {
      return DataTypeUtils.convertType(data, dataType, LAZY_DATE_FORMAT, LAZY_TIME_FORMAT, LAZY_TIMESTAMP_FORMAT, fieldName);
    }
  }
  return null;
}

代码示例来源:origin: apache/nifi

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();
}

相关文章

微信公众号

最新文章

更多