mattiabasone commented on code in PR #3634:
URL: https://github.com/apache/avro/pull/3634#discussion_r2732111395


##########
lang/php/lib/Datum/AvroIODatumReader.php:
##########
@@ -43,124 +43,126 @@
 class AvroIODatumReader
 {
     public function __construct(
-        private ?AvroSchema $writers_schema = null,
-        private ?AvroSchema $readers_schema = null
+        private ?AvroSchema $writersSchema = null,
+        private ?AvroSchema $readersSchema = null
     ) {
     }
 
-    public function setWritersSchema(AvroSchema $readers_schema): void
+    public function setWritersSchema(AvroSchema $schema): void
     {
-        $this->writers_schema = $readers_schema;
+        $this->writersSchema = $schema;
     }
 
     public function read(AvroIOBinaryDecoder $decoder): mixed
     {
-        if (is_null($this->readers_schema)) {
-            $this->readers_schema = $this->writers_schema;
+        if (is_null($this->readersSchema)) {
+            $this->readersSchema = $this->writersSchema;
         }
 
         return $this->readData(
-            $this->writers_schema,
-            $this->readers_schema,
+            $this->writersSchema,
+            $this->readersSchema,
             $decoder
         );
     }
 
     public function readData(
-        AvroSchema $writers_schema,
-        AvroSchema $readers_schema,
+        AvroSchema $writersSchema,
+        AvroSchema $readersSchema,
         AvroIOBinaryDecoder $decoder
     ): mixed {
         // Schema resolution: reader's schema is a union, writer's schema is 
not
         if (
-            $readers_schema instanceof AvroUnionSchema
-            && AvroSchema::UNION_SCHEMA === $readers_schema->type()
-            && AvroSchema::UNION_SCHEMA !== $writers_schema->type()
+            $readersSchema instanceof AvroUnionSchema
+            && AvroSchema::UNION_SCHEMA === $readersSchema->type()
+            && AvroSchema::UNION_SCHEMA !== $writersSchema->type()
         ) {
-            foreach ($readers_schema->schemas() as $schema) {
-                if (self::schemasMatch($writers_schema, $schema)) {
-                    return $this->readData($writers_schema, $schema, $decoder);
+            foreach ($readersSchema->schemas() as $schema) {
+                if (self::schemasMatch($writersSchema, $schema)) {
+                    return $this->readData($writersSchema, $schema, $decoder);
                 }
             }
 
-            throw new AvroIOSchemaMatchException($writers_schema, 
$readers_schema);
+            throw new AvroIOSchemaMatchException($writersSchema, 
$readersSchema);
         }
 
-        return match ($writers_schema->type()) {
+        return match ($writersSchema->type()) {
             AvroSchema::NULL_TYPE => $decoder->readNull(),
             AvroSchema::BOOLEAN_TYPE => $decoder->readBoolean(),
             AvroSchema::INT_TYPE => $decoder->readInt(),
             AvroSchema::LONG_TYPE => $decoder->readLong(),
             AvroSchema::FLOAT_TYPE => $decoder->readFloat(),
             AvroSchema::DOUBLE_TYPE => $decoder->readDouble(),
             AvroSchema::STRING_TYPE => $decoder->readString(),
-            AvroSchema::BYTES_TYPE => $this->readBytes($writers_schema, 
$readers_schema, $decoder->readBytes()),
-            AvroSchema::ARRAY_SCHEMA => $this->readArray($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::MAP_SCHEMA => $this->readMap($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::UNION_SCHEMA => $this->readUnion($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::ENUM_SCHEMA => $this->readEnum($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::FIXED_SCHEMA => $this->readFixed($writers_schema, 
$readers_schema, $decoder),
+            AvroSchema::BYTES_TYPE => $this->readBytes($writersSchema, 
$readersSchema, $decoder->readBytes()),
+            AvroSchema::ARRAY_SCHEMA => $this->readArray($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::MAP_SCHEMA => $this->readMap($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::UNION_SCHEMA => $this->readUnion($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::ENUM_SCHEMA => $this->readEnum($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::FIXED_SCHEMA => $this->readFixed($writersSchema, 
$readersSchema, $decoder),
             AvroSchema::RECORD_SCHEMA,
             AvroSchema::ERROR_SCHEMA,
-            AvroSchema::REQUEST_SCHEMA => $this->readRecord($writers_schema, 
$readers_schema, $decoder),
+            AvroSchema::REQUEST_SCHEMA => $this->readRecord($writersSchema, 
$readersSchema, $decoder),
             default => throw new AvroException(sprintf(
                 "Cannot read unknown schema type: %s",
-                $writers_schema->type()
+                $writersSchema->type()
             )),
         };
     }
 
     /**
      * @throws AvroSchemaParseException
-     * @return bool true if the schemas are consistent with
-     *                  each other and false otherwise.
+     * @return bool true if the schemas are consistent with each other and 
false otherwise.
      */
     public static function schemasMatch(
-        AvroSchema $writers_schema,
-        AvroSchema $readers_schema
+        AvroSchema $writersSchema,
+        AvroSchema $readersSchema
     ): bool {
-        $writers_schema_type = $writers_schema->type;
-        $readers_schema_type = $readers_schema->type;
+        $writersSchemaType = $writersSchema->type;
+        $readersSchemaType = $readersSchema->type;
 
-        if (AvroSchema::UNION_SCHEMA === $writers_schema_type || 
AvroSchema::UNION_SCHEMA === $readers_schema_type) {
+        if (AvroSchema::UNION_SCHEMA === $writersSchemaType || 
AvroSchema::UNION_SCHEMA === $readersSchemaType) {
             return true;
         }
 
-        if (AvroSchema::isPrimitiveType($writers_schema_type)) {
-            return true;
+        if (
+            AvroSchema::isPrimitiveType($writersSchemaType)
+            && AvroSchema::isPrimitiveType($readersSchemaType)
+        ) {
+            return $writersSchemaType === $readersSchemaType;

Review Comment:
   I've update the check in 
https://github.com/apache/avro/pull/3634/commits/53f58943b52453457374540bad977af3dcc34292,
 wdyt?



##########
lang/php/lib/Datum/AvroIODatumReader.php:
##########
@@ -43,124 +43,126 @@
 class AvroIODatumReader
 {
     public function __construct(
-        private ?AvroSchema $writers_schema = null,
-        private ?AvroSchema $readers_schema = null
+        private ?AvroSchema $writersSchema = null,
+        private ?AvroSchema $readersSchema = null
     ) {
     }
 
-    public function setWritersSchema(AvroSchema $readers_schema): void
+    public function setWritersSchema(AvroSchema $schema): void
     {
-        $this->writers_schema = $readers_schema;
+        $this->writersSchema = $schema;
     }
 
     public function read(AvroIOBinaryDecoder $decoder): mixed
     {
-        if (is_null($this->readers_schema)) {
-            $this->readers_schema = $this->writers_schema;
+        if (is_null($this->readersSchema)) {
+            $this->readersSchema = $this->writersSchema;
         }
 
         return $this->readData(
-            $this->writers_schema,
-            $this->readers_schema,
+            $this->writersSchema,
+            $this->readersSchema,
             $decoder
         );
     }
 
     public function readData(
-        AvroSchema $writers_schema,
-        AvroSchema $readers_schema,
+        AvroSchema $writersSchema,
+        AvroSchema $readersSchema,
         AvroIOBinaryDecoder $decoder
     ): mixed {
         // Schema resolution: reader's schema is a union, writer's schema is 
not
         if (
-            $readers_schema instanceof AvroUnionSchema
-            && AvroSchema::UNION_SCHEMA === $readers_schema->type()
-            && AvroSchema::UNION_SCHEMA !== $writers_schema->type()
+            $readersSchema instanceof AvroUnionSchema
+            && AvroSchema::UNION_SCHEMA === $readersSchema->type()
+            && AvroSchema::UNION_SCHEMA !== $writersSchema->type()
         ) {
-            foreach ($readers_schema->schemas() as $schema) {
-                if (self::schemasMatch($writers_schema, $schema)) {
-                    return $this->readData($writers_schema, $schema, $decoder);
+            foreach ($readersSchema->schemas() as $schema) {
+                if (self::schemasMatch($writersSchema, $schema)) {
+                    return $this->readData($writersSchema, $schema, $decoder);
                 }
             }
 
-            throw new AvroIOSchemaMatchException($writers_schema, 
$readers_schema);
+            throw new AvroIOSchemaMatchException($writersSchema, 
$readersSchema);
         }
 
-        return match ($writers_schema->type()) {
+        return match ($writersSchema->type()) {
             AvroSchema::NULL_TYPE => $decoder->readNull(),
             AvroSchema::BOOLEAN_TYPE => $decoder->readBoolean(),
             AvroSchema::INT_TYPE => $decoder->readInt(),
             AvroSchema::LONG_TYPE => $decoder->readLong(),
             AvroSchema::FLOAT_TYPE => $decoder->readFloat(),
             AvroSchema::DOUBLE_TYPE => $decoder->readDouble(),
             AvroSchema::STRING_TYPE => $decoder->readString(),
-            AvroSchema::BYTES_TYPE => $this->readBytes($writers_schema, 
$readers_schema, $decoder->readBytes()),
-            AvroSchema::ARRAY_SCHEMA => $this->readArray($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::MAP_SCHEMA => $this->readMap($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::UNION_SCHEMA => $this->readUnion($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::ENUM_SCHEMA => $this->readEnum($writers_schema, 
$readers_schema, $decoder),
-            AvroSchema::FIXED_SCHEMA => $this->readFixed($writers_schema, 
$readers_schema, $decoder),
+            AvroSchema::BYTES_TYPE => $this->readBytes($writersSchema, 
$readersSchema, $decoder->readBytes()),
+            AvroSchema::ARRAY_SCHEMA => $this->readArray($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::MAP_SCHEMA => $this->readMap($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::UNION_SCHEMA => $this->readUnion($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::ENUM_SCHEMA => $this->readEnum($writersSchema, 
$readersSchema, $decoder),
+            AvroSchema::FIXED_SCHEMA => $this->readFixed($writersSchema, 
$readersSchema, $decoder),
             AvroSchema::RECORD_SCHEMA,
             AvroSchema::ERROR_SCHEMA,
-            AvroSchema::REQUEST_SCHEMA => $this->readRecord($writers_schema, 
$readers_schema, $decoder),
+            AvroSchema::REQUEST_SCHEMA => $this->readRecord($writersSchema, 
$readersSchema, $decoder),
             default => throw new AvroException(sprintf(
                 "Cannot read unknown schema type: %s",
-                $writers_schema->type()
+                $writersSchema->type()
             )),
         };
     }
 
     /**
      * @throws AvroSchemaParseException
-     * @return bool true if the schemas are consistent with
-     *                  each other and false otherwise.
+     * @return bool true if the schemas are consistent with each other and 
false otherwise.
      */
     public static function schemasMatch(
-        AvroSchema $writers_schema,
-        AvroSchema $readers_schema
+        AvroSchema $writersSchema,
+        AvroSchema $readersSchema
     ): bool {
-        $writers_schema_type = $writers_schema->type;
-        $readers_schema_type = $readers_schema->type;
+        $writersSchemaType = $writersSchema->type;
+        $readersSchemaType = $readersSchema->type;
 
-        if (AvroSchema::UNION_SCHEMA === $writers_schema_type || 
AvroSchema::UNION_SCHEMA === $readers_schema_type) {
+        if (AvroSchema::UNION_SCHEMA === $writersSchemaType || 
AvroSchema::UNION_SCHEMA === $readersSchemaType) {
             return true;
         }
 
-        if (AvroSchema::isPrimitiveType($writers_schema_type)) {
-            return true;
+        if (
+            AvroSchema::isPrimitiveType($writersSchemaType)
+            && AvroSchema::isPrimitiveType($readersSchemaType)
+        ) {
+            return $writersSchemaType === $readersSchemaType;

Review Comment:
   I've updated the check in 
https://github.com/apache/avro/pull/3634/commits/53f58943b52453457374540bad977af3dcc34292,
 wdyt?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to