• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SpecificRecordBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.avro.specific.SpecificRecordBase的典型用法代码示例。如果您正苦于以下问题:Java SpecificRecordBase类的具体用法?Java SpecificRecordBase怎么用?Java SpecificRecordBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SpecificRecordBase类属于org.apache.avro.specific包,在下文中一共展示了SpecificRecordBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getAvroBuilderClass

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Class<? extends SpecificRecordBuilderBase> getAvroBuilderClass(
    Class<? extends SpecificRecordBase> avroClass) {
  for (Class<?> clazz : avroClass.getClasses()) {
    if (SpecificRecordBuilderBase.class.isAssignableFrom(clazz)) {
      try {
        if (clazz.getMethod("build").getReturnType() != avroClass) {
          continue;
        }
      } catch (NoSuchMethodException expected) {
      }
      return (Class<? extends SpecificRecordBuilderBase>) clazz;
    }
  }
  return null;
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:17,代码来源:AvroJacksonDeserializers.java


示例2: setup

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/** This is the place you can access map-reduce workflow node parameters */
@SuppressWarnings("unchecked")
@Override
protected void setup(Context context) throws IOException, InterruptedException {
    String moduleClassName = context.getConfiguration().get(EXPORT_ACTION_BUILDER_FACTORY_CLASSNAME);
    if (StringUtils.isNotBlank(moduleClassName)) {
        try {
            Class<?> clazz = Class.forName(moduleClassName);
            Constructor<?> constructor = clazz.getConstructor();
            ActionBuilderFactory<SpecificRecordBase> actionBuilderFactory = (ActionBuilderFactory<SpecificRecordBase>) constructor.newInstance();
            actionBuilder = actionBuilderFactory.instantiate(context.getConfiguration(), StaticConfigurationProvider.AGENT_DEFAULT,
                    getActionSetId(actionBuilderFactory.getAlgorithName(), context.getConfiguration()));
        } catch (Exception e) {
            throw new RuntimeException(
                    "unexpected exception ocurred when instantiating " + "builder module: " + moduleClassName, e);
        }
    } else {
        throw new InvalidParameterException("unknown action builder module instance, " + "no "
                + EXPORT_ACTION_BUILDER_FACTORY_CLASSNAME + " parameter provided!");
    }
}
 
开发者ID:openaire,项目名称:iis,代码行数:22,代码来源:SequenceFileExporterMapper.java


示例3: getSpecificProperties

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Build and return properties by specific properties class.
 *
 * @param propertiesClass the class of properties
 * @param <S>             the class of properties
 * @return property instance
 */
public <S extends SpecificRecordBase> S getSpecificProperties(Class<S> propertiesClass) {
  Properties entity = findOrCreateByClass(propertiesClass);
  S specificProperties = null;
  if (entity != null) {
    AvroByteArrayConverter<S> converter =
        new AvroByteArrayConverter<>(propertiesClass);
    try {
      specificProperties = converter.fromByteArray(entity.getRawConfiguration());
    } catch (IOException ex) {
      LOG.error(
          "Unable to parse raw data for specific record " + propertiesClass.getSimpleName(), ex);
    }
  }
  if (specificProperties == null) {
    specificProperties = buildDefaultProperties(propertiesClass);
  }
  return specificProperties;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:26,代码来源:PropertiesFacade.java


示例4: buildDefaultProperties

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
private <S extends SpecificRecordBase> S buildDefaultProperties(Class<S> propertiesClass) {
  S result = null;
  try {
    Schema schema = (Schema) propertiesClass.getField(SCHEMA).get(null);
    RawSchema rawSchema = new RawSchema(schema.toString());
    DefaultRecordGenerationAlgorithm<RawData> algotithm =
        new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory());
    RawData rawData = algotithm.getRootData();
    AvroJsonConverter<S> converter = new AvroJsonConverter<>(schema, propertiesClass);
    result = converter.decodeJson(rawData.getRawData());
  } catch (Exception ex) {
    LOG.error(
        "Unable to build default specific properties for class "
            + propertiesClass.getSimpleName(), ex);
  }
  return result;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:18,代码来源:PropertiesFacade.java


示例5: createDefault

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
private <S extends SpecificRecordBase> Properties createDefault(Class<S> propertiesClass) {
  Properties properties = new Properties();

  S specificProperties = buildDefaultProperties(propertiesClass);
  AvroByteArrayConverter<S> converter =
      new AvroByteArrayConverter<>(propertiesClass);
  try {
    properties.setRawConfiguration(converter.toByteArray(specificProperties));
  } catch (IOException ex) {
    LOG.error("Unable to serialize configuration for properties", ex);
  }
  properties.setFqn(propertiesClass.getName());
  Long id = save(properties);
  properties.setId(id);
  return properties;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:17,代码来源:PropertiesFacade.java


示例6: ProtocolSerializer

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Finds all of the messages in the specified packaged and calls register.
 * @param messagePackage A string which contains the full name of the
 *                       package containing the protocol messages.
 */
@Inject
private ProtocolSerializer(
    @Parameter(ProtocolSerializerNamespace.class) final String messagePackage) {

  // Build a list of the message reflection classes.
  final ScanResult scanResult = new FastClasspathScanner(messagePackage).scan();
  final List<String> scanNames = scanResult.getNamesOfSubclassesOf(SpecificRecordBase.class);
  final List<Class<?>> messageClasses = scanResult.classNamesToClassRefs(scanNames);

  // Add the header message from the org.apache.reef.wake.avro.message package.
  messageClasses.add(Header.class);

  // Register all of the messages in the specified package.
  for (final Class<?> cls : messageClasses) {
    this.register(cls);
  }
}
 
开发者ID:apache,项目名称:reef,代码行数:23,代码来源:ProtocolSerializer.java


示例7: setupModule

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
@Override
public void setupModule(SetupContext context) {
  // Serialization is easy - this mixin disables serialization of the Schema field,
  // and everything else Just Works.
  context.setMixInAnnotations(SpecificRecordBase.class, AvroMappingMixin.class);
  // Deserialization is harder. Registering a custom Deserializers instance allows us to manually
  // construct a JsonDeserializer each time the ObjectMapper encounters a new type, so we can
  // detect SpecificRecordBase subclasses and handle them specially.
  context.addDeserializers(new AvroJacksonDeserializers());
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:11,代码来源:AvroJacksonModule.java


示例8: Kafka09AvroTableSource

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates a Kafka 0.9 Avro {@link StreamTableSource} using a given {@link SpecificRecord}.
 *
 * @param topic      Kafka topic to consume.
 * @param properties Properties for the Kafka consumer.
 * @param schema	 Schema of the produced table.
 * @param record     Avro specific record.
 */
public Kafka09AvroTableSource(
	String topic,
	Properties properties,
	TableSchema schema,
	Class<? extends SpecificRecordBase> record) {

	super(
		topic,
		properties,
		schema,
		record);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:Kafka09AvroTableSource.java


示例9: Kafka08AvroTableSource

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates a Kafka 0.8 Avro {@link StreamTableSource} using a given {@link SpecificRecord}.
 *
 * @param topic      Kafka topic to consume.
 * @param properties Properties for the Kafka consumer.
 * @param schema     Schema of the produced table.
 * @param record     Avro specific record.
 */
public Kafka08AvroTableSource(
	String topic,
	Properties properties,
	TableSchema schema,
	Class<? extends SpecificRecordBase> record) {

	super(
		topic,
		properties,
		schema,
		record);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:Kafka08AvroTableSource.java


示例10: Kafka011AvroTableSource

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates a Kafka 0.11 Avro {@link StreamTableSource} using a given {@link SpecificRecord}.
 *
 * @param topic      Kafka topic to consume.
 * @param properties Properties for the Kafka consumer.
 * @param schema     Schema of the produced table.
 * @param record     Avro specific record.
 */
public Kafka011AvroTableSource(
	String topic,
	Properties properties,
	TableSchema schema,
	Class<? extends SpecificRecordBase> record) {

	super(
		topic,
		properties,
		schema,
		record);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:Kafka011AvroTableSource.java


示例11: Kafka010AvroTableSource

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates a Kafka 0.10 Avro {@link StreamTableSource} using a given {@link SpecificRecord}.
 *
 * @param topic      Kafka topic to consume.
 * @param properties Properties for the Kafka consumer.
 * @param schema     Schema of the produced table.
 * @param record     Avro specific record.
 */
public Kafka010AvroTableSource(
	String topic,
	Properties properties,
	TableSchema schema,
	Class<? extends SpecificRecordBase> record) {

	super(
		topic,
		properties,
		schema,
		record);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:Kafka010AvroTableSource.java


示例12: KafkaAvroTableSource

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates a generic Kafka Avro {@link StreamTableSource} using a given {@link SpecificRecord}.
 *
 * @param topic            Kafka topic to consume.
 * @param properties       Properties for the Kafka consumer.
 * @param schema           Schema of the produced table.
 * @param avroRecordClass  Class of the Avro record that is read from the Kafka topic.
 */
protected KafkaAvroTableSource(
	String topic,
	Properties properties,
	TableSchema schema,
	Class<? extends SpecificRecordBase> avroRecordClass) {

	super(
		topic,
		properties,
		schema,
		convertToRowTypeInformation(avroRecordClass));

	this.avroRecordClass = avroRecordClass;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:KafkaAvroTableSource.java


示例13: convertToRowTypeInformation

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Converts the extracted AvroTypeInfo into a RowTypeInfo nested structure with deterministic field order.
 * Replaces generic Utf8 with basic String type information.
 */
@SuppressWarnings("unchecked")
private static <T extends SpecificRecordBase> TypeInformation<Row> convertToRowTypeInformation(Class<T> avroClass) {
	final AvroTypeInfo<T> avroTypeInfo = new AvroTypeInfo<>(avroClass);
	// determine schema to retrieve deterministic field order
	final Schema schema = SpecificData.get().getSchema(avroClass);
	return (TypeInformation<Row>) convertToTypeInformation(avroTypeInfo, schema);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:KafkaAvroTableSource.java


示例14: ensureCompatibility

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
@Override
public CompatibilityResult<T> ensureCompatibility(TypeSerializerConfigSnapshot configSnapshot) {
	if (configSnapshot instanceof AvroSchemaSerializerConfigSnapshot ||
			configSnapshot instanceof AvroSerializerConfigSnapshot) {

		// avro serializer, nice :-)
		checkState(serializer instanceof AvroSerializer,
				"Serializer was changed backwards to PojoSerializer and now encounters AvroSerializer snapshot.");

		return serializer.ensureCompatibility(configSnapshot);
	}
	else if (configSnapshot instanceof PojoSerializerConfigSnapshot) {
		// common previous case
		checkState(SpecificRecordBase.class.isAssignableFrom(type),
				"BackwardsCompatibleAvroSerializer resuming a state serialized " +
						"via a PojoSerializer, but not for an Avro Specific Record");

		final AvroTypeInfo<? extends SpecificRecordBase> typeInfo =
				new AvroTypeInfo<>(type.asSubclass(SpecificRecordBase.class), true);

		@SuppressWarnings("unchecked")
		final TypeSerializer<T> pojoSerializer =
				(TypeSerializer<T>) typeInfo.createPojoSerializer(new ExecutionConfig());
		this.serializer = pojoSerializer;
		return serializer.ensureCompatibility(configSnapshot);
	}
	else if (configSnapshot instanceof KryoRegistrationSerializerConfigSnapshot) {
		// force-kryo old case common previous case
		// we create a new Kryo Serializer with a blank execution config.
		// registrations are anyways picked up from the snapshot.
		serializer = new KryoSerializer<>(type, new ExecutionConfig());
		return serializer.ensureCompatibility(configSnapshot);
	}
	else {
		// completely incompatible type, needs migration
		return CompatibilityResult.requiresMigration();
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:39,代码来源:BackwardsCompatibleAvroSerializer.java


示例15: generateFieldsFromAvroSchema

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
private static <T extends SpecificRecordBase> List<PojoField> generateFieldsFromAvroSchema(Class<T> typeClass) {
	PojoTypeExtractor pte = new PojoTypeExtractor();
	ArrayList<Type> typeHierarchy = new ArrayList<>();
	typeHierarchy.add(typeClass);
	TypeInformation ti = pte.analyzePojo(typeClass, typeHierarchy, null, null, null);

	if(!(ti instanceof PojoTypeInfo)) {
		throw new IllegalStateException("Expecting type to be a PojoTypeInfo");
	}
	PojoTypeInfo pti =  (PojoTypeInfo) ti;
	List<PojoField> newFields = new ArrayList<>(pti.getTotalFields());

	for(int i = 0; i < pti.getArity(); i++) {
		PojoField f = pti.getPojoFieldAt(i);
		TypeInformation newType = f.getTypeInformation();
		// check if type is a CharSequence
		if(newType instanceof GenericTypeInfo) {
			if((newType).getTypeClass().equals(CharSequence.class)) {
				// replace the type by a org.apache.avro.util.Utf8
				newType = new GenericTypeInfo(org.apache.avro.util.Utf8.class);
			}
		}
		PojoField newField = new PojoField(f.getField(), newType);
		newFields.add(newField);
	}
	return newFields;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:28,代码来源:AvroTypeInfo.java


示例16: getSchema

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 *
 * @param recordClass		Avro record type class
 * @return					the Avro schema for the supplied class
 * @throws ToolException	if an exception is thrown extracting the schema from the record class
 */
public static Schema getSchema(Class<? extends SpecificRecordBase> recordClass) throws ToolException {
	try {
		// Will have a static member SCHEMA$ from which we can parse the schema:
		Field field = recordClass.getDeclaredField("SCHEMA$");
		return (Schema)field.get(null);
	}
	catch (NoSuchFieldException | SecurityException
			| IllegalArgumentException | IllegalAccessException e) {
		throw new ToolException(e);
	}
}
 
开发者ID:conversant,项目名称:mara,代码行数:18,代码来源:AvroUtil.java


示例17: map

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
@Override
protected void map(AvroKey<? extends SpecificRecordBase> key, NullWritable ignore, Context context)
        throws IOException, InterruptedException {
    List<AtomicAction> actions = createActions(key.datum());
    if (actions != null) {
        for (AtomicAction action : actions) {
            Text keyOut = new Text();
            Text valueOut = new Text();
            keyOut.set(action.getRowKey());
            valueOut.set(action.toString());
            context.write(keyOut, valueOut);
        }
    }
}
 
开发者ID:openaire,项目名称:iis,代码行数:15,代码来源:SequenceFileExporterMapper.java


示例18: createActions

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Creates list of actions for given avro object.
 * 
 * @param datum source avro object
 */
private List<AtomicAction> createActions(SpecificRecordBase datum) {
    try {
        return actionBuilder.build(datum);
    } catch (TrustLevelThresholdExceededException e) {
        return Collections.emptyList();
    }
}
 
开发者ID:openaire,项目名称:iis,代码行数:13,代码来源:SequenceFileExporterMapper.java


示例19: serialize

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
public static <T extends SpecificRecordBase> byte[] serialize(T record) throws IOException {
    try {
        DatumWriter<T> writer = new SpecificDatumWriter<T>(record.getSchema());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
        writer.write(record, encoder);
        encoder.flush();
        IOUtils.closeQuietly(out);
        return out.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:hkropp,项目名称:storm-hive-streaming-example,代码行数:15,代码来源:KafkaAvroStockProducer.java


示例20: editPropertiesDto

import org.apache.avro.specific.SpecificRecordBase; //导入依赖的package包/类
/**
 * Found property from database or create new if not found, update it and save to database.
 *
 * @param propertiesDto   the property to update
 * @param propertiesClass the property class
 * @param <S>             the property class
 * @return property dto
 */
public <S extends SpecificRecordBase> PropertiesDto editPropertiesDto(
    PropertiesDto propertiesDto,Class<S> propertiesClass) throws Exception {
  Properties entity = findOrCreateByClass(propertiesClass);
  GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(
      propertiesDto.getConfiguration());
  GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(record.getSchema());
  byte[] rawConfiguration = converter.encode(record);
  entity.setRawConfiguration(rawConfiguration);
  save(entity);
  return toDto(entity, propertiesClass);
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:20,代码来源:PropertiesFacade.java



注:本文中的org.apache.avro.specific.SpecificRecordBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefactoringWizard类代码示例发布时间:2022-05-21
下一篇:
Java PrivateCredentialPermission类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap