Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7e3656b
added support for object type attribute
ArnabChatterjee20k Oct 17, 2025
6edfe1a
updated validators
ArnabChatterjee20k Oct 17, 2025
4483496
updated tests
ArnabChatterjee20k Oct 17, 2025
10cf2bd
* added gin index
ArnabChatterjee20k Oct 17, 2025
8cd5921
removed redundant return after skip in tests
ArnabChatterjee20k Oct 17, 2025
117af69
updated array handling for equal and contains in object
ArnabChatterjee20k Oct 17, 2025
a92fd41
Merge remote-tracking branch 'upstream/main' into var_object
ArnabChatterjee20k Oct 17, 2025
979619f
fixed gin index issue
ArnabChatterjee20k Oct 17, 2025
6ba8558
updated validating default types
ArnabChatterjee20k Oct 17, 2025
49139d8
Merge remote-tracking branch 'upstream/main' into var_object
ArnabChatterjee20k Oct 27, 2025
739a4c3
* added support method in the mongodb adapter
ArnabChatterjee20k Oct 27, 2025
2cb3d98
renamed gin to object index to have a general term
ArnabChatterjee20k Oct 27, 2025
e2768d9
updated lock file
ArnabChatterjee20k Oct 27, 2025
f62ff51
Merge remote-tracking branch 'upstream/main' into var_object
ArnabChatterjee20k Oct 28, 2025
f5c0cfd
Refactor object type constants to use VAR_OBJECT for consistency acro…
ArnabChatterjee20k Oct 31, 2025
9a96110
added object validator test
ArnabChatterjee20k Nov 3, 2025
fd74c74
Merge remote-tracking branch 'upstream/3.x' into var_object
ArnabChatterjee20k Nov 6, 2025
1a4151d
fixed count, upsert methods for vector
ArnabChatterjee20k Nov 6, 2025
d4e3876
updated upsert fix, added sum fix
ArnabChatterjee20k Nov 6, 2025
8649aca
update var_object to be a filter similar to other types
ArnabChatterjee20k Nov 6, 2025
cd4e0b5
linting
ArnabChatterjee20k Nov 6, 2025
80b742e
Merge branch 'fix/vector-queries' into var_object
ArnabChatterjee20k Nov 6, 2025
9a0cea6
added test to simulate a vector store
ArnabChatterjee20k Nov 6, 2025
fad8570
removed reduntant comment
ArnabChatterjee20k Nov 11, 2025
29f4cfe
updated the semantics for not equal case
ArnabChatterjee20k Nov 11, 2025
5b34785
index, attribute filters, typo updates
ArnabChatterjee20k Nov 12, 2025
9a01de3
linting
ArnabChatterjee20k Nov 12, 2025
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
Prev Previous commit
Next Next commit
updated the semantics for not equal case
  • Loading branch information
ArnabChatterjee20k committed Nov 11, 2025
commit 29f4cfe9f0d6260add6ed8e49fb917958f6c3e64
6 changes: 5 additions & 1 deletion src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ public static function equal(string $attribute, array $values): self
*/
public static function notEqual(string $attribute, string|int|float|bool|array $value): self
{
return new self(self::TYPE_NOT_EQUAL, $attribute, is_array($value) ? $value : [$value]);
// maps or not an array
if ((is_array($value) && !array_is_list($value)) || !is_array($value)) {
$value = [$value];
}
return new self(self::TYPE_NOT_EQUAL, $attribute, $value);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Database/Validator/Query/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,8 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
break;

case Database::VAR_OBJECT:
// For JSONB/object queries, value must be an array
if (!is_array($value)) {
$this->message = 'Query value for object type must be an array';
return false;
}
// No further validation needed - JSONB accepts any valid array structure
// value for object can be of any type as its a hashmap
// eg; ['key'=>value']
continue 2;

case Database::VAR_POINT:
Expand Down
23 changes: 18 additions & 5 deletions tests/e2e/Adapter/Scopes/ObjectAttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Tests\E2E\Adapter\Scopes;

use Exception;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Index as IndexException;
use Utopia\Database\Exception\Query as QueryException;
use Utopia\Database\Exception\Structure as StructureException;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission;
Expand Down Expand Up @@ -152,21 +154,31 @@ public function testObjectAttribute(): void

// Test 11d: notEqual on scalar inside object should exclude doc1
$results = $database->find($collectionId, [
Query::notEqual('meta', [['age' => 26]])
Query::notEqual('meta', ['age' => 26])
]);
// Should return doc2 only
$this->assertCount(1, $results);
$this->assertEquals('doc2', $results[0]->getId());

try {
// test -> not equal allows one value only
$results = $database->find($collectionId, [
Query::notEqual('meta', [['age' => 26],['age' => 27]])
]);
$this->fail('No query thrown');
} catch (Exception $e) {
$this->assertInstanceOf(QueryException::class, $e);
}

// Test 11e: notEqual on nested object should exclude doc1
$results = $database->find($collectionId, [
Query::notEqual('meta', [[
Query::notEqual('meta', [
'user' => [
'info' => [
'country' => 'CA'
]
]
]])
])
]);
// Should return doc2 only
$this->assertCount(1, $results);
Expand Down Expand Up @@ -588,9 +600,10 @@ public function testObjectAttributeGinIndex(): void

// Test 3: Query with equal on indexed JSONB column
$results = $database->find($collectionId, [
Query::equal('data', [['env' => 'production']])
Query::equal('data', [['config' => ['env' => 'production']]])
]);
$this->assertCount(0, $results); // Note: Object index doesn't make equal queries work differently
$this->assertCount(1, $results);
$this->assertEquals('gin1', $results[0]->getId());

// Test 4: Query with contains on indexed JSONB column
$results = $database->find($collectionId, [
Expand Down