本文整理汇总了Java中org.apache.avro.SchemaBuilder.record方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder.record方法的具体用法?Java SchemaBuilder.record怎么用?Java SchemaBuilder.record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.SchemaBuilder
的用法示例。
在下文中一共展示了SchemaBuilder.record方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: schemaFor
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
private static Schema schemaFor(StructType structType, String record, String namespace, int recordCount) {
// Increment after using the recordCount
record = (null == record) ? "record" + recordCount++ : record;
LOG.debug("Converting {} to Avro Record schema [{}:{}]", structType, record, namespace);
SchemaBuilder.RecordBuilder<Schema> schema = SchemaBuilder.record(record);
if (null != namespace) {
schema.namespace(namespace);
}
schema.doc("Auto-generated from Spark DataFrame");
SchemaBuilder.FieldAssembler<Schema> assembler = schema.fields();
StructField[] structFields = structType.fields();
for (StructField f : structFields) {
assembler.name(f.name()).type(typeFor(f.dataType(), f.nullable(), recordCount)).noDefault();
}
return assembler.endRecord();
}
示例2: createSchemaFor
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
/**
* Generate a schema with given schema name and has one field of STRING type
* for each dimension and one field of LONG type for each metric
* @param schemaName
* @param dimensions
* @param metrics
* @return
*/
public static Schema createSchemaFor(String schemaName, String[] dimensions,
String[] metrics) {
FieldAssembler<Schema> fields;
RecordBuilder<Schema> record = SchemaBuilder.record(schemaName);
fields = record.namespace("com.linkedin.thirdeye.join").fields();
for (String dimension : dimensions) {
fields = fields.name(dimension).type().nullable().stringType()
.noDefault();
}
for (String metric : metrics) {
fields = fields.name(metric).type().nullable().longType().longDefault(0);
}
Schema schema = fields.endRecord();
return schema;
}
示例3: record
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
@Override
public RecordContext record(String name) {
RecordBuilder<?> recordBuilder = SchemaBuilder.record(name);
return new RecordContextImpl(recordBuilder);
}
示例4: getSchemaForTriplesMap
import org.apache.avro.SchemaBuilder; //导入方法依赖的package包/类
protected Schema getSchemaForTriplesMap(TriplesMapGraph graph, String triplesMapId)
{
TriplesMap map = graph.getTriplesMap(triplesMapId);
RecordBuilder<Schema> rb = SchemaBuilder.record("subjr"+(id++));
Set<String> currentPredicates = new HashSet<String>();
FieldAssembler<Schema> fieldAssembler = rb.fields();
for(PredicateObjectMap pom : map.getPredicateObjectMaps())
{
boolean isMap = false;
Schema targetSchema = null;
String predicateShortHand = null;
if(pom.getPredicate().getTemplate().getAllColumnNameTermElements().isEmpty())
{
String predicate = pom.getPredicate().getTemplate().getR2rmlTemplateString(rep);
predicateShortHand = shortHandURIGenerator.getShortHand(predicate).toString().replaceAll("[^\\w]", "_");
}
else
{
isMap = true;
}
if(pom.getObject() != null && pom.getObject().hasRefObjectMap())
{
RefObjectMap refObjectMap = pom.getObject().getRefObjectMap();
if(!refObjectMap.getParentTriplesMap().getId().equalsIgnoreCase(triplesMapId))
{
targetSchema = triplesMapIdToSchema.get(refObjectMap.getParentTriplesMap().getId());
}
}
if(currentPredicates.add(predicateShortHand))
{
fieldAssembler = addField(fieldAssembler, pom, isMap,
targetSchema, predicateShortHand);
}
else
{
//TODO handle conflicting types
LOG.warn("Duplicate predicate detected in schema");
}
}
fieldAssembler = fieldAssembler.name("id").type().unionOf().array().items().stringType().and().stringType().and().nullType().endUnion().noDefault();
fieldAssembler = fieldAssembler.name("rdf_type").type().unionOf().array().items().stringType().and().stringType().and().nullType().endUnion().noDefault();
return fieldAssembler.endRecord();
}