Skip to content

Commit

Permalink
Merge pull request #3082 from redpanda-data/avro-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
rockwotj authored Dec 16, 2024
2 parents 91688b9 + fb0a1f4 commit 7bf9f79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Changelog

All notable changes to this project will be documented in this file.

## 4.45.0 - TBD

### Added

- `avro` scanner now emits metadata for the Avro schema it used along with the schema fingerprint (@rockwotj)

## 4.44.0 - 2024-12-13

### Added
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/components/pages/scanners/avro.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ For example, the union schema `["null","string","Foo"]`, where `Foo` is a record
However, it is possible to instead create documents in https://pkg.go.dev/github.com/linkedin/goavro/v2#NewCodecForStandardJSONFull[standard/raw JSON format^] by setting the field <<avro_raw_json,`avro_raw_json`>> to `true`.
This scanner also emits the canonical Avro schema as `@avro_schema` metadata, along with the schema's fingerprint available via `@avro_schema_fingerprint`.
== Fields
Expand Down
7 changes: 6 additions & 1 deletion internal/impl/avro/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ For example, the union schema ` + "`[\"null\",\"string\",\"Foo\"]`, where `Foo`"
- a ` + "`Foo` instance as `{\"Foo\": {...}}`, where `{...}` indicates the JSON encoding of a `Foo`" + ` instance.
However, it is possible to instead create documents in https://pkg.go.dev/github.com/linkedin/goavro/v2#NewCodecForStandardJSONFull[standard/raw JSON format^] by setting the field ` + "<<avro_raw_json,`avro_raw_json`>> to `true`" + `.
This scanner also emits the canonical Avro schema as ` + "`@avro_schema`" + ` metadata, along with the schema's fingerprint available via ` + "`@avro_schema_fingerprint`" + `.
`).
Fields(
service.NewBoolField(sFieldRawJSON).
Expand Down Expand Up @@ -133,7 +135,10 @@ func (c *avroScanner) NextBatch(ctx context.Context) (service.MessageBatch, erro
if err != nil {
return nil, fmt.Errorf("failed to decode OCF datum to JSON: %s", err)
}
return service.MessageBatch{service.NewMessage(jb)}, nil
msg := service.NewMessage(jb)
msg.MetaSetMut("avro_schema", c.avroCodec.CanonicalSchema())
msg.MetaSetMut("avro_schema_fingerprint", c.avroCodec.Rabin)
return service.MessageBatch{msg}, nil
}

func (c *avroScanner) Close(ctx context.Context) error {
Expand Down

0 comments on commit 7bf9f79

Please sign in to comment.