Skip to content

Commit 23d53a3

Browse files
authored
Add fix from Avro main stream for broken schema evolution (#8)
1 parent 93ffb3b commit 23d53a3

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

lib/avro/datum.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ public function read_record($writers_schema, $readers_schema, $decoder)
725725
$readers_fields[$writers_field->name()]->type(),
726726
$decoder);
727727
else
728-
$this->skip_data($type, $decoder);
728+
self::skip_data($type, $decoder);
729729
}
730730
// Fill in default values
731731
if (count($readers_fields) > count($record))
@@ -816,7 +816,7 @@ public function read_default_value($field_schema, $default_value)
816816
* @return
817817
* @throws AvroException
818818
*/
819-
private function skip_data($writers_schema, $decoder)
819+
public static function skip_data($writers_schema, $decoder)
820820
{
821821
switch ($writers_schema->type())
822822
{
@@ -1030,6 +1030,58 @@ public function skip_bytes() { return $this->skip($this->read_long()); }
10301030

10311031
public function skip_string() { return $this->skip_bytes(); }
10321032

1033+
public function skip_fixed($writers_schema, AvroIOBinaryDecoder $decoder)
1034+
{
1035+
$decoder->skip($writers_schema->size());
1036+
}
1037+
1038+
public function skip_enum($writers_schema, AvroIOBinaryDecoder $decoder)
1039+
{
1040+
$decoder->skip_int();
1041+
}
1042+
1043+
public function skip_union($writers_schema, AvroIOBinaryDecoder $decoder)
1044+
{
1045+
$index = $decoder->read_long();
1046+
AvroIODatumReader::skip_data($writers_schema->schema_by_index($index), $decoder);
1047+
}
1048+
1049+
public function skip_record($writers_schema, AvroIOBinaryDecoder $decoder)
1050+
{
1051+
foreach ($writers_schema->fields() as $f) {
1052+
AvroIODatumReader::skip_data($f->type(), $decoder);
1053+
}
1054+
}
1055+
1056+
public function skip_array($writers_schema, AvroIOBinaryDecoder $decoder)
1057+
{
1058+
$block_count = $decoder->read_long();
1059+
while (0 !== $block_count) {
1060+
if ($block_count < 0) {
1061+
$decoder->skip($this->read_long());
1062+
}
1063+
for ($i = 0; $i < $block_count; $i++) {
1064+
AvroIODatumReader::skip_data($writers_schema->items(), $decoder);
1065+
}
1066+
$block_count = $decoder->read_long();
1067+
}
1068+
}
1069+
1070+
public function skip_map($writers_schema, AvroIOBinaryDecoder $decoder)
1071+
{
1072+
$block_count = $decoder->read_long();
1073+
while (0 !== $block_count) {
1074+
if ($block_count < 0) {
1075+
$decoder->skip($this->read_long());
1076+
}
1077+
for ($i = 0; $i < $block_count; $i++) {
1078+
$decoder->skip_string();
1079+
AvroIODatumReader::skip_data($writers_schema->values(), $decoder);
1080+
}
1081+
$block_count = $decoder->read_long();
1082+
}
1083+
}
1084+
10331085
/**
10341086
* @param int $len count of bytes to skip
10351087
* @uses AvroIO::seek()

0 commit comments

Comments
 (0)