Skip to content

Commit

Permalink
Recognize INT32 with deprecated ConvertedType as DateTimeImmutable ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
norberttech committed Jun 9, 2024
1 parent 42df541 commit c7c8bf0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Flow\Parquet\BinaryReader\Bytes;
use Flow\Parquet\Data\Converter;
use Flow\Parquet\ParquetFile\Schema\{FlatColumn, PhysicalType};
use Flow\Parquet\ParquetFile\Schema\{ConvertedType, FlatColumn, PhysicalType};
use Flow\Parquet\{Option, Options};

final class BytesStringConverter implements Converter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Flow\Parquet\Data\Converter;
use Flow\Parquet\Options;
use Flow\Parquet\ParquetFile\Schema\{FlatColumn, LogicalType, PhysicalType};
use Flow\Parquet\ParquetFile\Schema\{ConvertedType, FlatColumn, LogicalType, PhysicalType};

final class Int32DateConverter implements Converter
{
Expand All @@ -21,6 +21,10 @@ public function isFor(FlatColumn $column, Options $options) : bool
return true;
}

if ($column->type() === PhysicalType::INT32 && $column->convertedType() === ConvertedType::DATE) {
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Flow\Parquet\Tests\Unit\Data\Converter;

use Flow\Parquet\Data\Converter\Int32DateConverter;
use Flow\Parquet\Options;
use Flow\Parquet\ParquetFile\Schema\{ConvertedType, FlatColumn, PhysicalType};
use PHPUnit\Framework\TestCase;

final class Int32DateConverterTest extends TestCase
Expand All @@ -20,4 +22,21 @@ public function test_converting_dates() : void
$converter->fromParquetType($converter->toParquetType($date))
);
}

public function test_converting_int32_with_deprecated_converted_type() : void
{
$converter = new Int32DateConverter();

self::assertTrue(
$converter->isFor(
new FlatColumn(
'date',
PhysicalType::INT32,
ConvertedType::DATE,
null,
),
Options::default()
)
);
}
}

0 comments on commit c7c8bf0

Please sign in to comment.