Skip to content

Commit

Permalink
set_indexes fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Firetawnyowl authored and nekufa committed May 7, 2024
1 parent f1c7fdb commit 940c183
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ public function setIndexes(array $indexes)
foreach ($indexes as $n => $index) {
$indexes[$n]['fields'] = [];
foreach ($index['parts'] as $part) {
$indexes[$n]['fields'][] = $this->fields[$part[0]];
if (array_key_exists('field', $part)){
$indexes[$n]['fields'][] = $this->fields[$part['field']];
} else {
$indexes[$n]['fields'][] = $this->fields[$part[0]];
}
}
}
$this->indexes = $indexes;
Expand Down
49 changes: 49 additions & 0 deletions tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use Tarantool\Client\Client;
use Tarantool\Mapper\Mapper;
use Tarantool\Mapper\Pool;
use Tarantool\Mapper\Space;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

class MapperTest extends TestCase
Expand Down Expand Up @@ -49,6 +51,53 @@ public function testCache()
$this->assertCount($freshCounter - 4, $this->middleware->data);
}

// public function testSpaceGetFormat()
// {

// }

public function testDifferentIndexPartConfiguration()
{
$mapper = $this->createMapper();
foreach ($mapper->find('_vspace') as $space) {
if ($space['id'] >= 512) {
$mapper->getSpace($space['id'])->drop();
}
}

$tester = $mapper->createSpace('tester');
$tester->addProperty('id', 'unsigned');
$tester->addProperty('name', 'string');

$tester->addIndex(['name'], ['name'=>'first']);

$mapper->client->call("box.space.tester:create_index", 'second', [
'parts' => ['name']
]);

$indexSpace = $mapper->getSpace('_index');

$third = [
'id' => $tester->getId(),
'iid' => count($mapper->find('_vindex', ['id' => $tester->getId()])) + 1,
'name' => 'third',
'opts' => ['unique' => false],
'type' => 'tree',
'parts' => [
['field'=> 1, 'type' => 'str']
]
];

$mapper->client->call("box.space._index:insert", $indexSpace->getTuple($third));

$property = new ReflectionProperty(Space::class, 'indexes');
$property->setAccessible(true);
$indexes = $property->getValue($tester);

$this->assertSame($indexes[1]['fields'], $indexes[2]['fields']);
$this->assertSame($indexes[1]['fields'], $indexes[3]['fields']);
}

public function testLua()
{
$mapper = $this->createMapper();
Expand Down

0 comments on commit 940c183

Please sign in to comment.