-
Notifications
You must be signed in to change notification settings - Fork 0
3624: AVRO-4226: Missing doc attributes for record fields #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,7 @@ public static function parseFields( | |
| $type = $field[AvroSchema::TYPE_ATTR] ?? null; | ||
| $order = $field[AvroField::ORDER_ATTR] ?? null; | ||
| $aliases = $field[AvroSchema::ALIASES_ATTR] ?? null; | ||
| $doc = $field[AvroSchema::DOC_ATTR] ?? null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since 🤖 Was this useful? React with 👍 or 👎 |
||
|
|
||
| $default = null; | ||
| $has_default = false; | ||
|
|
@@ -110,7 +111,8 @@ public static function parseFields( | |
| hasDefault: $has_default, | ||
| default: $default, | ||
| order: $order, | ||
| aliases: $aliases | ||
| aliases: $aliases, | ||
| doc: $doc | ||
| ); | ||
| $field_names[] = $name; | ||
| if ($new_field->hasAliases() && array_intersect($alias_names, $new_field->getAliases())) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,15 +28,15 @@ | |
|
|
||
| class SchemaExample | ||
| { | ||
| public $name; | ||
| public $normalized_schema_string; | ||
| public string $name; | ||
| public string $normalized_schema_string; | ||
|
|
||
| public function __construct( | ||
| public $schema_string, | ||
| public $is_valid, | ||
| $normalized_schema_string = null, | ||
| $name = null, | ||
| public $comment = null | ||
| public string $schema_string, | ||
| public bool $is_valid, | ||
| ?string $normalized_schema_string = null, | ||
| ?string $name = null, | ||
| public ?string $comment = null | ||
| ) { | ||
| $this->name = $name ?: $this->schema_string; | ||
| $this->normalized_schema_string = $normalized_schema_string ?: json_encode(json_decode((string) $this->schema_string, true)); | ||
|
|
@@ -45,8 +45,8 @@ public function __construct( | |
|
|
||
| class SchemaTest extends TestCase | ||
| { | ||
| private static $examples = []; | ||
| private static $valid_examples = []; | ||
| private static array $examples = []; | ||
| private static array $valid_examples = []; | ||
|
|
||
| public function test_json_decode(): void | ||
| { | ||
|
|
@@ -232,6 +232,27 @@ public function test_validate_repeated_aliases(): void | |
| ); | ||
| } | ||
|
|
||
| public function test_doc_attribute_on_primitive_fields(): void | ||
| { | ||
| $schemaJson = <<<JSON | ||
| { | ||
| "type": "record", | ||
| "name": "fruits", | ||
| "fields": [ | ||
| { | ||
| "name": "banana", | ||
| "type": "string", | ||
| "doc": "This is a banana" | ||
| } | ||
| ] | ||
| } | ||
| JSON; | ||
|
|
||
| $schema = AvroSchema::parse($schemaJson); | ||
|
|
||
| self::assertEquals($schemaJson, json_encode($schema->toAvro(), flags: JSON_PRETTY_PRINT)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This compares raw JSON strings, but 🤖 Was this useful? React with 👍 or 👎
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:bug; feedback:The Augment AI reviewer is correct! Instead of comparing the JSONs as strings it would be better to compare the decoded version of the JSON values. This way the JSON will be normalized and any leading space and/or different fields order won't break the test. |
||
| } | ||
|
|
||
| public function test_logical_types_in_record(): void | ||
| { | ||
| $avro = <<<JSON | ||
|
|
@@ -380,7 +401,7 @@ protected static function make_examples(): void | |
| new SchemaExample('{"no_type": "test"}', false), | ||
| new SchemaExample('{"type": "panther"}', false), | ||
| ], | ||
| self::make_primitive_examples() | ||
| self::makePrimitiveExamples() | ||
| ); | ||
|
|
||
| $array_examples = [ | ||
|
|
@@ -783,7 +804,7 @@ protected static function make_examples(): void | |
| } | ||
| } | ||
|
|
||
| protected static function make_primitive_examples() | ||
| protected static function makePrimitiveExamples(): array | ||
| { | ||
| $examples = []; | ||
| foreach ([ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 4360
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1066
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 515
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 3250
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 2760
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 295
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 5043
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 3173
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1228
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1321
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 2879
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 656
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1744
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 2612
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1800
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1433
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 2237
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 974
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 1156
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 481
🏁 Script executed:
Repository: martin-augment/avro
Length of output: 884
Field aliases should be serialized in
toAvro()output.The
aliasesfield is not being serialized, which breaks round-trip serialization for schemas containing field aliases. Although aliases are parsed from the input schema (line 76 in AvroRecordSchema.php), validated, and stored, they're discarded when callingtoAvro(). This is inconsistent with:docandorderattributes being included (lines 134-140)getAliases()methodtoAvro()output (lines 65-66)fieldsByAlias()Add aliases serialization:
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:good-to-have; category:bug; feedback:The CodeRabbit AI reviewer is correct! For consistency with the other fields of this class the old $aliases field should also be serialized in the JSON representation. Prevents releasing an unfinished feature.