Thalweg · API reference ← Main docs

Crate twg_type_map

Crate twg_type_map 

Source
Expand description

Shared type-mapping vocabulary across formats and storage targets.

Decode-side (source format -> Arrow/PgType):

  • pg_type::PgType: a PostgreSQL-facing type bridging Arrow, decoded JSON values, and SQL DDL text - the common ground across the Protobuf/Avro/JSON decode paths.
  • identifiers: SQL identifier validation/quoting.
  • json_arrow: basic (schemaless) JSON -> Arrow type inference.
  • json_schema: JSON Schema document ($schema/type/format) -> PgType, distinct from json_arrow (which infers from an already-decoded value, not a schema document).
  • avro (feature avro): Avro schema -> Arrow type mapping.

Protobuf’s Arrow-type derivation lives in the separate twg-proto-schema crate (it needs descriptor-tree traversal that doesn’t belong here) - this crate doesn’t re-export it to avoid a dependency both ways; use both crates together if you need Protobuf and Postgres/Avro/JSON type mapping in the same place.

Storage-target side (Arrow/PgType -> a table/wire format’s own type system):

  • delta::DeltaType: Delta Lake’s schema type system - built from the public Delta protocol spec.
  • iceberg::IcebergType: Apache Iceberg’s schema type system (field IDs are NOT assigned here - that’s a schema-evolution concern for the caller, not a type-mapping one; see the module doc comment) - also built from the public Iceberg spec.
  • zerobus_sink::ProtoFieldType: the sink-direction type system for building OUTGOING protobuf descriptors - deliberately a much smaller, coarser 7-variant type set than PgType, with its own widening rules and Delta/Unity Catalog type-name mappings. Does NOT carry any fixed metadata-column table: that is a specific application’s column contract, not generic type-mapping vocabulary, and belongs in the calling application instead.

delta/iceberg bridge through Arrow (reusing PgType’s existing Arrow bridge as the hub) rather than hand-rolling separate PgType-to-X logic; zerobus_sink::ProtoFieldType is its own independent type system, not re-derived through the hub, because the sink’s coarser vocabulary does not map cleanly onto it.

Re-exports§

pub use pg_type::PgType;

Modules§

avro
Avro schema -> Arrow schema mapping. Feature-gated behind avro since it pulls in apache-avro.
delta
Delta Lake’s schema type system, per the public Delta Transaction Log Protocol spec (PROTOCOL.md#primitive-types / #struct-field). This is a documented, versioned open format, so this mapping is built directly from the spec.
iceberg
Apache Iceberg’s schema type system, per the public format spec (https://iceberg.apache.org/spec/#schemas-and-data-types) - a documented, versioned open format, built directly from the spec.
identifiers
SQL identifier validation and quoting.
json_arrow
Basic JSON value -> Arrow type inference. Deliberately simpler than crate::pg_type::PgType::from_json_value - this is for a schemaless JSON-to-Arrow decode path (no string sniffing for UUID/timestamp/date; arrays, objects, and null all collapse to Utf8), not the richer SQL-facing inference PgType does. The two serve different purposes and are not duplicates to reconcile.
json_schema
Maps a JSON Schema document (the declarative $schema/type/ format format, e.g. from a schema registry) to crate::pg_type::PgType. Distinct from crate::pg_type::PgType::from_json_value, which infers from an already-decoded value instead of a schema document.
pg_type
PgType: a PostgreSQL-facing type that bridges Arrow, JSON values, and SQL DDL text - the shared type-mapping vocabulary used across Protobuf/Avro/JSON decode paths. from_arrow_type/to_arrow_type are inverses of each other (mostly - Arrow has strictly more scalar variants than Postgres, so from_arrow_type is lossy in the narrowing direction by design), and from_json_value gives type inference straight from a decoded serde_json::Value (used when a source format’s own schema doesn’t give you a type directly, e.g. schemaless JSON payloads).
zerobus_sink
ProtoFieldType: the SINK-direction type system - building outgoing protobuf descriptors (e.g. for a Zerobus-style ingest wire protocol), as opposed to twg-proto-schema’s decode-direction mapping (an INCOMING protobuf descriptor -> Arrow).