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

Batch Branch: 400 Bad Request #4

Closed
picklepete opened this issue Aug 23, 2011 · 5 comments
Closed

Batch Branch: 400 Bad Request #4

picklepete opened this issue Aug 23, 2011 · 5 comments

Comments

@picklepete
Copy link

Hi Josh,

I'm currently trying your batch branch and have encountered an error in committing operations, the following example code should work:

<?php
    use Everyman\Neo4j\Transport,
        Everyman\Neo4j\Client,
        Everyman\Neo4j\Index,
        Everyman\Neo4j\Relationship,
        Everyman\Neo4j\Node,
        Everyman\Neo4j\Batch;

    error_reporting(-1);
    ini_set('display_errors', 1);

    function loaderTestAutoloader($sClass)
    {
        $sLibPath = __DIR__.'/batch-lib/';
        $sClassFile = str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php';
        $sClassPath = $sLibPath.$sClassFile;
        if (file_exists($sClassPath)) {
            require($sClassPath);
        }
    }
    spl_autoload_register('loaderTestAutoloader');

    $transport = new Transport();
    $client = new Client($transport);

    $batch = new Batch($client);

    $node = new Node($client);
    $node->setProperties(array('foo' => 'bar', 'baz' => 'qux'));
    $batch->save($node);

    $result = $batch->commit();
    var_dump($result);
?>

The issue lies in that $result will always return false. After some debugging I discovered that Java is returning a 400 Bad Request with the following message: java.util.LinkedHashMap cannot be cast to java.util.List in Transport->makeRequest(). The full stacktrace is available here: https://gist.github.com/25fd7f7aef3fdb77e32a

I'm currently running Neo4j 1.4.1 (upgraded from 1.4, just in case that was the problem).

Any ideas?

Cheers,

  • Peter
@jadell
Copy link
Owner

jadell commented Aug 23, 2011

Hey Peter,

I haven't had time to investigate yet, but I suspect it's because the request data is not getting JSON encoded correctly. Can you var_dump the output of Transport::encodeData(); in the Transport::makeRequest() method, and post it here? File is lib/Everyman/Neo4j/Transport.php

Thanks!

-- Josh

@picklepete
Copy link
Author

Hey Josh,

Thanks for the quick reply, here's what is being encoded ($data):

Array
(
    [0] => Array
        (
            [method] => POST
            [to] => /node
            [body] => Array
                (
                    [foo] => bar
                    [baz] => qux
                )

            [id] => 0
        )
)

And this is what is being outputted by encodeData():

{"0":{"method":"POST","to":"\/node","body":{"foo":"bar","baz":"qux"},"id":0}}

Cheers,

  • Peter

@jadell
Copy link
Owner

jadell commented Aug 23, 2011

Hey Peter,

The problem is that the outer "wrapper" of the data should be encoded as an array, not an object. In other words, the data needs to end up looking like this:

[{"method":"POST","to":"\/node","body":{"foo":"bar","baz":"qux"},"id":0}]

A potential fix might be to have Transport::encodeData() look to see if the outer array is numerically indexed only and, if so, not cast it to an object before encoding. I will take a look at it soon, or you can take a stab at it if you want.

Thanks for the find!

-- Josh

@jadell
Copy link
Owner

jadell commented Aug 23, 2011

Hey Peter,

Could you pull the latest batch branch, which includes commit 87499ce. It should fix the issue. Please let me know if there is still a problem.

Thanks.

-- Josh

@picklepete
Copy link
Author

Hey Josh, your fix worked, thanks :) I'm opening a separate ticket however, as batch inserts are incredibly slow compared to sequential inserts. Example script / benchmarks in #5.

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