当前位置: 首页>>代码示例>>Java>>正文


Java NullNode.getInstance方法代码示例

本文整理汇总了Java中org.codehaus.jackson.node.NullNode.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java NullNode.getInstance方法的具体用法?Java NullNode.getInstance怎么用?Java NullNode.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.node.NullNode的用法示例。


在下文中一共展示了NullNode.getInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSchema

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
public static Schema getSchema(SeekableInput input) throws IOException
{
    DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
    DataFileReader<GenericRecord> dataFileReader =
            new DataFileReader<GenericRecord>(input, datumReader);
    Schema schema = dataFileReader.getSchema();

    if (PadDefaultNullsToSchema)
    {
        // a list of "cloned" fields, with optional default value set to null
        ArrayList<Field> paddedFields = new ArrayList<Field>();

        for (Field field: schema.getFields())
        {
            // should this field be padded?
            boolean needsNullPadding = (field.schema() != null) // the field has nested schema
                && (field.schema().getType().equals(Type.UNION)) // the nested schema is UNION
                && (field.schema().getTypes().get(0).getType().equals(Type.NULL)); // the first element of union is NULL type

            JsonNode defValue = needsNullPadding ? NullNode.getInstance() : field.defaultValue();

            Field f = new Field(field.name(), field.schema(), field.doc(), defValue);
            paddedFields.add(f);
        }

        schema = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(), schema.isError());
        schema.setFields(paddedFields);
    }

    return schema;
}
 
开发者ID:linkedin,项目名称:Cubert,代码行数:32,代码来源:AvroUtils.java

示例2: generate

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
public Schema generate(String schemaNameOverride) throws IOException {
  ClassWriter classWriter = new ClassWriter(options, connManager,
      tableName, null);
  Map<String, Integer> columnTypes = classWriter.getColumnTypes();
  String[] columnNames = classWriter.getColumnNames(columnTypes);

  List<Field> fields = new ArrayList<Field>();
  for (String columnName : columnNames) {
    String cleanedCol = AvroUtil.toAvroIdentifier(ClassWriter.toJavaIdentifier(columnName));
    int sqlType = columnTypes.get(columnName);
    Schema avroSchema = toAvroSchema(sqlType, columnName);
    Field field = new Field(cleanedCol, avroSchema, null,  NullNode.getInstance());
    field.addProp("columnName", columnName);
    field.addProp("sqlType", Integer.toString(sqlType));
    fields.add(field);
  }

  TableClassName tableClassName = new TableClassName(options);
  String shortClassName = tableClassName.getShortClassForTable(tableName);
  String avroTableName = (tableName == null ? TableClassName.QUERY_RESULT : tableName);
  String avroName = schemaNameOverride != null ? schemaNameOverride :
      (shortClassName == null ? avroTableName : shortClassName);
  String avroNamespace = tableClassName.getPackageForTable();

  String doc = "Sqoop import of " + avroTableName;
  Schema schema = Schema.createRecord(avroName, doc, avroNamespace, false);
  schema.setFields(fields);
  schema.addProp("tableName", avroTableName);
  return schema;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:31,代码来源:AvroSchemaGenerator.java

示例3: updateUnionFields

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
private Schema updateUnionFields(Schema schema) {
    Schema updatedSchema = schema;
    List<Schema.Field> fields = schema.getFields();
    boolean hasUnionType = false;
    List<Schema.Field> updatedFields = new ArrayList<>(fields.size());
    for (Schema.Field field : fields) {
        Schema fieldSchema = field.schema();
        Schema.Field updatedField = field;
        // if it is union and first type is null then set default value as null
        if (fieldSchema.getType() == Schema.Type.UNION &&
                fieldSchema.getTypes().get(0).getType() == Schema.Type.NULL) {
            updatedField = new Schema.Field(field.name(), fieldSchema, field.doc(), NullNode.getInstance(), field.order());
            hasUnionType = true;
        }
        updatedFields.add(updatedField);
    }

    if (hasUnionType) {
        updatedSchema = Schema.createRecord(schema.getName(), schema.getDoc(), schema.getNamespace(), schema.isError());
        updatedSchema.setFields(updatedFields);
        for (String alias : schema.getAliases()) {
            updatedSchema.addAlias(alias);
        }
        for (Map.Entry<String, org.codehaus.jackson.JsonNode> nodeEntry : schema.getJsonProps().entrySet()) {
            updatedSchema.addProp(nodeEntry.getKey(), nodeEntry.getValue());
        }
    }

    return updatedSchema;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:31,代码来源:AvroSchemaResolver.java

示例4: getDefaultValue

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
/**
 * Returns default value for given field or null if no default value should be used.
 */
private JsonNode getDefaultValue(Schema schema) {
  if(defaultValuesForTypes.containsKey(schema.getType())) {
    return defaultValuesForTypes.get(schema.getType());
  }

  if(getConfig().avroNullableFields && getConfig().avroDefaultNullable) {
    return NullNode.getInstance();
  }

  return null;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:15,代码来源:AvroSchemaGenerator.java

示例5: generateAvroField

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
public static Schema.Field generateAvroField(SchemaField field) {
    return new Schema.Field(field.getName(), generateAvroSchema(field.getType()), null, NullNode.getInstance());
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:4,代码来源:AvroUtil.java

示例6: optionalField

import org.codehaus.jackson.node.NullNode; //导入方法依赖的package包/类
public static Schema.Field optionalField(String name, Schema schema) {
  return new Schema.Field(name, optional(schema), null, NullNode.getInstance());
}
 
开发者ID:apache,项目名称:parquet-mr,代码行数:4,代码来源:AvroTestUtil.java


注:本文中的org.codehaus.jackson.node.NullNode.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。