本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}