-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ClassTag is provided in params in deserialization schema factory … (#…
…1499) * ClassTag is provided in params so one deserialization schema factory will work for multiple deserialization schemas * Code review fixes * Code review fixes - code formatting * Migration guide. * Add AvroSchemaDeterminer with fallback to fixed String schema.
- Loading branch information
Showing
16 changed files
with
177 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 26 additions & 3 deletions
29
...a/pl/touk/nussknacker/engine/avro/schemaregistry/BasedOnVersionAvroSchemaDeterminer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,44 @@ | ||
package pl.touk.nussknacker.engine.avro.schemaregistry | ||
|
||
import cats.data.Validated | ||
import pl.touk.nussknacker.engine.avro.{AvroSchemaDeterminer, SchemaDeterminerError, RuntimeSchemaData} | ||
import cats.data.Validated.Valid | ||
import org.apache.avro.Schema | ||
import pl.touk.nussknacker.engine.avro.{AvroSchemaDeterminer, RuntimeSchemaData, SchemaDeterminerError} | ||
|
||
class BasedOnVersionAvroSchemaDeterminer(schemaRegistryClient: SchemaRegistryClient, | ||
topic: String, | ||
versionOption: SchemaVersionOption) extends AvroSchemaDeterminer { | ||
versionOption: SchemaVersionOption, | ||
isKey: Boolean) extends AvroSchemaDeterminer { | ||
|
||
override def determineSchemaUsedInTyping: Validated[SchemaDeterminerError, RuntimeSchemaData] = { | ||
val version = versionOption match { | ||
case ExistingSchemaVersion(v) => Some(v) | ||
case LatestSchemaVersion => None | ||
} | ||
schemaRegistryClient | ||
.getFreshSchema(topic, version, isKey = false) | ||
.getFreshSchema(topic, version, isKey = isKey) | ||
.leftMap(err => new SchemaDeterminerError(s"Fetching schema error for topic: $topic, version: $versionOption", err)) | ||
.map(withMetadata => RuntimeSchemaData(withMetadata.schema, Some(withMetadata.id))) | ||
} | ||
|
||
} | ||
|
||
class BasedOnVersionWithFallbackAvroSchemaDeterminer(schemaRegistryClient: SchemaRegistryClient, | ||
topic: String, | ||
versionOption: SchemaVersionOption, | ||
isKey: Boolean, | ||
schema: Schema | ||
) extends AvroSchemaDeterminer { | ||
|
||
override def determineSchemaUsedInTyping: Validated[SchemaDeterminerError, RuntimeSchemaData] = { | ||
val version = versionOption match { | ||
case ExistingSchemaVersion(v) => Some(v) | ||
case LatestSchemaVersion => None | ||
} | ||
schemaRegistryClient | ||
.getFreshSchema(topic, version, isKey = isKey) | ||
.map(withMetadata => RuntimeSchemaData(withMetadata.schema, Some(withMetadata.id))) | ||
.orElse(Valid(RuntimeSchemaData(schema, None))) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.