Skip to content

feat: add flag to preserve map key order across transcoded formats - #55

Draft
edsilegxrepo wants to merge 1 commit into
JFryy:mainfrom
edsilegxrepo:pr2/feature-preserve-key-order
Draft

feat: add flag to preserve map key order across transcoded formats#55
edsilegxrepo wants to merge 1 commit into
JFryy:mainfrom
edsilegxrepo:pr2/feature-preserve-key-order

Conversation

@edsilegxrepo

Copy link
Copy Markdown

Description

This PR introduces the -k / --preserve-key-order CLI flag, enabling the preservation of map key sequences when transcoding between structured configuration formats.

Key Changes

  1. Order Registry: Implements a pointer-based registry utilizing a RWMutex and pointer address tracking in codec/util/order.go to log key order during unmarshaling.
  2. Codec Integrations: Integrates order tracking into JSON, YAML, XML, CSV, TSV, and JSONL unmarshalers and marshalers.
  3. Interactive REPL Leak Prevention: Invokes ClearKeyOrder() before starting each query execution to prevent memory accumulation during long-running REPL sessions.
  4. E2E Tests: Adds TestE2E_KeyPreservation_Formats inside cli/integration_test.go to assert order consistency from flat files (like CSV) through to nested structures.

Justification & Upstream Value

  • Justification: Standard Go map deserialization is non-deterministic and marshals keys alphabetically. For configurations (YAML, TOML, JSON), this destroys the developer's logical layout, making diffs noisy and configurations harder to read. Key order preservation maintains layout stability.

Verification and Testing

  • Ran unit and integration tests:
    go test -v ./cli -run TestE2E_KeyPreservation_Formats
    Asserts JSON, JSONL, CSV, TSV, YAML, and XML all output columns and keys in their original ingestion sequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant