Flink 1.8.2 state evolution throwing exception - apache-flink

I am trying to alter a case class which has around 240 variable among which some are other pojos which are defined by me
Example : Signal (case class) has variable PowerPojoFeature, UserFeature.
When I alter any of the pojo add new variables it throws below exception
rg.apache.flink.util.StateMigrationException: The new state typeSerializer for operator state must not be incompatible.
at org.apache.flink.runtime.state.DefaultOperatorStateBackend.getListState(DefaultOperatorStateBackend.java:323)
Is there any example I can write custom serialisation for this or any other solution

Flink's serializer doesn't yet support case class evolution. You need to either use POJOs or Avro, or implement a custom serializer.
There are snippets of examples in the documentation for custom serializers.
Another approach would be to use the State Processor API to migrate the state and data type.

Related

Get all object properties in ontology without using reasoner

In OWL API, there method getObjectPropertiesInSignature() can be used to obtain the set of object properties in an ontology. I have two questions with respect to this:
By using this method, will it return also the object properties in imported ontology ?
Also, this method is deprecated in the latest version of OWL API, is there another method with the same behaviour ?
getObjectPropertiesInSignature() has an overloaded version with a boolean flag, its purpose is to allow you to choose to look in the signature of the ontology or in the signature of the imports closure. Use it to get the object properties for the whole imports closure.
The method is deprecated and the javadoc suggests using the stream based method. For all such scenarios in OWLAPI 5, methods named getXxx() have an alternative version named xxx() that returns a stream. It is preferable to use them if you need only one iteration through the underlying collection (it saves having to make defensive copies). If you need multiple iterations or lookups, you can keep using the deprecated methods or collect the data from the stream in a set.

Apex: Setting Properties with the Indexing Notation

Is it possible to set a property on an instance of a class like so;
MyCls item = new MyCls();
item['propName'] = propValue;
No. Apex does not support indexing notation on any object - custom classes, Map instances, or sObjects.
You can use the get() and put() methods on the Map and sObject built- classes to access fields by name or Map values. However, doing so on an sObject loses you compile-time field checking, and typically requires a lot of casting in statically-typed Apex. It's preferable to use standard access when possible.
This does not apply to custom classes unless you implement your own accessor methods.

In logs I see KafkaTopicPartition cannot be used as a POJO; what does that mean?

Not an error but I do see this line that according to the message might effect performance:
2019-01-02 14:44:44,879 INFO org.apache.flink.api.java.typeutils.TypeExtractor
- class org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition
does not contain a setter for field topic
2019-01-02 14:44:44,879 INFO org.apache.flink.api.java.typeutils.TypeExtractor
- Class class org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition
cannot be used as a POJO type because not all fields are valid POJO fields,
and must be processed as GenericType. Please read the Flink documentation on "Data Types & Serialization"
for details of the effect on performance.
2019-01-02 14:44:44,884 INFO org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase - No restore state for FlinkKafkaConsumer.
Is this something that I can/need to do about it ?
This statement about types that cannot be used as POJO types is logged at INFO level rather than WARN because it's often not particularly relevant. But it does sometimes indicate classes that may be causing performance problems. This is because Flink is able to use its own, more performant serialization framework for POJO classes (classes with an empty default constructor and public fields, or public getters and setters), and otherwise falls back to Kyro.
If this were one of your application objects, and if you were going to be serializing and deserializing LOTS of them, then yes, this would be something to consider doing something about. But in this case, no. This is an internal object used by the various Flink/Kafka connectors, and it shouldn't be changed.

SilverStripe: Creating form fields statically and via the 'new' keyword

I've been trying to find some info on difference between instantiating form fields through static method and the new keyword. Can somebody tell me what are the practical implications, limitations, between new MyFormField and MyFormField::create() esp. with regards to SilverStripe
Using the create factory method would check for overloads (set via Object::useCustomClass()) and return an instance of the custom class in that case.
This method first for strong class overloads (singletons & DB
interaction), then custom class overloads. If an overload is found, an
instance of this is returned rather than the original class. To
overload a class, use Object::useCustomClass()
So using the create method rather than instantiating the Object yourself would provide a possibility to overload the used Class without altering the code.
see
http://api.silverstripe.org/3.1/class-Object.html#_useCustomClass
http://api.silverstripe.org/3.1/class-Object.html#_create

Data Contract Serializer mandates super class to know about subclass

I got this problem,
"The deserializer has no knowlege of any type that maps to this contract"
After googling, I reached this post
The deserializer has no knowlege of any type that maps to this contract
where the answer says, the base class have to declare "KnownTypes" like
[DataContract, KnownType(typeof(Subclass)) ...],
If I have to declare this in my parent class, [DataContract, KnownType(typeof(Subclass))], doesn't it break the principles of OO Design that parent class doesn't have to know about subclass?
What is the right way of doing this?
The serializer is designed in a way that, if it serializes an object, it should be able to read it back. If you attempt to serialize an object with a declared type of 'Base', but an actual type of 'Derived' (see example below), if you want to be able to read back from the serialized object an instance of 'Derived', you need to somehow annotate the XML that the instance is not of the type of which it was declared.
[DataContract]
public class MyType
{
[DataMember]
public object obj = new Derived();
}
The serialized version of the type would look something like the XML below:
<MyType>
<obj actualType="Derived">
<!-- fields of the derived type -->
</obj>
</MyType>
When the type is being deserialized, the serializer will look at the "actualType" (not actual name) attribute, and it will have to find that type, initialize it, and set its properties. It's a potential security issue to let the serializer (with in Silverlight lives is a trusted assembly and has more "rights" than the normal user code) to create arbitrary type, so that's one reason for limiting the types which can be deserialized. And based on the design of the serializer (if we can serialize it, we should be able to deserialize it), the serialization fails for that reason as well.
Another problem with that is that the serialized data is often used to communicate between different services, in different computers, and possibly with different languages. It's possible (and often it is the case) that you have a class in a namespace in the client which has a similar data contract to a class in the server side, but they have different names and / or reside in different namespaces. So simply adding the CLR type name in the "actualType" attribute won't work in this scenario either (the [KnownType] attribute helps the serialzier map the data contract name / namespace to the actual CLR type). Also, if you're talking to a service in a different language / platform (i.e., Java), CLR type names don't even make sense.
Another more detailed explanation is given at the post http://www.dotnetconsult.co.uk/weblog2/PermaLink,guid,a3775eb1-b441-43ad-b9f1-e4aaba404235.aspx - it talks about [ServiceKnownType] instead of [KnownType], but the principles are the same.
Finally, about your question: does it break that OO principle? Yes, that principle is broken, that's a price to pay for being able to have lose coupling between the client and services in your distributed (service-oriented) application.
Yes it breaks the principles of OO design. This is because SOA is about sharing contracts (the C in ABC of services) and not types, whereas OO is about type hierarchies. Think like this the client for a service may not be even in an OO language but SOA principles can still be applied. How the mapping is done on server side is an implementation issue.

Resources