s3

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package s3 provides a replay.Driver that reads JSON-Lines event archives from S3 (or any S3-compatible store like MinIO) and feeds the records into the pipeline.

This is the standard "kappa replay" path for Kinesis-backed pipelines whose live retention is shorter than the desired backfill window. Events are typically archived to S3 by Kinesis Data Firehose with date-partitioning (e.g. year=/month=/day=/), or by Kafka Connect's S3 sink for Kafka topics.

Phase 1 supports JSON-Lines (one JSON object per line). Parquet support is a Phase 2 addition gated on real demand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[T any] struct {
	Client *s3.Client
	Bucket string
	// Prefix narrows the object scan (e.g. "events/year=2026/month=05/"). Empty means
	// the entire bucket.
	Prefix string
	// Decode converts a single JSON-Lines line to T.
	Decode Decoder[T]
	// OnDecodeError, if non-nil, is called for every line whose Decode returned an
	// error. Default behavior is to drop silently.
	OnDecodeError func(key string, lineNum int, raw []byte, err error)
}

Config configures an S3 replay driver.

type Decoder

type Decoder[T any] func([]byte) (T, error)

Decoder converts a single JSON line to a typed Record value.

type Driver

type Driver[T any] struct {
	// contains filtered or unexported fields
}

Driver implements replay.Driver for S3-archived JSON-Lines events.

func NewDriver

func NewDriver[T any](cfg Config[T]) (*Driver[T], error)

NewDriver returns a Driver. The client is owned by the caller.

func (*Driver[T]) Close

func (d *Driver[T]) Close() error

Close is a no-op; the underlying client is owned by the caller.

func (*Driver[T]) Name

func (d *Driver[T]) Name() string

Name returns "s3:<bucket>/<prefix>".

func (*Driver[T]) Replay

func (d *Driver[T]) Replay(ctx context.Context, out chan<- source.Record[T]) error

Replay enumerates all objects under (Bucket, Prefix), reads each as JSON-Lines, and emits one source.Record per line. Returns when all objects have been consumed or ctx is canceled. Object enumeration is paged via ListObjectsV2.

type ParquetConfig added in v0.2.0

type ParquetConfig[T any] struct {
	// Client is the S3 client. Required.
	Client *awss3.Client

	// Bucket is the S3 bucket. Required.
	Bucket string

	// Prefix narrows the object scan (e.g. "events/year=2026/month=05/").
	// Empty means the entire bucket.
	Prefix string

	// Decode converts a single Arrow row into T. Required.
	Decode ParquetDecoder[T]

	// KeyFilter, when non-nil, decides whether to include a listed key.
	// Default behavior includes every key ending in ".parquet"; pass a
	// custom KeyFilter to broaden ("*.parquet.snappy") or narrow
	// ("only files newer than X").
	KeyFilter func(key string) bool

	// BatchSize is the number of rows materialized per arrow.RecordBatch
	// pulled out of Parquet. Defaults to 4096.
	BatchSize int64

	// Allocator is the Arrow memory allocator. Defaults to
	// memory.DefaultAllocator.
	Allocator memory.Allocator

	// OnDecodeError, when non-nil, is invoked for rows that fail to
	// decode. Default: drop silently and continue. Wire to a DLQ or
	// logger to surface poison rows.
	OnDecodeError func(key string, rowOrdinal int, err error)
}

ParquetConfig configures a Parquet S3 replay driver.

type ParquetDecoder added in v0.2.0

type ParquetDecoder[T any] func(rec arrow.RecordBatch, row int) (T, error)

ParquetDecoder converts a single Parquet row (column-array + row index) into T. Implementations should pull only the columns they need from the arrow.RecordBatch by name; cross-record allocations are the caller's responsibility because the Record is reused after the call returns.

type ParquetDriver added in v0.2.0

type ParquetDriver[T any] struct {
	// contains filtered or unexported fields
}

ParquetDriver implements replay.Driver for S3-archived Parquet event streams. The standard "kappa replay" shape for pipelines whose upstream archive is Spark-produced or Firehose-with-Parquet-format — 5-20x smaller than gzipped JSON Lines on the same data, predicate- pushdown-friendly, native to every modern columnar engine.

For ad-hoc / hand-built JSON dumps, the line-based Driver in this same package remains the right choice. Use this Parquet driver when the archive was written by a columnar engine.

func NewParquetDriver added in v0.2.0

func NewParquetDriver[T any](cfg ParquetConfig[T]) (*ParquetDriver[T], error)

NewParquetDriver returns a ParquetDriver. The S3 client is owned by the caller.

func (*ParquetDriver[T]) Close added in v0.2.0

func (d *ParquetDriver[T]) Close() error

Close is a no-op; the underlying client is owned by the caller.

func (*ParquetDriver[T]) Name added in v0.2.0

func (d *ParquetDriver[T]) Name() string

Name returns "s3-parquet:<bucket>/<prefix>".

func (*ParquetDriver[T]) Replay added in v0.2.0

func (d *ParquetDriver[T]) Replay(ctx context.Context, out chan<- source.Record[T]) error

Replay enumerates every object under (Bucket, Prefix), opens each one that passes KeyFilter as Parquet, and emits one source.Record per row via the configured Decoder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL