本文整理匯總了Java中org.apache.avro.Schema.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Schema.toString方法的具體用法?Java Schema.toString怎麽用?Java Schema.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.avro.Schema
的用法示例。
在下文中一共展示了Schema.toString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: internalValidate
import org.apache.avro.Schema; //導入方法依賴的package包/類
private void internalValidate(Schema schema) throws SchemaValidationException {
if (schema.getType() == RECORD) {
String name = schema.getFullName();
if (recordTypeNames.contains(name)) {
return;
}
recordTypeNames.add(name);
for (Field field : schema.getFields()) {
internalValidate(field.schema());
}
} else if (schema.getType() == MAP) {
internalValidate(schema.getValueType());
} else if (schema.getType() == ARRAY) {
internalValidate(schema.getElementType());
} else if (schema.getType() == UNION) {
boolean containsBytes = false;
boolean containsString = false;
for (Schema unionSchema : schema.getTypes()) {
if (unionSchema.getType() == Schema.Type.BYTES) {
containsBytes = true;
} else if (unionSchema.getType() == Schema.Type.STRING) {
containsString = true;
}
if (containsBytes && containsString) {
String message = "Schema contains a variant of union[bytes, string]: " + unionSchema.toString();
throw new SchemaValidationException(message);
}
if (COMPOSITE_TYPES.contains(unionSchema)) {
internalValidate(unionSchema);
}
}
}
}
示例2: computeSchema
import org.apache.avro.Schema; //導入方法依賴的package包/類
private Schema computeSchema(String streamName, SamzaSqlRelMessage relMessage) {
List<Schema.Field> keyFields = new ArrayList<>();
List<String> fieldNames = relMessage.getFieldNames();
List<Object> values = relMessage.getFieldValues();
for (int index = 0; index < fieldNames.size(); index++) {
if (fieldNames.get(index).equals(SamzaSqlRelMessage.KEY_NAME) || values.get(index) == null) {
continue;
}
Object value = values.get(index);
Schema avroType;
if (value instanceof GenericData.Record) {
avroType = ((GenericData.Record) value).getSchema();
} else {
avroType = ReflectData.get().getSchema(value.getClass());
}
keyFields.add(new Schema.Field(fieldNames.get(index), avroType, "", null));
}
Schema ks = Schema.createRecord(streamName, "", streamName + "_namespace", false);
ks.setFields(keyFields);
String schemaStr = ks.toString();
Schema schema;
// See whether we have a schema object corresponding to the schemaValue and reuse it.
// CachedSchemaRegistryClient doesn't like if we recreate schema objects.
if (_schemas.containsKey(schemaStr)) {
schema = _schemas.get(schemaStr);
} else {
schema = Schema.parse(schemaStr);
_schemas.put(schemaStr, schema);
}
return schema;
}
示例3: downloadContent
import org.apache.avro.Schema; //導入方法依賴的package包/類
/**
* Get the avro schema from the active editor and display it in a text format.
*
* @param editor
*/
public void downloadContent(AvroSchemaEditor editor) {
/*
Schema schema = SchemaBuilder
.unionOf()
.record("Author")
.fields()
.name("name").type().stringType().noDefault()
.name("birthday").type().longType().noDefault()
.endRecord().and()
.record("Book")
.fields()
.name("title").type().stringType().noDefault()
.name("author").type().unionOf()
.type("Author").and()
.stringType().endUnion()
.noDefault()
.endRecord().endUnion();
*/
RootNode rootNode = editor.getContext().getRootNode();
IEditorConfiguration editorConfiguration = editor.getEditorConfiguration();
AvroSchemaGenerator schemaGenerator = editorConfiguration.getGenerator(editor.getContext());
Schema schema = schemaGenerator.generate(rootNode);
String content = schema == null ? "" : schema.toString(true);
text.setText(content);
}
示例4: assertSchemaContains
import org.apache.avro.Schema; //導入方法依賴的package包/類
static void assertSchemaContains(Schema schemaSubset, Schema original) {
String subset = schemaSubset.toString(false);
String whole = original.toString(false);
assertTrue(String.format("Subset '%s' not found in '%s'", subset, whole),
whole.contains(subset));
}
示例5: format
import org.apache.avro.Schema; //導入方法依賴的package包/類
public String format(String content) {
Schema schema = new Schema.Parser().parse(content);
return schema.toString(true);
}