You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7be58c3
Browse filesBrowse the repository at this point in the historyBrowse files
Map DateTime to google.protobuf.Timestamp and document temporal string formats (#1306)
## Why
Mapping `DateTime` to `string` loses the type safety proto offers — a
string can be malformed in ways a
[`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp)
cannot, and proto consumers get language-native timestamp types. For the
remaining `string`-typed temporal scalars, the proto type is much wider
than the ElasticGraph type, so the expected format deserves
documentation at the point of use (per [review
discussion](#1080 (comment))).
## What
- Map `DateTime` to `google.protobuf.Timestamp`, importing
`google/protobuf/timestamp.proto` automatically. A `Timestamp` is a UTC
instant, so a publisher's original UTC offset is not preserved;
`t.protobuf type: "string"` remains available as an override.
- `t.protobuf` gains two options usable by any scalar:
- `import:` maps a scalar to an externally defined proto type, emitting
the needed `import` statement
- `field_comment:` documents the expected format above each generated
field
- The built-in `string`-typed temporal scalars (`Date`, `LocalTime`,
`TimeZone`) use `field_comment:` to document their formats (e.g. `//
Must be formatted as an ISO 8601 date, e.g. "2024-11-25".`). Values are
still validated at ingestion time, exactly as with JSON ingestion.
- Each `protobuf` call replaces the full protobuf configuration, so an
override that omits `import:` or `field_comment:` clears the value a
prior call set.
## Risk Assessment
Low — only affects the unreleased `elasticgraph-proto_ingestion`
extension from #1080.
## References
- Stacked on #1304 (→ #1080)
- Addresses
#1080 (comment)
and
#1080 (comment)
## Update — 2026-07-10
Nested-list wrapper comment propagation was removed after #1080 changed
to reject lists of lists. Format comments continue to apply to supported
scalar and single-list fields.
## Update — 2026-08-18
Addressed review feedback:
- `comment:` is now `field_comment:`, and renders as `//` lines
**above** the field rather than trailing the field line. Proto compilers
attach leading comments to the code they generate for a field; a
trailing comment is usually discarded. This also removed the reason the
comment had to be a single line, so a multi-line `field_comment:` is now
allowed.
- Built-in temporal comments were reworded to read well above the field
(e.g. `Must be formatted as an ISO 8601 date, e.g. "2024-11-25".`).
- The "each `protobuf` call replaces the full configuration" behavior is
now documented and covered in both directions (override that drops the
import, and override that drops the field comment).
- Enum and object types now answer `protobuf_import` with `nil`, so
import rendering no longer greps for scalar types and a non-scalar type
can start requiring an import without a change there.
- Spec reorganization (moving scalar-related examples out of
`schema_spec.rb`) is handled in a follow-up PR at the end of this stack.
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb
+45-21Lines changed: 45 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -14,33 +14,57 @@ module SchemaDefinition
14
14
moduleSchemaElements
15
15
# Extends ScalarType with proto field type conversion.
16
16
moduleScalarTypeExtension
17
-
# Default protobuf types applied to ElasticGraph's built-in scalar types as they are constructed.
18
-
BUILT_IN_SCALAR_PROTO_TYPES_BY_NAME={
19
-
"Boolean"=>"bool",
20
-
"Cursor"=>"string",
21
-
"Date"=>"string",
22
-
"DateTime"=>"string",
23
-
"Float"=>"double",
24
-
"ID"=>"string",
25
-
"Int"=>"int32",
26
-
"JsonSafeLong"=>"int64",
27
-
"LocalTime"=>"string",
28
-
"LongString"=>"int64",
29
-
"String"=>"string",
30
-
"TimeZone"=>"string",
31
-
"Untyped"=>"string"
32
-
}.freeze
17
+
# Default protobuf options applied to ElasticGraph's built-in scalar types as they are constructed.
18
+
BUILT_IN_SCALAR_PROTO_OPTIONS_BY_NAME={
19
+
"Boolean"=>{type: "bool"},
20
+
"Cursor"=>{type: "string"},
21
+
"Date"=>{type: "string",field_comment: %(Must be formatted as an ISO 8601 date, e.g. "2024-11-25".)},
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/sig/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rbs
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/sig/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rbs
Copy file name to clipboardExpand all lines: elasticgraph-proto_ingestion/sig/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rbs
0 commit comments