-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
standalone deser #239
standalone deser #239
Conversation
src/jackdaw/specs.clj
Outdated
:opt-un [::schema | ||
::schema-filename] | ||
:req-un [::serde-keyword | ||
::key?])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth have the req-un
before that opt-un
. I feel I see that most commonly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I'm still working on the test coverage and CHANGELOG update |
We may want to create a separate top-level function for when a deserializer-only serde is wanted. That feels a bit safer to me than relaxing the current spec. |
Codecov Report
@@ Coverage Diff @@
## master #239 +/- ##
==========================================
- Coverage 80.30% 80.02% -0.28%
==========================================
Files 42 42
Lines 2660 2673 +13
Branches 153 153
==========================================
+ Hits 2136 2139 +3
- Misses 371 381 +10
Partials 153 153
Continue to review full report at Codecov.
|
cb1eb1e
to
1fbe16e
Compare
Thanks Charles, I think the current version of the PR does what you want. |
@@ -18,3 +18,16 @@ | |||
{:avro/schema schema | |||
:key? key? | |||
:avro/coercion-cache coercion-cache}))) | |||
|
|||
(defn reader-serde | |||
"Creates a serde for Avro data with an optional schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't take a schema.
src/jackdaw/specs.clj
Outdated
:req-un [::serde-keyword | ||
::key?] | ||
:opt-un [::schema | ||
::schema-filename])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::key?
is only needed for the Schema Registry. We can probably reuse :jackdaw.serde/serde
defined above.
Let's modify the spec to take an optional key named ::reader-only?
. When true, ::schema
, ::schema-filename
, and ::key?
are not required. When false or missing, only ::key?
and one of ::schema
and ::schema-filename
are required.
this looser spec (see :jackdaw.serde/confluent-avro-reader-serde and | ||
:jackdaw.serde/confluent-avro-serde)." | ||
[schema-registry-url schema key? & [opts-map]] | ||
(serde schema-registry-url schema key? opts-map)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should call jsa/serde
without a schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can set a value for :reader-only?
so the user doesn't have to.
src/jackdaw/serdes/resolver.clj
Outdated
(throw (ex-info "Invalid serde config." | ||
(s/explain-data :jackdaw.serde/confluent-avro-serde serde-config))) | ||
(s/explain-data spec-key serde-config))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serde-resolver requires a schema. Can we back out these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's only the serialization side that uses it, and the current kafka-productionised code looks up everything using the resolver
An alternate approach would be to allow the resolver (or something with a similar API) to return a wrapper with only the deserializer
field.
The current approach is compatible with the existing code paths because the expected deserializer field is present and the resolver adds the expected conversions on read, I'm open to other options but would like to limit the scope of the API change. What about creating a wrapper where the deserializer
works via the schema registry and the serializer
simply throws an informative error?
src/jackdaw/serdes/resolver.clj
Outdated
@@ -54,12 +54,16 @@ | |||
(let [schema (cond | |||
schema-filename (load-schema serde-config) | |||
schema schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you plan to handle the case where schema
and schema-filename
are not supplied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch - my test should have caught that but did not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cond
just works that way, but I added an explicit nil for clarity
(ins)user=> (cond true 1)
1
(ins)user=> (cond false 1)
nil
I thought that this PR #157 meant that |
I think this is true - but the spec used by the resolver would still fail, and I think I want that entry point. |
;; by providing :serde/type of :read-only we can allow a serde without local schema | ||
reader-avro-config {:serde-keyword :jackdaw.serdes.avro.confluent/serde | ||
:key? false | ||
:serde-type :read-only} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather have this work like :key?
.
Example:
{:serde-keyword :jackdaw.serdes.avro.confluent/serde
:key? false
:read-only? true}
Or if :key?
is not required:
{:serde-keyword :jackdaw.serdes.avro.confluent/serde
:read-only? true}
What happened to |
@@ -39,6 +39,8 @@ | |||
Options: | |||
schema-registry-url - The URL for the schema registry | |||
type-registry - A mapping per jackdaw.serdes.avro/+base-schema-type-registry+> | |||
read-only - Specifies that you will not be using the resulting serializer, | |||
and does not require a schema or schema-filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if you try to write with a read-only avro serdes?
Would be nice to get a clean error message, as debugging avro error is a black art at the best of times!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an informative message, and a test of that message.
With a multi-spec a separate top level definition isn't needed - if the |
4203495
to
8e9460a
Compare
src/jackdaw/specs.clj
Outdated
::key?])) | ||
|
||
(s/def :jackdaw.serde/confluent-avro-serde | ||
(s/multi-spec avro-serde-type :read-only?)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extend the existing key group?
(s/def :jackdaw.serde/confluent-avro-serde
(s/keys :req-un [::serde-keyword
::key?
(or ::read-only? ::schema ::schema-filename)])
56a1df5
to
3f1db89
Compare
@@ -671,7 +674,8 @@ | |||
{:keys [avro/schema | |||
avro/coercion-cache | |||
key? | |||
deserializer-properties] | |||
deserializer-properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it pre-exists this pr, introduced in commt #8551c18c836b7b52e0a0b16b9b041d30b3eb4a0c
src/jackdaw/specs.clj
Outdated
::read-only?)]) | ||
#(exactly-one-true? (string? (:schema %)) | ||
(string? (:schema-filename %)) | ||
(true? (:read-only? %))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we agreed just to check for the key's presence or absence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misunderstood - easy enough to fix
3f1db89
to
6640303
Compare
6640303
to
6df5f40
Compare
Updates some stale comments.
Changes the spec for avro serdes so that the schema document is optional. This allows a reader to continue using a topic as the producer evolves their schema, without updating the schemas documents in lockstep.
Checklist