Giter Site home page Giter Site logo

Comments (5)

zhenlineo avatar zhenlineo commented on June 15, 2024

Hi Christian,

The fieldNames of the SUCCESS message are not get replaced, as the two SUCCESS messages are independent.

In the example,

 Client: RUN "MATCH (a:Person) RETURN a.name AS name, a.age AS age" {}
 Client: PULL_ALL
 Server: SUCCESS {"fields": ["name", "age"]} <---- a reply to RUN "MATCH..."
 Server: RECORD ["Alice", 33]
 Server: RECORD ["Bob", 44]
 Server: RECORD ["Carol", 55]
 Server: SUCCESS {} <----- a reply to PULL_ALL

As you could see, the first SUCCESS message is an answer to the RUN query, and then the second SUCCESS message is a reply to PULL_ALL. So having the second SUCCESS being empty is not considered to be an error.

Furthermore, we currently have a draft to expand the second empty SUCCESS message to provide more info while using PROFILE and EXPLAIN neo4j/neo4j#5271 (doc: https://github.com/neo4j/neo4j/pull/5271/files#diff-1de199999691d6c1b9b19a1da6bb7073R199)

Then for your question: "is there a way to address stream's current Record object directly instead of using the fieldNames()/get() functions and how would fieldNames() be used, if it is empty after a succesful exchange?"

I am not quite understand what you want to achieve here. If I understand you correctly then you want to get the field names when a Record is still a RecordMessage object (the string received from the server)? If so then you need to capture the first SUCESS message and then parse the field names yourself. But why you want to achieve this? Why not just use the Result rs object?

Driver driver = GraphDatabase.driver( "neo4j://localhost" );    
Session session = driver.session();
Result rs = session.run("MATCH (n:TestNode) RETURN n;");  <-------- this one 
System.out.println(rs.fieldNames());

And you could find a lot of examples to use the Result object in ITs, e.g. https://github.com/neo4j/neo4j-java-driver/blob/master/driver/src/test/java/org/neo4j/driver/integration/StatementIT.java

Best,
Zhen

from neo4j-java-driver.

ckramp avatar ckramp commented on June 15, 2024

Hi Zhen,

thank you for taking the time to look into the issue.

To make the issue more clear, I will try to condense it as much as possible.

I have a clean instance of neo4j 3.0.0 and execute the following query to create a sample node:

CREATE (n:TestNode {name:'test'}) RETURN n;

Afterwards I am trying to run this query to get the created node:

MATCH (n:TestNode) RETURN n;

This works flawlessly in the neo4j webinterface.

When using the neo4j-java-driver and calling the fieldNames() function on the Result object now, it returns an empty Iterable.

Driver driver = GraphDatabase.driver( "neo4j://localhost" );    
Session session = driver.session();
Result rs = session.run("MATCH (n:TestNode) RETURN n;");  
System.out.println(rs.fieldNames()); <--- returns '[]'

I would have expected it to return '[n]' instead.

The documentation states the following:

/**
 * Get an ordered sequence of the field names in this result.
 *
 * @return field names
 */
Iterable<String> fieldNames();

From my understanding the Result rs from above should point to the first Record returned by session.run(...) and calling fieldNames() on rs should have the same result as using:

rs.single().fieldNames() <- returns '[n]'

I hope this makes the issue more clear and I am looking forward to your reply.

Kind regards,
Christian

from neo4j-java-driver.

zhenlineo avatar zhenlineo commented on June 15, 2024

Hi Christian,

Thanks a lot for this wonderful explanation. I got this problem now. You are totally correct and your first answer is probably the cause of this bug. We are working on a PR to fix this bug soon.

Thanks a lot again. Please let us know if you have any other problem/suggestion when you are using this driver.

Best,
Zhen

from neo4j-java-driver.

zhenlineo avatar zhenlineo commented on June 15, 2024

#50

from neo4j-java-driver.

ckramp avatar ckramp commented on June 15, 2024

Hello Zhen,

Thank you for your work in providing a fix for this problem.
The issue has been resolved and fieldNames() is working now.

Kind regards,
Christian

from neo4j-java-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.