From 8662f3db2983ca54deb2e804790733ab302ac450 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 16 Oct 2023 14:44:22 +0200 Subject: [PATCH] Replace hashing algorithm from `sha256` to `xxh128` --- src/core/etl/src/Flow/ETL/Cache/LocalFilesystemCache.php | 2 +- src/core/etl/src/Flow/ETL/GroupBy.php | 4 ++-- src/core/etl/tests/Flow/ETL/Tests/Integration/FlowTest.php | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/etl/src/Flow/ETL/Cache/LocalFilesystemCache.php b/src/core/etl/src/Flow/ETL/Cache/LocalFilesystemCache.php index e699c4fcc..831a5c967 100644 --- a/src/core/etl/src/Flow/ETL/Cache/LocalFilesystemCache.php +++ b/src/core/etl/src/Flow/ETL/Cache/LocalFilesystemCache.php @@ -90,6 +90,6 @@ public function read(string $id) : \Generator private function cachePath(string $id) : string { - return \rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \hash('sha256', $id); + return \rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \hash('xxh128', $id); } } diff --git a/src/core/etl/src/Flow/ETL/GroupBy.php b/src/core/etl/src/Flow/ETL/GroupBy.php index e69536451..4e176e164 100644 --- a/src/core/etl/src/Flow/ETL/GroupBy.php +++ b/src/core/etl/src/Flow/ETL/GroupBy.php @@ -120,12 +120,12 @@ private function hash(array $values) : string /** @var mixed $value */ foreach ($values as $value) { if ($value === null) { - $stringValues[] =\hash('sha256', 'null'); + $stringValues[] =\hash('xxh128', 'null'); } elseif (\is_scalar($value)) { $stringValues[] = (string) $value; } } - return \hash('sha256', \implode('', $stringValues)); + return \hash('xxh128', \implode('', $stringValues)); } } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/FlowTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/FlowTest.php index 32dd2e8f6..ebe3febee 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/FlowTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/FlowTest.php @@ -4,7 +4,6 @@ namespace Flow\ETL\Tests\Integration; -use function Flow\ETL\DSL\col; use function Flow\ETL\DSL\ref; use Flow\ETL\Cache\PSRSimpleCache; use Flow\ETL\Config; @@ -27,7 +26,7 @@ public function test_etl_cache() : void $cacheContent = \array_values(\array_diff(\scandir($this->cacheDir), ['..', '.'])); - $this->assertContains(\hash('sha256', 'test_etl_cache'), $cacheContent); + $this->assertContains(\hash('xxh128', 'test_etl_cache'), $cacheContent); } public function test_etl_psr_cache() : void @@ -84,7 +83,7 @@ public function test_etl_sort_by_in_memory() : void ->id($id = 'test_etl_sort_by_in_memory') ->cache($cacheSpy = new CacheSpy(Config::default()->cache())) )->extract(new AllRowTypesFakeExtractor($rowsets = 20, $rows = 2)) - ->sortBy(col('id')) + ->sortBy(ref('id')) ->fetch(); $cache = \array_diff(\scandir($this->cacheDir), ['..', '.']);