org.talend.daikon.avro.AvroUtils.isNullable()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(76)

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

AvroUtils.isNullable介绍

暂无

代码示例

代码示例来源:origin: org.talend.components/bigquery-runtime

private TableFieldSchema tryArrayFieldSchema(org.apache.avro.Schema.Field field) {
  String fieldName = field.name();
  TableFieldSchema tableFieldSchema = new TableFieldSchema().setName(fieldName);
  boolean nullable = AvroUtils.isNullable(field.schema());
  if (!nullable) {
    tableFieldSchema = tableFieldSchema.setMode(REQUIRED_MODE);
  }
  org.apache.avro.Schema fieldSchema = AvroUtils.unwrapIfNullable(field.schema());
  if (fieldSchema.getType() == org.apache.avro.Schema.Type.ARRAY) {
    return tryFieldSchema(tableFieldSchema.setMode(REPEATED_MODE), fieldSchema.getElementType());
  }
  return tryFieldSchema(tableFieldSchema, fieldSchema);
}

代码示例来源:origin: Talend/components

private TableFieldSchema tryArrayFieldSchema(org.apache.avro.Schema.Field field) {
  String fieldName = field.name();
  TableFieldSchema tableFieldSchema = new TableFieldSchema().setName(fieldName);
  boolean nullable = AvroUtils.isNullable(field.schema());
  if (!nullable) {
    tableFieldSchema = tableFieldSchema.setMode(REQUIRED_MODE);
  }
  org.apache.avro.Schema fieldSchema = AvroUtils.unwrapIfNullable(field.schema());
  if (fieldSchema.getType() == org.apache.avro.Schema.Type.ARRAY) {
    return tryFieldSchema(tableFieldSchema.setMode(REPEATED_MODE), fieldSchema.getElementType());
  }
  return tryFieldSchema(tableFieldSchema, fieldSchema);
}

代码示例来源:origin: org.talend.components/processing-runtime

if (AvroUtils.isNullable(field.schema()))
  fieldSchema = AvroUtils.wrapAsNullable(fieldSchema);
fieldList.add(new Schema.Field(field.name(), fieldSchema, field.doc(), field.defaultVal()));

代码示例来源:origin: Talend/components

if (AvroUtils.isNullable(field.schema()))
  fieldSchema = AvroUtils.wrapAsNullable(fieldSchema);
fieldList.add(new Schema.Field(field.name(), fieldSchema, field.doc(), field.defaultVal()));

代码示例来源:origin: org.talend.components/components-jdbc-runtime

/**
 * Creates new actual schema from incoming specification <code>schema</code>
 * Actual schema fields has the same names as specification schema, but they have String type
 * Note, getSchema() will return schema, which differs from specification schema passed to this method
 */
