Skip to content

API Reference parrot_formdesigner.services.sinks.mapper

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.sinks.mapper

View source

Submission mapper — tabular flattening and document nesting.

Turns a :class:~parrot_formdesigner.services.submissions.FormSubmission into what a sink actually stores. Two modes, selected by the sink's data family (spec section 8, resolved):

  • Tabular (postgres_table, csv_file, gsheet, and the bigquery asyncdb driver): one flat row per submission. A scalar field becomes a column named after its field_id; a GROUP field flattens recursively as parent__child; an ARRAY field becomes exactly ONE column holding a JSON-serialized value; declared :class:~parrot_formdesigner.core.schema.FormMetadataField keys become their own columns; the reserved submission columns are always present.
  • Document (Mongo / Arango asyncdb drivers): one document per submission, with data stored nested and unflattened, plus the reserved fields — flattening a document store loses structure for no benefit.

Pure functions only: no I/O, no sink, no storage code imported here.

Alias FieldType

Re-exported from parrot_formdesigner.core.types.FieldType.

Alias FormField

Re-exported from parrot_formdesigner.core.schema.FormField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSubmission

Re-exported from parrot_formdesigner.services.submissions.FormSubmission.

Alias FormSubsection

Re-exported from parrot_formdesigner.core.schema.FormSubsection.

Attribute RESERVED_COLUMNS

Type: frozenset[str]

Alias SectionItem

Re-exported from parrot_formdesigner.core.schema.SectionItem.

Function column_names_for

Return the ordered, deterministic tabular column set for form.

Used by ensure_target() to compute the additive column set: the reserved columns first (in a fixed order), then one column per form field (in schema order), then one column per declared metadata key.

column_names_for(form: FormSchema) -> list[str]

Parameter Type Default Description
form FormSchema The form whose tabular column set to compute.

Returns: list[str] — The ordered list of column names.

Function field_types_for

Return a {flattened column name: FieldType} map for form.

Built on the SAME canonical traversal :func:column_names_for uses (:func:_iter_form_fields), so a column's reported type can never drift from what :func:flatten_submission actually emits for it — sinks that need per-column type inference (e.g. PostgresTableSink DDL, AsyncDBSink's BigQuery schema) should use this instead of re-implementing the field-tree walk.

field_types_for(form: FormSchema) -> dict[str, FieldType]

Parameter Type Default Description
form FormSchema The form whose tabular columns to type.

Returns: dict[str, FieldType] — A dict mapping each flattened (non-reserved, non-metadata) column name to its originating field's FieldType.

Function flatten_submission

Flatten submission into a single tabular row.

flatten_submission(form: FormSchema, submission: FormSubmission) -> dict[str, Any]

Parameter Type Default Description
form FormSchema The form that produced submission (used to walk the field tree and any declared metadata).
submission FormSubmission The submission to flatten.

Returns: dict[str, Any] — A flat dict: reserved columns, then one entry per form field (GROUP -> parent__child, ARRAY -> one JSON-serialized column), then one entry per declared metadata key.

Raises:

  • ValueError — If a flattened column name is not a valid identifier (e.g. exceeds the 63-character Postgres cap).

Function nest_submission

Build a document-mode record: reserved fields + nested data.

nest_submission(form: FormSchema, submission: FormSubmission) -> dict[str, Any]

Parameter Type Default Description
form FormSchema The form that produced submission (unused for nesting, kept for a symmetric signature with :func:flatten_submission).
submission FormSubmission The submission to nest.

Returns: dict[str, Any] — A dict with every reserved column plus a "data" key holding submission.data exactly as submitted (a shallow copy, so the caller's submission.data is never mutated). FEAT-458: extra_data is one of the reserved columns — included as a nested object (or None), never stringified.

Alias validate_identifier

Re-exported from parrot_formdesigner.services._identifiers.validate_identifier.

Function voice_capable_columns

Return the flattened columns that may carry a VoiceEvidenceEnvelope (FEAT-649).

Rule (shared with migration 009, TASK-4230): a column is voice-capable when its field has answer_envelope == "voice" (FEAT-488), or when the form enables voice (form.voice set and form.voice.enabled) and the field type is not in _NON_VOICE_TYPES (HIDDEN, PASSWORD, ARRAY, GROUP).

voice_capable_columns(form: FormSchema) -> frozenset[str]

Parameter Type Default Description
form FormSchema The form whose tabular columns to classify.

Returns: frozenset[str] — The set of column names whose values are JSON-serialised and stored as JSONB.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally