Repository navigation
feat(view): add metadata JSON serialization - #1196
kamcheungting-db wants to merge 4 commits into
Conversation
220f6d6 to
1f41d92
Compare
1f41d92 to
49d5e3f
Compare
020941f to
0a8bcea
Compare
- Share one IsSqlRepresentationType policy between metadata validation and JSON serde. "sql" in any case is reserved everywhere, while "ſql" (U+017F LATIN SMALL LETTER LONG S) does not case-fold to "sql" and is now an opaque type that parses, validates, and round trips unchanged. - Add ValidateViewMetadataForWrite, used by ViewMetadata::Validate and by serialization: the read checks plus SchemaField::Validate on every schema field, including nested struct fields. A NaN default or a default with the wrong type now fails fast instead of being serialized as null or producing metadata that cannot be reloaded. Parsing stays lenient so existing metadata still round trips.
| bool number_integer(number_integer_t) override { return true; } | ||
| bool number_unsigned(number_unsigned_t) override { return true; } | ||
| bool number_float(number_float_t, const string_t& token) override { | ||
| return token.find_first_of(".eE") != std::string::npos; |
There was a problem hiding this comment.
A valid opaque payload number like 9007199254740993.0 passes this check after the DOM has rounded it. Can we preserve its value, or reject precision loss before a property-only update writes back a different number?
| if (IsSqlRepresentationType(unknown.type)) { | ||
| return ValidationFailed("Unknown view representation must have a non-SQL type"); | ||
| } | ||
| if (unknown.extra_fields.contains("type")) { |
There was a problem hiding this comment.
A nested non-finite number in the public extra_fields passes here and is written as null. Please validate that all opaque values can be serialized without changing them.
| /// The representation type identifier from the metadata, such as "cypher". | ||
| std::string type; | ||
| /// Representation-specific JSON fields, excluding the type discriminator. | ||
| nlohmann::json::object_t extra_fields; |
There was a problem hiding this comment.
The bundled JSON comparator treats UINT64_MAX and -1 as equal through its signed cast. Please compare opaque numeric values without narrowing and add a regression for these two payloads. Comparator
There was a problem hiding this comment.
btw, we shouldn't export nlohmann::json::object_t in a public header.
| GetJsonInteger<int32_t>(json, kCurrentVersionId)); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto schemas, RequiredArray(json, kSchemas)); | ||
| for (const auto& schema : schemas) { | ||
| ICEBERG_RETURN_UNEXPECTED(GetJsonInteger<int32_t>(schema, kSchemaId)); |
There was a problem hiding this comment.
With an omitted schema ID and a version referencing 0, Java and our shared parser both default to schema 0. Please remove this precheck and keep the duplicate check on the resolved IDs. Java parser
| IdToFieldVisitor id_visitor(fields); | ||
| ICEBERG_RETURN_UNEXPECTED(VisitTypeInline(schema, &id_visitor)); | ||
| for (const auto& [id, field_ref] : fields) { | ||
| if (auto status = field_ref.get().Validate(); !status.has_value()) { |
There was a problem hiding this comment.
A time default of 86,400,000,000 microseconds passes this check and is written as "24:00". Our reader rejects hour 24. Please validate the time range on write and test the last valid microsecond of the day.
| for (const auto* reserved : {"sql", "SQL", "SqL"}) { | ||
| SCOPED_TRACE(reserved); | ||
| ICEBERG_UNWRAP_OR_FAIL(auto metadata, ViewMetadataFromJson(ValidMetadataJson())); | ||
| metadata->versions[0]->representations.push_back( |
There was a problem hiding this comment.
The linter flags this call and the one at line 467. Please use emplace_back in both loops.
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| #include <nlohmann/json.hpp> |
There was a problem hiding this comment.
As a convention, we shouldn't include nlohmann header here.
Adds Iceberg view format v1 JSON parsing and serialization, building on #1069.
ViewProperties.ViewMetadata::Validate()additionally checks UUID, location, references, and SQL dialects.sqlare reserved; other tags, includingſql, remain opaque.For example, metadata with a missing historical reference can still round trip after a property edit. An integer field with a string default (
"oops") now fails validation and serialization, preventing JSON that cannot reload. NaN defaults are rejected before they can becomenull.Validation: 85 view tests, 175 JSON serde tests, 583 schema tests, and the C++20 header check pass under Clang 18 with ASan/UBSan (leak detection and alloc/dealloc mismatch checks disabled). Six new regression tests fail before the fixes and pass afterward. Pre-commit passes for the changed files.