Skip to content

Follow-ups to RecordPreparer: faster Timestamps, shared generated names, imported message zero values - #1472

Merged
myronmarston merged 2 commits into
mainfrom
myron/proto-record-preparer-followups
Nov 30, 2026
Merged

myronmarston merged 2 commits into
mainfrom
myron/proto-record-preparer-followups

Conversation

@myronmarston

@myronmarston myronmarston commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups to RecordPreparer from #1442, proposed as a stacked PR.

 build_scalar_preparer
+  Timestamp field whose scalar uses the DateTime preparer
+    Time.at(seconds, nanos, :nsec).iso8601(DATE_TIME_PRECISION)
   other message scalar
-    preparer(JSON.parse(encode_json(value)))
+    preparer(JSON.parse(encode_json(value, emit_defaults: true)))

 build_enum
-  {symbol => name, number => name}
+  {symbol => name}

 schema generator and RecordPreparer
-  "value", "values", zero value name minus "_UNSPECIFIED"
+  ProtoConversions::ABSTRACT_TYPE_ONEOF_NAME, LIST_WRAPPER_VALUES_FIELD_NAME, enum_value_prefix(name)
  • Timestamps: most of the cost per Timestamp was IndexingPreparers::DateTime re-parsing an ISO 8601 string. The direct format gives the same output: it truncates to milliseconds and handles negative seconds.
  • Imported message scalars: the canonical protobuf JSON form omits zero-valued fields. For example, a geo_point scalar with lat: 0 was indexed as {"lon" => 5.5}.
  • Enum numbers: decoded messages return known enum values as symbols on MRI and on JRuby. Only a JRuby RepeatedField#push(0) keeps a number, and only the spec did that.
  • Shared names: the generator and RecordPreparer now use the same constants for the names that the generator emits. ProtoPublisher keeps its own derivation, so it stays an independent check.

Evidence

  • Before: the new imported-message spec failed: expected {"location" => {"lat" => 0.0, "lon" => 5.5}}, got {"location" => {"lon" => 5.5}}.
    After: it passes.
  • No existing spec failed under these broken implementations. Each now fails a new spec:
    • The Timestamp shortcut ignores the scalar's preparer.
    • The shortcut rounds instead of truncating, or computes with a Float.
    • Treat every message outside google.protobuf as an object type.
    • List recursion drops the nested mapping below the first list level.
    • Presence methods use snake_case names.
    • A field named value marks a type as abstract.
  • Benchmark: for one Timestamp value on MRI 4.0, preparation takes 2.0 µs on the JSON path and 0.4 µs on the direct format.

Merge Danger

Door: two-way

Blast Radius: elasticgraph-proto_ingestion. The only effect outside it is a new optional proto_paths: argument on SpecSupport::ProtoPublisher.

🤖 Generated with Claude Code

@myronmarston

Copy link
Copy Markdown
Collaborator Author

This change is part of the following stack:

Change managed by git-spice.

@myronmarston
myronmarston force-pushed the myron/proto-record-preparer-followups branch 2 times, most recently from 4d2b0ef to cefc153 Compare November 29, 2026 02:12
@myronmarston
myronmarston marked this pull request as ready for review November 29, 2026 02:18
@jwils
jwils force-pushed the joshuaw/proto-record-conversion branch from 71db773 to e58a6b4 Compare November 29, 2026 14:53
Base automatically changed from joshuaw/proto-record-conversion to main November 29, 2026 15:23
Follow-ups to the protobuf `RecordPreparer`. Each change below gives its own reason.

- Format `google.protobuf.Timestamp` values with `Time.at(seconds, nanos, :nsec)` when the scalar uses the `DateTime` indexing preparer. Re-parsing an ISO 8601 string in `IndexingPreparers::DateTime` costs about 1.5 µs of the 2.0 µs spent per `Timestamp` value.
- Encode other message scalars with `emit_defaults: true`. The canonical protobuf JSON form omits zero-valued fields, so a `geo_point` scalar with `lat: 0` was prepared as `{"lon" => 5.5}`.
- Key the enum lookup by symbol only. Decoded messages return known enum values as symbols on both MRI and JRuby. Only a JRuby `RepeatedField#push(0)` keeps a number, and only the spec did that.
- Add `ProtoConversions::ABSTRACT_TYPE_ONEOF_NAME`, `LIST_WRAPPER_VALUES_FIELD_NAME` and `enum_value_prefix`, and use them in the schema generator and in `RecordPreparer`. Before this, a change to the generator could break preparation with no shared code to show the link.
- Let `ProtoPublisher` search extra proto paths for the files that `schema.proto` imports.
- Add specs for these cases:
  - Truncation of sub-millisecond digits, negative `seconds` before 1970, and a `Timestamp` scalar with another indexing preparer.
  - An imported message scalar with a zero-valued field.
  - Nested lists of objects and abstract types, a list of `DateTime` values, camelCase fields, and a field named `value`. No spec failed before when list recursion dropped the nested mapping below the first level, when presence methods used snake_case names, or when a field named `value` marked a type as abstract.

Generated with Claude Code
@myronmarston
myronmarston force-pushed the myron/proto-record-preparer-followups branch from cefc153 to 194fd1e Compare November 29, 2026 20:54
Addresses review feedback from PR #1472.

- Read the list wrapper's field with `LIST_WRAPPER_VALUES_FIELD_NAME` instead of the hardcoded `values` accessor.

Generated with Claude Code
@myronmarston
myronmarston enabled auto-merge (squash) November 30, 2026 18:08
@myronmarston
myronmarston merged commit e5234fe into main Nov 30, 2026
24 checks passed
@myronmarston
myronmarston deleted the myron/proto-record-preparer-followups branch November 30, 2026 18:27
jwils added a commit that referenced this pull request Nov 30, 2026
- Use `ProtoConversions::ABSTRACT_TYPE_ONEOF_NAME` and `ProtoConversions::LIST_WRAPPER_VALUES_FIELD_NAME` in `Descriptors`, `RecordValidator`, and `IngestionAdapter` instead of hardcoded `"value"` / `"values"` names
- Drop the unused `path` parameter from `RecordValidator#error_for` and extract `DATE_REGEX`
- Consolidate `IngestionAdapter` `@update_targets` and `@ingestible_types` into `@update_targets_by_type` and make the non-ingestible error message accurate for concrete and abstract types
- Replace `schema.respond_to?(:json_schema_version)` in `schema_evolution_spec.rb` with a format check and generalize the shared example descriptions
- Close mutation-testing gaps in `ingestion_adapter_spec.rb` (`Date` trailing characters, renamed scalar error name, `camelCase` field presence, concrete field named `value`), use `:STATE_UNSPECIFIED`, and qualify top-level constants with `::`

Co-authored-by: Neo <f833053fa3445a7878359a1bd17c4f6b4ed1ceb3e7414f306f4929b1f9032d02@buzz>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
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.

2 participants