當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.defaultValue方法代碼示例

本文整理匯總了Java中org.apache.avro.Schema.Field.defaultValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.defaultValue方法的具體用法?Java Field.defaultValue怎麽用?Java Field.defaultValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.avro.Schema.Field的用法示例。


在下文中一共展示了Field.defaultValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: injectDefaultValueIfAvailable

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private void injectDefaultValueIfAvailable(final JsonParser in, String fieldName) throws IOException {
	Field field = findField(schema, fieldName);
	
	if (field == null) {
		throw new AvroTypeException("Expected field name not found: " + fieldName);
	}
	
	JsonNode defVal = field.defaultValue();
	if (defVal == null) {
		throw new AvroTypeException("Expected field name not found: " + fieldName);
	}
	
	List<JsonElement> result = new ArrayList<>(2);
	JsonParser traverse = defVal.traverse();
	JsonToken nextToken;
	while ((nextToken = traverse.nextToken()) != null) {
		if (nextToken.isScalarValue()) {
			result.add(new JsonElement(nextToken, traverse.getText()));
		} else {
			result.add(new JsonElement(nextToken));
		}
	}
	result.add(NULL_JSON_ELEMENT);
	if (currentReorderBuffer == null) {
		currentReorderBuffer = new ReorderBuffer();
	}
	currentReorderBuffer.origParser = in;
	this.in = makeParser(result);
}
 
開發者ID:Celos,項目名稱:avro-json-decoder,代碼行數:30,代碼來源:ExtendedJsonDecoder.java

示例2: checkReaderWriterRecordFields

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private SchemaCompatibilityResult checkReaderWriterRecordFields(final Schema reader,
    final Schema writer,
    final Stack<String> location) {
  SchemaCompatibilityResult result = SchemaCompatibilityResult.compatible();     
  location.push("fields");
  // Check that each field in the reader record can be populated from
  // the writer record:
  for (final Field readerField : reader.getFields()) {
    location.push(Integer.toString(readerField.pos()));
    final Field writerField = lookupWriterField(writer, readerField);
    if (writerField == null) {
      // Reader field does not correspond to any field in the writer
      // record schema, so the reader field must have a default value.
      if (readerField.defaultValue() == null) {
        // reader field has no default value
        result = result.mergedWith(SchemaCompatibilityResult.incompatible(
            SchemaIncompatibilityType.READER_FIELD_MISSING_DEFAULT_VALUE, reader, writer,
            readerField.name(), location));
      }
    } else {
      result = result.mergedWith(getCompatibility("type", readerField.schema(),
          writerField.schema(), location));
    }
    // POP field index
    location.pop();
  }
  // All fields in the reader record can be populated from the writer
  // record:
  // POP "fields" literal
  location.pop();
  return result;
}
 
開發者ID:HotelsDotCom,項目名稱:avro-compatibility,代碼行數:33,代碼來源:SchemaCompatibility.java

示例3: getRecordSchemaWithDirtySupport

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
private static Schema getRecordSchemaWithDirtySupport(Schema originalSchema, Map<Schema,Schema> queue) throws IOException {
  if (originalSchema.getType() != Type.RECORD) {
    throw new IOException("Gora only supports record schemas.");
  }
  List<Field> originalFields = originalSchema.getFields();
  /* make sure the schema doesn't contain the field __g__dirty */
  for (Field field : originalFields) {
    if (GORA_RESERVED_NAMES.contains(field.name())) {
      throw new IOException(
        "Gora schemas cannot contain the field name " + field.name());
    }
  }
  Schema newSchema = Schema.createRecord(originalSchema.getName(),
  originalSchema.getDoc(), originalSchema.getNamespace(),
  originalSchema.isError());
  
  queue.put(originalSchema, newSchema);
  
  List<Field> newFields = new ArrayList<>();
  byte[] defaultDirtyBytesValue = new byte[getNumberOfBytesNeededForDirtyBits(originalSchema)];
  Arrays.fill(defaultDirtyBytesValue, (byte) 0);
  JsonNode defaultDirtyJsonValue = JsonNodeFactory.instance
    .binaryNode(defaultDirtyBytesValue);
  Field dirtyBits = new Field(DIRTY_BYTES_FIELD_NAME,
    Schema.create(Type.BYTES),
    "Bytes used to represent weather or not a field is dirty.",
    defaultDirtyJsonValue);
  newFields.add(dirtyBits);
  for (Field originalField : originalFields) {
    // recursively add dirty support
    Field newField = new Field(originalField.name(),
      getSchemaWithDirtySupport(originalField.schema(),queue),
      originalField.doc(), originalField.defaultValue(),
      originalField.order());
    newFields.add(newField);
  }
  newSchema.setFields(newFields);
  return newSchema;
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:40,代碼來源:GoraCompiler.java

示例4: defaultFor

import org.apache.avro.Schema.Field; //導入方法依賴的package包/類
public static String defaultFor(Field field) {

		JsonNode dflt = field.defaultValue();
		if (dflt == null || dflt instanceof NullNode) return null;

		return dflt.asText();
	}
 
開發者ID:Comcast,項目名稱:pipeclamp,代碼行數:8,代碼來源:AvroUtil.java


注:本文中的org.apache.avro.Schema.Field.defaultValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。