Java Code Examples for org.apache.flink.api.common.ExecutionConfig#addDefaultKryoSerializer()

The following examples show how to use org.apache.flink.api.common.ExecutionConfig#addDefaultKryoSerializer() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void addAvroSerializersIfRequired(ExecutionConfig reg, Class<?> type) {
	if (org.apache.avro.specific.SpecificRecordBase.class.isAssignableFrom(type) ||
		org.apache.avro.generic.GenericData.Record.class.isAssignableFrom(type)) {

		// Avro POJOs contain java.util.List which have GenericData.Array as their runtime type
		// because Kryo is not able to serialize them properly, we use this serializer for them
		reg.registerTypeWithKryoSerializer(GenericData.Array.class, Serializers.SpecificInstanceCollectionSerializerForArrayList.class);

		// We register this serializer for users who want to use untyped Avro records (GenericData.Record).
		// Kryo is able to serialize everything in there, except for the Schema.
		// This serializer is very slow, but using the GenericData.Records of Kryo is in general a bad idea.
		// we add the serializer as a default serializer because Avro is using a private sub-type at runtime.
		reg.addDefaultKryoSerializer(Schema.class, AvroSchemaSerializer.class);
	}
}
 
Example 2
Source Project: flink   File: AvroKryoSerializerUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addAvroSerializersIfRequired(ExecutionConfig reg, Class<?> type) {
	if (org.apache.avro.specific.SpecificRecordBase.class.isAssignableFrom(type) ||
		org.apache.avro.generic.GenericData.Record.class.isAssignableFrom(type)) {

		// Avro POJOs contain java.util.List which have GenericData.Array as their runtime type
		// because Kryo is not able to serialize them properly, we use this serializer for them
		reg.registerTypeWithKryoSerializer(GenericData.Array.class, Serializers.SpecificInstanceCollectionSerializerForArrayList.class);

		// We register this serializer for users who want to use untyped Avro records (GenericData.Record).
		// Kryo is able to serialize everything in there, except for the Schema.
		// This serializer is very slow, but using the GenericData.Records of Kryo is in general a bad idea.
		// we add the serializer as a default serializer because Avro is using a private sub-type at runtime.
		reg.addDefaultKryoSerializer(Schema.class, AvroSchemaSerializer.class);
	}
}
 
Example 3
@Benchmark
@OperationsPerInvocation(value = SerializationFrameworkMiniBenchmarks.RECORDS_PER_INVOCATION)
public void serializerKryoThrift(FlinkEnvironmentContext context) throws Exception {
	StreamExecutionEnvironment env = context.env;
	env.setParallelism(4);
	ExecutionConfig executionConfig = env.getConfig();
	executionConfig.enableForceKryo();
	executionConfig.addDefaultKryoSerializer(org.apache.flink.benchmark.thrift.MyPojo.class, TBaseSerializer.class);
	executionConfig.addDefaultKryoSerializer(org.apache.flink.benchmark.thrift.MyOperation.class, TBaseSerializer.class);

	env.addSource(new ThriftPojoSource(RECORDS_PER_INVOCATION, 10))
			.rebalance()
			.addSink(new DiscardingSink<>());

	env.execute();
}
 
Example 4
Source Project: flink   File: AvroKryoSerializerUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addAvroSerializersIfRequired(ExecutionConfig reg, Class<?> type) {
	if (org.apache.avro.specific.SpecificRecordBase.class.isAssignableFrom(type) ||
		org.apache.avro.generic.GenericData.Record.class.isAssignableFrom(type)) {

		// Avro POJOs contain java.util.List which have GenericData.Array as their runtime type
		// because Kryo is not able to serialize them properly, we use this serializer for them
		reg.registerTypeWithKryoSerializer(GenericData.Array.class, Serializers.SpecificInstanceCollectionSerializerForArrayList.class);

		// We register this serializer for users who want to use untyped Avro records (GenericData.Record).
		// Kryo is able to serialize everything in there, except for the Schema.
		// This serializer is very slow, but using the GenericData.Records of Kryo is in general a bad idea.
		// we add the serializer as a default serializer because Avro is using a private sub-type at runtime.
		reg.addDefaultKryoSerializer(Schema.class, AvroSchemaSerializer.class);
	}
}
 
Example 5
@Test
public void testDuplicateSerializerWithDefaultSerializerClass() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, TestSerializer.class);
	runDuplicateSerializerTest(executionConfig);
}
 
Example 6
@Test
public void testDuplicateSerializerWithDefaultSerializerInstance() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, new TestSerializer());
	runDuplicateSerializerTest(executionConfig);
}
 
Example 7
@Test
public void testDuplicateSerializerWithDefaultSerializerClass() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, TestSerializer.class);
	runDuplicateSerializerTest(executionConfig);
}
 
Example 8
@Test
public void testDuplicateSerializerWithDefaultSerializerInstance() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, new TestSerializer());
	runDuplicateSerializerTest(executionConfig);
}
 
Example 9
@Test
public void testDuplicateSerializerWithDefaultSerializerClass() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, TestSerializer.class);
	runDuplicateSerializerTest(executionConfig);
}
 
Example 10
@Test
public void testDuplicateSerializerWithDefaultSerializerInstance() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.addDefaultKryoSerializer(WrappedString.class, new TestSerializer());
	runDuplicateSerializerTest(executionConfig);
}