// TODO this one more kind of copySchema() method which should be implemented in Daikon see TDKN-96
@Override
public void setSchema(Schema schema) {
  actualSchema = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(), schema.isError());
  
  List<Schema.Field> stringFields = new ArrayList<>();
  for (Schema.Field specField : schema.getFields()) {
    boolean nullable = AvroUtils.isNullable(specField.schema());
    Schema stringSchema = AvroUtils._string();
    if (nullable) {
      stringSchema = AvroUtils.wrapAsNullable(stringSchema);
    }
    Schema.Field stringField = new Schema.Field(specField.name(), stringSchema, specField.doc(), specField.defaultVal(), specField.order());
    for (Map.Entry<String, Object> entry : specField.getObjectProps().entrySet()) {
      stringField.addProp(entry.getKey(), entry.getValue());
    }
    stringFields.add(stringField);
  }
  actualSchema.setFields(stringFields);
  for (Map.Entry<String, Object> entry : schema.getObjectProps().entrySet()) {
    actualSchema.addProp(entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: Talend/components

if (keyValue != null || AvroUtils.isNullable(field.schema())) {
    outputRecord.put(field.name(), keyValue);
if (keyValue != null || AvroUtils.isNullable(field.schema())) {
  outputRecord.put(field.name(), keyValue);
if (valueValue != null || AvroUtils.isNullable(field.schema())) {
  outputRecord.put(field.name(), valueValue);

代码示例来源:origin: Talend/components

/**
 * Creates new actual schema from incoming specification <code>schema</code>
 * Actual schema fields has the same names as specification schema, but they have String type
 * Note, getSchema() will return schema, which differs from specification schema passed to this method
 */
// TODO this one more kind of copySchema() method which should be implemented in Daikon see TDKN-96
@Override
public void setSchema(Schema schema) {
  actualSchema = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(), schema.isError());
  
  List<Schema.Field> stringFields = new ArrayList<>();
  for (Schema.Field specField : schema.getFields()) {
    boolean nullable = AvroUtils.isNullable(specField.schema());
    Schema stringSchema = AvroUtils._string();
    if (nullable) {
      stringSchema = AvroUtils.wrapAsNullable(stringSchema);
    }
    Schema.Field stringField = new Schema.Field(specField.name(), stringSchema, specField.doc(), specField.defaultVal(), specField.order());
    for (Map.Entry<String, Object> entry : specField.getObjectProps().entrySet()) {
      stringField.addProp(entry.getKey(), entry.getValue());
    }
    stringFields.add(stringField);
  }
  actualSchema.setFields(stringFields);
  for (Map.Entry<String, Object> entry : schema.getObjectProps().entrySet()) {
    actualSchema.addProp(entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: org.talend.components/components-adapter-beam

if (keyValue != null || AvroUtils.isNullable(field.schema())) {
    outputRecord.put(field.name(), keyValue);
if (keyValue != null || AvroUtils.isNullable(field.schema())) {
  outputRecord.put(field.name(), keyValue);
if (valueValue != null || AvroUtils.isNullable(field.schema())) {
  outputRecord.put(field.name(), valueValue);

代码示例来源:origin: org.talend.components/bigquery-runtime

private Object convertField(FieldValue fieldValue, org.apache.avro.Schema fieldSchema) {
  boolean nullable = AvroUtils.isNullable(fieldSchema);
  if (nullable && fieldValue.isNull()) {
    return null;
  }
  fieldSchema = AvroUtils.unwrapIfNullable(fieldSchema);
  switch (fieldValue.getAttribute()) {
  case PRIMITIVE:
    if (BigQueryType.TIMESTAMP.toString().equals(fieldSchema.getProp(TALEND_COLUMN_DB_TYPE))) {
      Double doubleValue = ((Long) fieldValue.getTimestampValue()) / 1000000.0;
      return formatTimestamp(doubleValue.toString());
    } else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
      return fieldValue.getDoubleValue();
    } else if (AvroUtils.isSameType(fieldSchema, AvroUtils._boolean())) {
      return fieldValue.getBooleanValue();
    } else {
      return fieldValue.getValue();
    }
  case REPEATED:
    List<Object> listValue = new ArrayList<>();
    List<FieldValue> repeatedChildValue = fieldValue.getRepeatedValue();
    for (FieldValue childValue : repeatedChildValue) {
      listValue.add(convertField(childValue, fieldSchema.getElementType()));
    }
    return listValue;
  case RECORD:
    return convertFileds(fieldValue.getRecordValue(), fieldSchema);
  }
  throw TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_ARGUMENT).create();
}

代码示例来源:origin: Talend/components

private Object convertField(FieldValue fieldValue, org.apache.avro.Schema fieldSchema) {
  boolean nullable = AvroUtils.isNullable(fieldSchema);
  if (nullable && fieldValue.isNull()) {
    return null;
  }
  fieldSchema = AvroUtils.unwrapIfNullable(fieldSchema);
  switch (fieldValue.getAttribute()) {
  case PRIMITIVE:
    if (BigQueryType.TIMESTAMP.toString().equals(fieldSchema.getProp(TALEND_COLUMN_DB_TYPE))) {
      Double doubleValue = ((Long) fieldValue.getTimestampValue()) / 1000000.0;
      return formatTimestamp(doubleValue.toString());
    } else if (AvroUtils.isSameType(fieldSchema, AvroUtils._double())) {
      return fieldValue.getDoubleValue();
    } else if (AvroUtils.isSameType(fieldSchema, AvroUtils._boolean())) {
      return fieldValue.getBooleanValue();
    } else {
      return fieldValue.getValue();
    }
  case REPEATED:
    List<Object> listValue = new ArrayList<>();
    List<FieldValue> repeatedChildValue = fieldValue.getRepeatedValue();
    for (FieldValue childValue : repeatedChildValue) {
      listValue.add(convertField(childValue, fieldSchema.getElementType()));
    }
    return listValue;
  case RECORD:
    return convertFileds(fieldValue.getRecordValue(), fieldSchema);
  }
  throw TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_ARGUMENT).create();
}

相关文章