confluentinc / ksql

The database purpose-built for stream processing applications.
https://ksqldb.io
Other
128 stars 1.04k forks source link

Improve KsqlSerdeFactory for Public API Consumption #4441

Open agavra opened 4 years ago

agavra commented 4 years ago

If KsqlSerdeFactory is going to become part of our public API then we should give it some love to make it more extensible, e.g.:

Originally posted by @big-andy-coates in https://github.com/confluentinc/ksql/pull/4437

big-andy-coates commented 4 years ago

We should also look at the Format interface too. The recent work I've done removes any reference to Connect types. But I also think we should plan for extension with our public APIs.

For example, Format currently has two methods for converting between ParsedSchema and List<SingleColumn>. I recently added FormatInfo as a parameter to one of these. In the future that would be a breaking change. Hence we should pass some kind of Context object as a parameter. This provides a way of passing new things to these methods without needing to change the syntax of the method or requiring existing user's custom serde classes to change.

e.g.

  default List<SimpleColumn> toColumns(ParsedSchema schema, ToColumnContext context) {
    throw new KsqlException("Format does not implement Schema Registry support: " + name());
  }

  default ParsedSchema toParsedSchema(List<SimpleColumn> columns, FromColumnContext context) {
    throw new KsqlException("Format does not implement Schema Registry support: " + name());
  }

Initially, both ToColumnContext and FromColumnContext can have a single getter to obtain the FormatInfo. In the future, more getters can be added without requiring a signature change,