Skip to content
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

Covered more parquet edge cases #779

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/dremel/src/Flow/Dremel/Dremel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function assemble(array $repetitions, array $definitions, array $values)
if ($definition === 0) {
$output[] = null;
} elseif ($definition === $maxDefinitionLevel) {
$output[] = $values[$valueIndex];
$output[] = $values[$valueIndex] ?? null;
$valueIndex++;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/parquet/src/Flow/Parquet/Data/DataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static function initialize(Options $options) : self

public function fromParquetType(FlatColumn $column, mixed $data) : mixed
{
if ($data === null) {
return null;
}

if (\array_key_exists($column->flatPath(), $this->cache)) {
if ($this->cache[$column->flatPath()] === null) {
return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Flow\Parquet\Exception;

final class DataConversionException extends \Flow\ETL\Exception\RuntimeException
final class DataConversionException extends RuntimeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Flow\Parquet\Exception;

final class RuntimeException extends \RuntimeException
class RuntimeException extends \RuntimeException
{
}
9 changes: 7 additions & 2 deletions src/lib/parquet/src/Flow/Parquet/ParquetFile/PageReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ public function readData(FlatColumn $column, PageHeader $pageHeader, Compression

/* @phpstan-ignore-next-line */
$levelsLength = $pageHeader->dataPageHeaderV2()->repetitionsByteLength() + $pageHeader->dataPageHeaderV2()->definitionsByteLength();
/* @phpstan-ignore-next-line */
$levels = \fread($stream, $levelsLength);

if ($levelsLength) {
/* @phpstan-ignore-next-line */
$levels = \fread($stream, $levelsLength);
} else {
$levels = '';
}

$data = (new Codec($this->options))
->decompress(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php declare(strict_types=1);

namespace Flow\Parquet\Tests\Integration\IO;

use Flow\Parquet\Reader;
use PHPUnit\Framework\TestCase;

final class EdgeCasesReadingTest extends TestCase
{
public function test_nonullable_impala() : void
{
$path = __DIR__ . '/../../Fixtures/EdgeCases/nonnullable.impala.parquet';

$reader = (new Reader())->read($path);

$rows = [];

foreach ($reader->values() as $row) {
$rows[] = $row;
}

$this->assertSame(
[
[
'ID' => null,
'Int_Array' => [
'list' => [
'element' => 4294967295,
],
],
'int_array_array' => [
'list' => [
'element' => [
'list' => [
'element' => [
[4294967295, 4294967294],
[null],
],
],
],
],
],
'Int_Map' => [
'map' => [
'key' => 'k1',
'value' => 4294967295,
],
],
'int_map_array' => [
'list' => [
'element' => [
'map' => [
'key' => [null, 'k1', null, null],
'value' => [null, 1, null, null]],
],
],
],
'nested_Struct' => [
'a' => null,
'B' => [
'list' => [
'element' => 4294967295,
],
],
'c' => [
'D' => [
'list' => [
'element' => [
'list' => [
'element' => [
'e' => 4294967295,
'f' => 'nonnullable',
],
],
],
],
],
],
'G' => null,
],
],
],
$rows
);
}

public function test_read_datapage_v2_snappy_list() : void
{
$this->expectExceptionMessage('Encoding DELTA_BINARY_PACKED not supported');

$path = __DIR__ . '/../../Fixtures/EdgeCases/datapage_v2.snappy.parquet';

$reader = (new Reader())->read($path);

$rows = [];

foreach ($reader->values() as $row) {
$rows[] = $row;
}

$this->assertSame(
[
['emptylist' => null],
],
$rows
);
}

public function test_read_null_list() : void
{
$path = __DIR__ . '/../../Fixtures/EdgeCases/null_list.parquet';

$reader = (new Reader())->read($path);

$rows = [];

foreach ($reader->values() as $row) {
$rows[] = $row;
}

$this->assertSame(
[
['emptylist' => null],
],
$rows
);
}
}