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

Add snappy tests based on extension and polyfill #1108

Merged
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
7 changes: 6 additions & 1 deletion .github/workflows/test-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ jobs:
tools: composer:v2
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
extensions: :psr, brotli, lz4, zstd
extensions: :psr, brotli, lz4, zstd, snappy-https://github.com/kjdev/[email protected]
env:
SNAPPY_CONFIGURE_PREFIX_OPTS: "CXXFLAGS=-std=c++11"

- name: "List PHP Extensions"
run: php -m
Expand Down Expand Up @@ -95,3 +97,6 @@ jobs:

- name: "Test ZSTD"
run: "composer test -- --group zstd-extension"

- name: "Test Snappy"
run: "composer test -- --group snappy-extension"
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,64 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void
\unlink($path);
}

#[Group('snappy-extension')]
public function test_writing_and_reading_file_with_snappy_compression() : void
{
if (!\extension_loaded('snappy')) {
self::markTestSkipped('The snappy extension is not available');
}

$path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet';

$writer = new Writer(Compressions::SNAPPY);

$schema = Schema::with(NestedColumn::struct('struct', [
FlatColumn::int64('int64'),
FlatColumn::boolean('boolean'),
FlatColumn::string('string'),
FlatColumn::int32('int32'),
NestedColumn::list('list_of_int', ListElement::int32()),
NestedColumn::list('list_of_string', ListElement::string()),
]));

$faker = Factory::create();
$inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array {
return [
[
'struct' => [
'int64' => $faker->numberBetween(0, Consts::PHP_INT64_MAX),
'boolean' => $faker->boolean,
'string' => $faker->text(150),
'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX),
'list_of_int' => \array_map(
static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX),
\range(1, \random_int(2, 10))
),
'list_of_string' => \array_map(
static fn ($i) => $faker->text(10),
\range(1, \random_int(2, 10))
),
],
],
];
}, \range(1, 100)));

$writer->write($path, $schema, $inputData);

self::assertSame(
$inputData,
\iterator_to_array((new Reader())->read($path)->values())
);
self::assertFileExists($path);
\unlink($path);
}

public function test_writing_and_reading_file_with_snappy_polyfill() : void
{
if (\extension_loaded('snappy')) {
self::markTestSkipped('The snappy extension is available');
}

$path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet';

$writer = new Writer(Compressions::SNAPPY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,29 @@ public function test_lz4_raw() : void
);
}

#[Group('snappy-extension')]
public function test_snappy() : void
{
if (!\extension_loaded('snappy')) {
self::markTestSkipped('The snappy extension is not available');
}

$data = 'this is some test data to be compressed';

$codec = new Codec((new Options()));

self::assertSame(
$data,
$codec->decompress($codec->compress($data, Compressions::SNAPPY), Compressions::SNAPPY)
);
}

public function test_snappy_polyfill() : void
{
if (\extension_loaded('snappy')) {
self::markTestSkipped('The snappy extension is available');
}

$data = 'this is some test data to be compressed';

$codec = new Codec((new Options()));
Expand All @@ -86,7 +107,7 @@ public function test_snappy() : void
);
}

public function test_uncompressed() : void
public function test_snappy_uncompressed() : void
{
$data = 'this is some test data to be compressed';

Expand Down
Loading