Skip to content

Commit 6a1d2db

Browse files
author
codeliner
committed
Fix that nested NOT filter is not working properly
1 parent 7acd9fe commit 6a1d2db

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/PostgresDocumentStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private function filterToWhereClause(Filter $filter, $argsCount = 0): array
609609
throw new RuntimeException('Not filter cannot be combined with a non prop filter!');
610610
}
611611

612-
[$innerFilterStr, $args, $argsCount] = $this->filterToWhereClause($innerFilter);
612+
[$innerFilterStr, $args, $argsCount] = $this->filterToWhereClause($innerFilter, $argsCount);
613613

614614
if($innerFilter instanceof DocumentStore\Filter\AnyOfFilter || $innerFilter instanceof DocumentStore\Filter\AnyOfDocIdFilter) {
615615
$inPos = strpos($innerFilterStr, ' IN(');

tests/PostgresDocumentStoreTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace EventEngine\DocumentStoreTest\Postgres;
1313

14+
use EventEngine\DocumentStore\Filter\AndFilter;
1415
use EventEngine\DocumentStore\Filter\AnyOfDocIdFilter;
1516
use EventEngine\DocumentStore\Filter\AnyOfFilter;
1617
use EventEngine\DocumentStore\Filter\DocIdFilter;
18+
use EventEngine\DocumentStore\Filter\EqFilter;
1719
use EventEngine\DocumentStore\Filter\InArrayFilter;
1820
use EventEngine\DocumentStore\Filter\NotFilter;
1921
use PHPUnit\Framework\TestCase;
@@ -22,6 +24,7 @@
2224
use EventEngine\DocumentStore\MultiFieldIndex;
2325
use EventEngine\DocumentStore\Postgres\PostgresDocumentStore;
2426
use Ramsey\Uuid\Uuid;
27+
use function array_map;
2528

2629
class PostgresDocumentStoreTest extends TestCase
2730
{
@@ -396,6 +399,41 @@ public function it_handles_in_array_filter_with_object_items()
396399
$this->assertEquals([$secondDocId, $thirdDocId], $refs);
397400
}
398401

402+
/**
403+
* @test
404+
*/
405+
public function it_handles_not_filter_nested_in_and_filter()
406+
{
407+
$collectionName = 'test_not_filter_nested_in_and_filter';
408+
$this->documentStore->addCollection($collectionName);
409+
410+
$firstDocId = Uuid::uuid4()->toString();
411+
$secondDocId = Uuid::uuid4()->toString();
412+
$thirdDocId = Uuid::uuid4()->toString();
413+
414+
$this->documentStore->addDoc($collectionName, $firstDocId, ['foo' => ['bar' => 'bas'], 'ref' => $firstDocId]);
415+
$this->documentStore->addDoc($collectionName, $secondDocId, ['foo' => ['bar' => 'bat'], 'ref' => $secondDocId]);
416+
$this->documentStore->addDoc($collectionName, $thirdDocId, ['foo' => ['bar' => 'bat'], 'ref' => $thirdDocId]);
417+
418+
$filteredDocs = \iterator_to_array($this->documentStore->filterDocs(
419+
$collectionName,
420+
new AndFilter(
421+
new EqFilter('foo.bar', 'bat'),
422+
new NotFilter(
423+
new EqFilter('ref', $secondDocId)
424+
)
425+
)
426+
));
427+
428+
$this->assertCount(1, $filteredDocs);
429+
430+
$refs = array_map(function (array $doc) {
431+
return $doc['ref'];
432+
}, $filteredDocs);
433+
434+
$this->assertEquals([$thirdDocId], $refs);
435+
}
436+
399437
private function getIndexes(string $collectionName): array
400438
{
401439
return TestUtil::getIndexes($this->connection, self::TABLE_PREFIX.$collectionName);

0 commit comments

Comments
 (0)