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

$bolt->pull() returns private objects #49

Closed
isayeter opened this issue Apr 23, 2021 · 5 comments
Closed

$bolt->pull() returns private objects #49

isayeter opened this issue Apr 23, 2021 · 5 comments

Comments

@isayeter
Copy link

Hello there, when I run this code,

$res = $bolt->run('
	MATCH ()-->() RETURN count(*)
');

This is the output of print_r($bolt->pull()); :

Array
(
    [0] => Array
        (
            [0] => 7000000
        )

    [1] => Array
        (
            [bookmark] => FB:kcwQh+8j7SWhTdq4HJXlCqJs0j6Q
            [type] => r
            [t_last] => 0
            [db] => neo4j
        )

)

I can access the result by $bolt->pull()[0][0];

However when I run this query:

MATCH p=shortestPath(
	(u1:User {userID:"270350200"})-[:follows*]->(u2:User {userID:"17911468618"})
)
RETURN p

This is the output of print_r($bolt->pull()); :

Array
(
    [0] => Array
        (
            [0] => Bolt\structures\Path Object
                (
                    [nodes:Bolt\structures\Path:private] => Array
                        (
                            [0] => Bolt\structures\Node Object
                                (
                                    [id:Bolt\structures\Node:private] => 1000015
                                    [labels:Bolt\structures\Node:private] => Array
                                        (
                                            [0] => User
                                        )

                                    [properties:Bolt\structures\Node:private] => Array
                                        (
                                            [userID] => 270350200
                                        )

                                )

                            [1] => Bolt\structures\Node Object
                                (
                                    [id:Bolt\structures\Node:private] => 1000527
                                    [labels:Bolt\structures\Node:private] => Array
                                        (
                                            [0] => User
                                        )

                                    [properties:Bolt\structures\Node:private] => Array
                                        (
                                            [userID] => 11126166
                                        )

                                )

                            [2] => Bolt\structures\Node Object
                                (
                                    [id:Bolt\structures\Node:private] => 1007260
                                    [labels:Bolt\structures\Node:private] => Array
                                        (
                                            [0] => User
                                        )

                                    [properties:Bolt\structures\Node:private] => Array
                                        (
                                            [userID] => 2463846399
                                        )

                                )

                            [3] => Bolt\structures\Node Object
                                (
                                    [id:Bolt\structures\Node:private] => 1000095
                                    [labels:Bolt\structures\Node:private] => Array
                                        (
                                            [0] => User
                                        )

                                    [properties:Bolt\structures\Node:private] => Array
                                        (
                                            [userID] => 1043081670
                                        )

                                )

                            [4] => Bolt\structures\Node Object
                                (
                                    [id:Bolt\structures\Node:private] => 1000007
                                    [labels:Bolt\structures\Node:private] => Array
                                        (
                                            [0] => User
                                        )

                                    [properties:Bolt\structures\Node:private] => Array
                                        (
                                            [userID] => 17911468618
                                        )

                                )

                        )

                    [rels:Bolt\structures\Path:private] => Array
                        (
                            [0] => Bolt\structures\UnboundRelationship Object
                                (
                                    [id:Bolt\structures\UnboundRelationship:private] => 1105
                                    [type:Bolt\structures\UnboundRelationship:private] => follows
                                    [properties:Bolt\structures\UnboundRelationship:private] => Array
                                        (
                                        )

                                )

                            [1] => Bolt\structures\UnboundRelationship Object
                                (
                                    [id:Bolt\structures\UnboundRelationship:private] => 147354
                                    [type:Bolt\structures\UnboundRelationship:private] => follows
                                    [properties:Bolt\structures\UnboundRelationship:private] => Array
                                        (
                                        )

                                )

                            [2] => Bolt\structures\UnboundRelationship Object
                                (
                                    [id:Bolt\structures\UnboundRelationship:private] => 2769516
                                    [type:Bolt\structures\UnboundRelationship:private] => follows
                                    [properties:Bolt\structures\UnboundRelationship:private] => Array
                                        (
                                        )

                                )

                            [3] => Bolt\structures\UnboundRelationship Object
                                (
                                    [id:Bolt\structures\UnboundRelationship:private] => 8225
                                    [type:Bolt\structures\UnboundRelationship:private] => follows
                                    [properties:Bolt\structures\UnboundRelationship:private] => Array
                                        (
                                        )

                                )

                        )

                    [ids:Bolt\structures\Path:private] => Array
                        (
                            [0] => 1
                            [1] => 1
                            [2] => 2
                            [3] => 2
                            [4] => 3
                            [5] => 3
                            [6] => 4
                            [7] => 4
                        )

                )

        )

    [1] => Array
        (
            [bookmark] => FB:kcwQh+8j7SWhTdq4HJXlCqJs0j6Q
            [type] => r
            [t_last] => 1
            [db] => neo4j
            [notifications] => Array
                (
                    [0] => Array
                        (
                            [severity] => WARNING
                            [description] => Using shortest path with an unbounded pattern will likely result in long execution times. It is recommended to use an upper limit to the number of node hops in your pattern.
                            [code] => Neo.ClientNotification.Statement.UnboundedVariableLengthPatternWarning
                            [position] => Array
                                (
                                    [column] => 42
                                    [offset] => 64
                                    [line] => 3
                                )

                            [title] => The provided pattern is unbounded, consider adding an upper limit to the number of node hops.
                        )

                )

        )

)

I cant access the results neither $bolt->pull()[0][0]->nodes , $bolt->pull()[0][0]->rels , $bolt->pull()[0][0]->ids
they are all private variables, how can I access the result of that query?

Thank you.

@isayeter
Copy link
Author

And also, when I run a query that takes more than 60 seconds like:

try 
{
	$res = $bolt->run("
		LOAD CSV FROM 'file:///1619216052-500000-ff472d31be752fd62fb985aa1b915fb4.csv' AS row
		MERGE (u1:User{userID: row[0]})
		MERGE (u2:User{userID: row[1]})
		MERGE (u1)-[r:follows]->(u2);
	", array(), array("tx_timeout" => 200000));
} 
catch (Exception $e) 
{
	print_r($e);
	die();
}

it produces this error:

Bolt\error\ConnectException Object
(
    [message:protected] => Read error
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /..../vendor/stefanak-michal/bolt/src/connection/StreamSocket.php
    [line:protected] => 97
    ....

even I set tx_timeout: 20000 I think it is fallbacking after 60 seconds. How to fix this problem?

@stefanak-michal
Copy link
Collaborator

Hi.
Did you try $bolt->pull()[0][0]->nodes() ?

The structure class is immutable and you have to access properties through methods.

https://github.com/neo4j-php/Bolt/blob/master/src/structures/Path.php

@stefanak-michal
Copy link
Collaborator

And also, when I run a query that takes more than 60 seconds like:

try 
{
	$res = $bolt->run("
		LOAD CSV FROM 'file:///1619216052-500000-ff472d31be752fd62fb985aa1b915fb4.csv' AS row
		MERGE (u1:User{userID: row[0]})
		MERGE (u2:User{userID: row[1]})
		MERGE (u1)-[r:follows]->(u2);
	", array(), array("tx_timeout" => 200000));
} 
catch (Exception $e) 
{
	print_r($e);
	die();
}

it produces this error:

Bolt\error\ConnectException Object
(
    [message:protected] => Read error
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /..../vendor/stefanak-michal/bolt/src/connection/StreamSocket.php
    [line:protected] => 97
    ....

even I set tx_timeout: 20000 I think it is fallbacking after 60 seconds. How to fix this problem?

You set transaction timeout, not the connection timeout. If you want to set connection timeout, check up this page https://github.com/neo4j-php/Bolt/wiki/Connection

@isayeter
Copy link
Author

isayeter commented Apr 24, 2021

Hi.
Did you try $bolt->pull()[0][0]->nodes() ?

The structure class is immutable and you have to access properties through methods.

https://github.com/neo4j-php/Bolt/blob/master/src/structures/Path.php

oh sorry my bad, thank you.

And also, when I run a query that takes more than 60 seconds like:

try 
{
	$res = $bolt->run("
		LOAD CSV FROM 'file:///1619216052-500000-ff472d31be752fd62fb985aa1b915fb4.csv' AS row
		MERGE (u1:User{userID: row[0]})
		MERGE (u2:User{userID: row[1]})
		MERGE (u1)-[r:follows]->(u2);
	", array(), array("tx_timeout" => 200000));
} 
catch (Exception $e) 
{
	print_r($e);
	die();
}

it produces this error:

Bolt\error\ConnectException Object
(
    [message:protected] => Read error
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /..../vendor/stefanak-michal/bolt/src/connection/StreamSocket.php
    [line:protected] => 97
    ....

even I set tx_timeout: 20000 I think it is fallbacking after 60 seconds. How to fix this problem?

You set transaction timeout, not the connection timeout. If you want to set connection timeout, check up this page https://github.com/neo4j-php/Bolt/wiki/Connection

Yes, I set the timeout parameter 120000 in the constructor, it works now thank you.

However I have now another problem,

Message 'RUN
   LOAD CSV FROM 'file:///1619211853-500000-183d976272c0fd3d0ca5ae7ca8dfc91f.csv' AS row
   MERGE (u1:User{userID: row[0]})
   MERGE (u2:User{userID: row[1]})
   MERGE (u1)-[r:follows]->(u2);
Map{} Map{}' cannot be handled by a session in the AUTOCOMMIT state. (Neo.ClientError.Request.Invalid)

Sorry I'm a newbie in graph db's and bolt protocol, thank you for your kind helps.

@stefanak-michal
Copy link
Collaborator

If you call run, it will execute query in auto-commit state, which means it will open transaction, execute query and close transaction. It's neo4j behaviour. You can start transaction by yourself with $bolt->begin(), then call run how many times you want and later $bolt->commit() or rollback.

https://github.com/neo4j-php/Bolt/wiki/Usage

https://7687.org/bolt/bolt-protocol-message-specification-4.html#transaction

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