本文整理了Java中org.apache.avro.Protocol.getType()
方法的一些代码示例,展示了Protocol.getType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.getType()
方法的具体详情如下:
包路径:org.apache.avro.Protocol
类名称:Protocol
方法名:getType
[英]Returns the named type.
[中]返回指定的类型。
代码示例来源:origin: apache/avro
@Override
public Schema apply(final String f) {
return symbolTable.getType(f);
}
}
代码示例来源:origin: apache/avro
public Object respond(Message message, Object request)
throws AvroRemoteException {
GenericRecord params = (GenericRecord)request;
if ("hello".equals(message.getName())) {
LOG.info("hello: "+params.get("greeting"));
return new Utf8("goodbye");
}
if ("echo".equals(message.getName())) {
Object record = params.get("record");
LOG.info("echo: "+record);
return record;
}
if ("echoBytes".equals(message.getName())) {
Object data = params.get("data");
LOG.info("echoBytes: "+data);
return data;
}
if ("error".equals(message.getName())) {
if (throwUndeclaredError) throw new RuntimeException("foo");
GenericRecord error =
new GenericData.Record(PROTOCOL.getType("TestError"));
error.put("message", new Utf8("an error"));
throw new AvroRemoteException(error);
}
throw new AvroRuntimeException("unexpected message: "+message.getName());
}
代码示例来源:origin: apache/avro
@Test
public void testEcho() throws IOException {
GenericRecord record =
new GenericData.Record(PROTOCOL.getType("TestRecord"));
record.put("name", new Utf8("foo"));
record.put("kind", new GenericData.EnumSymbol
(PROTOCOL.getType("Kind"), "BAR"));
record.put("hash", new GenericData.Fixed
(PROTOCOL.getType("MD5"),
new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
GenericRecord params =
new GenericData.Record(PROTOCOL.getMessages().get("echo").getRequest());
params.put("record", record);
Object echoed = requestor.request("echo", params);
assertEquals(record, echoed);
}
代码示例来源:origin: apache/avro
for (Field f : PROTOCOL.getType("TestRecord").getFields())
fields.add(new Field(f.name(), f.schema(), null, null));
fields.add(new Field("extra", Schema.create(Schema.Type.BOOLEAN),
rec.put("name", new Utf8("foo"));
rec.put("kind", new GenericData.EnumSymbol
(PROTOCOL.getType("Kind"), "BAR"));
rec.put("hash", new GenericData.Fixed
(PROTOCOL.getType("MD5"),
new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
rec.put("extra", Boolean.TRUE);
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addIdAsDouble(double id) {
this.idRecord = new GenericData.Record( protocol.getType( "Id" ) );
idRecord.put( "value", id );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addIdAsFloat(float id) {
this.idRecord = new GenericData.Record( protocol.getType( "Id" ) );
idRecord.put( "value", id );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addFieldWithSerializableFieldable(byte[] fieldable) {
GenericRecord customFieldable = new GenericData.Record( protocol.getType( "CustomFieldable" ) );
customFieldable.put( "instance", ByteBuffer.wrap( fieldable ) );
fieldables.add( customFieldable );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addIdAsLong(long id) {
this.idRecord = new GenericData.Record( protocol.getType( "Id" ) );
idRecord.put( "value", id );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addIdAsString(String id) {
this.idRecord = new GenericData.Record( protocol.getType( "Id" ) );
idRecord.put( "value", id );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addPurgeAll(String entityClassName) {
int classRef = getClassReference( entityClassName );
GenericRecord purgeAll = new GenericData.Record( protocol.getType( "PurgeAll" ) );
purgeAll.put( "class", classRef );
operations.add( purgeAll );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addDocument() {
document = new GenericData.Record( protocol.getType( "Document" ) );
//backwards compatibility: we used to have a boost here in Lucene 3 / Hibernate Search 4.x
//With Lucene 3 there was a notion of "Document level boost" which was then dropped.
//Using the constant 1f doesn't hurt as it would be multiplied by the field boost,
//which in the new design incorporates the factor.
document.put( "boost", 1f );
document.put( "fieldables", fieldables );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addDelete(String entityClassName) {
int classRef = getClassReference( entityClassName );
GenericRecord delete = new GenericData.Record( protocol.getType( "Delete" ) );
delete.put( "class", classRef );
delete.put( "id", idRecord );
operations.add( delete );
idRecord = null;
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addDocValuesFieldWithNumericValue(long value, LuceneFieldContext context) {
GenericRecord record = new GenericData.Record( protocol.getType( "NumericDocValuesField" ) );
record.put( "name", context.getName() );
record.put( "type", context.getDocValuesType() );
record.put( "value", value );
fieldables.add( record );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addDeleteByQuery(String entityClassName, DeletionQuery deletionQuery) {
int classRef = getClassReference( entityClassName );
GenericRecord deleteByQuery = new GenericData.Record( protocol.getType( "DeleteByQuery" ) );
deleteByQuery.put( "class", classRef );
deleteByQuery.put( "key", deletionQuery.getQueryKey() );
deleteByQuery.put( "query", Arrays.asList( deletionQuery.serialize() ) );
operations.add( deleteByQuery );
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addAdd(String entityClassName, Map<String, String> fieldToAnalyzerMap) {
int classRef = getClassReference( entityClassName );
GenericRecord add = new GenericData.Record( protocol.getType( "Add" ) );
add.put( "class", classRef );
add.put( "id", idRecord );
add.put( "document", document );
add.put( "fieldToAnalyzerMap", fieldToAnalyzerMap );
operations.add( add );
idRecord = null;
clearDocument();
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addUpdate(String entityClassName, Map<String, String> fieldToAnalyzerMap) {
int classRef = getClassReference( entityClassName );
GenericRecord update = new GenericData.Record( protocol.getType( "Update" ) );
update.put( "class", classRef );
update.put( "id", idRecord );
update.put( "document", document );
update.put( "fieldToAnalyzerMap", fieldToAnalyzerMap );
operations.add( update );
idRecord = null;
clearDocument();
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void addDocValuesFieldWithBinaryValue(LuceneFieldContext context) {
GenericRecord record = new GenericData.Record( protocol.getType( "BinaryDocValuesField" ) );
record.put( "name", context.getName() );
record.put( "type", context.getDocValuesType() );
BytesRef binaryValue = context.getBinaryValue();
record.put( "value", ByteBuffer.wrap( binaryValue.bytes, binaryValue.offset, binaryValue.length ) );
record.put( "offset", 0 );
record.put( "length", binaryValue.length );
fieldables.add( record );
}
代码示例来源:origin: elodina/xml-avro
public static void xmlToAvro(File xmlFile, File avroFile) throws IOException, SAXException {
Schema schema = protocol.getType("Element");
Document doc = parse(xmlFile);
DatumWriter<GenericRecord> datumWriter = new SpecificDatumWriter<>(schema);
try (DataFileWriter<GenericRecord> fileWriter = new DataFileWriter<>(datumWriter)) {
fileWriter.create(schema, avroFile);
fileWriter.append(wrapElement(doc.getDocumentElement()));
}
}
代码示例来源:origin: hibernate/hibernate-search
private GenericRecord createNormalField(String schemaName, LuceneFieldContext context) {
GenericRecord field = new GenericData.Record( protocol.getType( schemaName ) );
field.put( "name", context.getName() );
field.put( "boost", context.getBoost() );
field.put( "omitNorms", context.isOmitNorms() );
field.put( "omitTermFreqAndPositions", context.isOmitTermFreqAndPositions() );
return field;
}
代码示例来源:origin: hibernate/hibernate-search
private GenericRecord createNumericField(String schemaName, LuceneNumericFieldContext context) {
GenericRecord numericField = new GenericData.Record( protocol.getType( schemaName ) );
numericField.put( "name", context.getName() );
numericField.put( "precisionStep", context.getPrecisionStep() );
numericField.put( "store", context.getStore() );
numericField.put( "indexed", context.isIndexed() );
numericField.put( "boost", context.getBoost() );
numericField.put( "omitNorms", context.getOmitNorms() );
numericField.put( "omitTermFreqAndPositions", context.getOmitTermFreqAndPositions() );
return numericField;
}
内容来源于网络,如有侵权,请联系作者删除!