diff --git a/.github/workflows/test-extensions.yml b/.github/workflows/test-extensions.yml index dd228a636..3426cc9df 100644 --- a/.github/workflows/test-extensions.yml +++ b/.github/workflows/test-extensions.yml @@ -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/php-ext-snappy@0.2.1 + env: + SNAPPY_CONFIGURE_PREFIX_OPTS: "CXXFLAGS=-std=c++11" - name: "List PHP Extensions" run: php -m @@ -95,3 +97,6 @@ jobs: - name: "Test ZSTD" run: "composer test -- --group zstd-extension" + + - name: "Test Snappy" + run: "composer test -- --group snappy-extension" \ No newline at end of file diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php index d6f7bb400..2de93d1bb 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php @@ -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); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Unit/ParquetFile/CodecTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Unit/ParquetFile/CodecTest.php index aaa46bf6c..daff1c4d4 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Unit/ParquetFile/CodecTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Unit/ParquetFile/CodecTest.php @@ -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())); @@ -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';