Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL table: ->find(['TEST_ID' => 1]) lists all rows but only with the data from first row ? #18

Closed
zilveer opened this issue May 19, 2019 · 4 comments

Comments

@zilveer
Copy link

zilveer commented May 19, 2019

Hi,
I am using SQL tables with mapper but I have issues with fetching correct data when using SQL tables.

I am using the lastest versions of php-client and php-mapper, the dev repo.

This is how you can re-produce the issue:

tarantoolctl enter myplace
\set language sql
CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, some_id INTEGER, test_id INTEGER)
INSERT INTO user (some_id, test_id) VALUES (78, 1)
INSERT INTO user (some_id, test_id) VALUES (43, 2)
INSERT INTO user (some_id, test_id) VALUES (12, 1)

With using php-mapper I am doing this:
$testing = $mapper->getRepository('USERS')->find(['TEST_ID' => 1]);
the result is:

array (size=3)
  0 => 
    object(Tarantool\Mapper\Entity)[602]
      public 'ID' => int 1
      public 'SOME_ID' => int 78
      public 'TEST_ID' => int 1
  1 => 
    object(Tarantool\Mapper\Entity)[602]
      public 'ID' => int 1
      public 'SOME_ID' => int 78
      public 'TEST_ID' => int 2
  2 => 
    object(Tarantool\Mapper\Entity)[602]
      public 'ID' => int 1
      public 'SOME_ID' => int 78
      public 'TEST_ID' => int 1

Which means that is actually just returns all rows but with the content of the first row in the table when it should return:

array (size=3)
  0 => 
    object(Tarantool\Mapper\Entity)[602]
      public 'ID' => int 1
      public 'SOME_ID' => int 78
      public 'TEST_ID' => int 1
  1 => 
    object(Tarantool\Mapper\Entity)[602]
      public 'ID' => int 3
      public 'SOME_ID' => int 12
      public 'TEST_ID' => int 1

If you have any questions regarding this please let me know.
If you can fix this bug I would be very happy.

regards Zilveer

@zilveer zilveer changed the title SQL table: ->find(['TEST_ID' => 1]) returns all rows? SQL table: ->find(['TEST_ID' => 1]) lists all rows but only with the data from first row ? May 19, 2019
@zilveer
Copy link
Author

zilveer commented May 19, 2019

I have found where the bug is causing the issue,
In Repository.php file line 213-219 there is a code:

foreach ($data as $tuple) {
    $instance = $this->getInstance($tuple);
    if ($one) {
        return $this->results[$cacheKey] = $instance;
    }
    $result[] = $instance;
}

I replaced it with:

foreach ($data as $tuple) {
    echo 'tuple:';
    var_dump($tuple);
    $instance = $this->getInstance($tuple);
    echo 'instance:';
    var_dump($instance);
    echo '<hr>';
    if ($one) {
        return $this->results[$cacheKey] = $instance;
    }
    $result[] = $instance;
}

and it seems to me that the request to $this->getInstance($tuple); is only returning the first row even though the tuple is shown with correct data (test my code and you will see).

EDIT:
I changed getTupleKey to the following code in Space.php:

public function getTupleKey(array $tuple)
{
    $key = [];
    foreach ($this->getPrimaryIndex()['parts'] as $part) {
        echo 'part';
        var_dump($part);
        if(isset($part[0]))
            $key[] = $tuple[$part[0]];
        if(isset($part['field']))
            $key[] = $tuple[$part['field']];
        
    }
    return count($key) == 1 ? $key[0] : implode(':', $key);
}

and now it shows all rows data correct, but it still shows all rows, so probably the function getInstance in file Repository.php needs to be adapted for SQL tables to only return the correct data.

regards Zilveer

@nekufa nekufa closed this as completed in fce1122 Jun 24, 2019
@nekufa
Copy link
Member

nekufa commented Jun 26, 2019

Hello @zilveer, thanks for you feedback!
I found out why sql-based spaces were not working - index format was changed.
This bug was fixed in the latest version, let me know if something else goes wrong.

@zilveer
Copy link
Author

zilveer commented Jul 3, 2019

@nekufa Perfect, i Will test it again.

Regards

@zilveer
Copy link
Author

zilveer commented Jul 9, 2019

Perfect it works good now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants