本文整理汇总了Java中org.codehaus.jackson.node.NullNode类的典型用法代码示例。如果您正苦于以下问题:Java NullNode类的具体用法?Java NullNode怎么用?Java NullNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NullNode类属于org.codehaus.jackson.node包,在下文中一共展示了NullNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: deSchema
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
public static SchemaComponent deSchema(String name, JsonNode n)
{
if (n.isObject())
return deSchema(name, (ObjectNode)n);
if (n.isArray())
return deSchema(name, (ArrayNode)n);
if (n.isBoolean())
return deSchema(name, (BooleanNode)n);
if(n.isInt())
return deSchema(name, (IntNode)n);
if (n.isFloatingPointNumber())
return deSchema(name, (DoubleNode)n);
if (n.isNull())
return deSchema(name, (NullNode)n);
return null;
}
示例3: inferSchema
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
/**
* It takes a record structure in <String, HiveTypeInfo> format.
* Generate a schema and return in String.
* @param record : record structure
* @return String representation of Avro schema.
* @throws StageException: If record contains unsupported type
*/
@Override
public String inferSchema(Map<String, HiveTypeInfo> record)
throws StageException
{
Map<String, Schema> fields = new LinkedHashMap<>();
for(Map.Entry<String, HiveTypeInfo> pair: record.entrySet()) {
if(!HiveMetastoreUtil.validateObjectName(pair.getKey())) {
throw new HiveStageCheckedException(Errors.HIVE_30, pair.getKey());
}
Schema columnSchema = Schema.createUnion(ImmutableList.of(Schema.create(Schema.Type.NULL), traverse(pair)));
// We always set default value to null
columnSchema.addProp("default", NullNode.getInstance());
fields.put(pair.getKey(), columnSchema);
}
Schema schema = buildSchema(fields);
return schema.toString();
}
示例4: convertFields
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
private Schema convertFields(String name, List<Type> parquetFields) {
List<Schema.Field> fields = new ArrayList<Schema.Field>();
for (Type parquetType : parquetFields) {
Schema fieldSchema = convertField(parquetType);
if (parquetType.isRepetition(REPEATED)) {
throw new UnsupportedOperationException("REPEATED not supported outside LIST or MAP. Type: " + parquetType);
} else if (parquetType.isRepetition(Type.Repetition.OPTIONAL)) {
fields.add(new Schema.Field(
parquetType.getName(), optional(fieldSchema), null, NullNode.getInstance()));
} else { // REQUIRED
fields.add(new Schema.Field(parquetType.getName(), fieldSchema, null, null));
}
}
Schema schema = Schema.createRecord(name, null, null, false);
schema.setFields(fields);
return schema;
}
示例5: testUnionOfTwoTypes
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
@Test
public void testUnionOfTwoTypes() throws Exception {
Schema schema = Schema.createRecord("record2", null, null, false);
Schema multipleTypes = Schema.createUnion(Arrays.asList(Schema.create(Schema.Type
.NULL),
Schema.create(INT),
Schema.create(Schema.Type.FLOAT)));
schema.setFields(Arrays.asList(
new Schema.Field("myunion", multipleTypes, null, NullNode.getInstance())));
// Avro union is modelled using optional data members of the different
// types. This does not translate back into an Avro union
testAvroToParquetConversion(
schema,
"message record2 {\n" +
" optional group myunion {\n" +
" optional int32 member0;\n" +
" optional float member1;\n" +
" }\n" +
"}\n");
}
示例6: testArrayOfOptionalRecords
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
@Test
public void testArrayOfOptionalRecords() throws Exception {
Schema innerRecord = Schema.createRecord("element", null, null, false);
Schema optionalString = optional(Schema.create(Schema.Type.STRING));
innerRecord.setFields(Lists.newArrayList(
new Schema.Field("s1", optionalString, null, NullNode.getInstance()),
new Schema.Field("s2", optionalString, null, NullNode.getInstance())
));
Schema schema = Schema.createRecord("HasArray", null, null, false);
schema.setFields(Lists.newArrayList(
new Schema.Field("myarray", Schema.createArray(optional(innerRecord)),
null, null)
));
System.err.println("Avro schema: " + schema.toString(true));
testRoundTripConversion(NEW_BEHAVIOR, schema, "message HasArray {\n" +
" required group myarray (LIST) {\n" +
" repeated group list {\n" +
" optional group element {\n" +
" optional binary s1 (UTF8);\n" +
" optional binary s2 (UTF8);\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n");
}
示例7: testArrayOfOptionalRecordsOldBehavior
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
@Test
public void testArrayOfOptionalRecordsOldBehavior() throws Exception {
Schema innerRecord = Schema.createRecord("InnerRecord", null, null, false);
Schema optionalString = optional(Schema.create(Schema.Type.STRING));
innerRecord.setFields(Lists.newArrayList(
new Schema.Field("s1", optionalString, null, NullNode.getInstance()),
new Schema.Field("s2", optionalString, null, NullNode.getInstance())
));
Schema schema = Schema.createRecord("HasArray", null, null, false);
schema.setFields(Lists.newArrayList(
new Schema.Field("myarray", Schema.createArray(optional(innerRecord)),
null, null)
));
System.err.println("Avro schema: " + schema.toString(true));
// Cannot use round-trip assertion because InnerRecord optional is removed
testAvroToParquetConversion(schema, "message HasArray {\n" +
" required group myarray (LIST) {\n" +
" repeated group array {\n" +
" optional binary s1 (UTF8);\n" +
" optional binary s2 (UTF8);\n" +
" }\n" +
" }\n" +
"}\n");
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: _bindAsTree
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
protected JsonNode _bindAsTree(JsonParser paramJsonParser)
throws IOException, JsonParseException, JsonMappingException
{
JsonToken localJsonToken = _initForReading(paramJsonParser);
if ((localJsonToken == JsonToken.VALUE_NULL) || (localJsonToken == JsonToken.END_ARRAY) || (localJsonToken == JsonToken.END_OBJECT));
DeserializationContext localDeserializationContext;
for (Object localObject = NullNode.instance; ; localObject = (JsonNode)_findRootDeserializer(this._config, JSON_NODE_TYPE).deserialize(paramJsonParser, localDeserializationContext))
{
paramJsonParser.clearCurrentToken();
return localObject;
localDeserializationContext = _createDeserializationContext(paramJsonParser, this._config);
}
}
示例12: readTree
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
public JsonNode readTree(InputStream paramInputStream)
throws IOException, JsonProcessingException
{
Object localObject = (JsonNode)readValue(paramInputStream, JSON_NODE_TYPE);
if (localObject == null)
localObject = NullNode.instance;
return (JsonNode)localObject;
}
示例13: readTree
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
public JsonNode readTree(File paramFile)
throws IOException, JsonParseException
{
Object localObject = (JsonNode)objectMapper().readValue(paramFile, JsonNode.class);
if (localObject == null)
localObject = NullNode.instance;
return (JsonNode)localObject;
}
示例14: testOptionalFields
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
@Test
public void testOptionalFields() throws Exception {
Schema schema = Schema.createRecord("record1", null, null, false);
Schema optionalInt = optional(Schema.create(INT));
schema.setFields(Arrays.asList(
new Schema.Field("myint", optionalInt, null, NullNode.getInstance())
));
testRoundTripConversion(
schema,
"message record1 {\n" +
" optional int32 myint;\n" +
"}\n");
}
示例15: testOldAvroListOfLists
import org.codehaus.jackson.node.NullNode; //导入依赖的package包/类
@Test
public void testOldAvroListOfLists() throws Exception {
Schema listOfLists = optional(Schema.createArray(Schema.createArray(
Schema.create(INT))));
Schema schema = Schema.createRecord("AvroCompatListInList", null, null, false);
schema.setFields(Lists.newArrayList(
new Schema.Field("listOfLists", listOfLists, null, NullNode.getInstance())
));
System.err.println("Avro schema: " + schema.toString(true));
testRoundTripConversion(schema,
"message AvroCompatListInList {\n" +
" optional group listOfLists (LIST) {\n" +
" repeated group array (LIST) {\n" +
" repeated int32 array;\n" +
" }\n" +
" }\n" +
"}");
// Cannot use round-trip assertion because 3-level representation is used
testParquetToAvroConversion(NEW_BEHAVIOR, schema,
"message AvroCompatListInList {\n" +
" optional group listOfLists (LIST) {\n" +
" repeated group array (LIST) {\n" +
" repeated int32 array;\n" +
" }\n" +
" }\n" +
"}");
}