Neo4jclient query gives me error - neo4jclient

What is wrong with this query
var result = Neo4jController.m_graphClient.Cypher
.Match("(A:" + objWorld.getLabel() + " { Name : {Name} })")
.Create("(A)-[R:" + Rel_World.world_country + "]->(B:" + objcountry.getLabel() + "{ objcountry }")
.WithParams(new
{
Name = objWorld.Name,
objcountry = objcountry
})
.Return((B, R) => new
{
CountryCount = B.Count(),
RelationCount = R.Count()
})
.Results
.Single();
I am getting this error
Message=SyntaxException: Invalid input 'R': expected whitespace, comment or ')' (line 3, column 1)
"RETURN count(B) AS CountryCount, count(R) AS RelationCount"
I am using Neo4jclient to interact with neo4j

Forgot to add a ')' in the query field.

Related

org.neo4j.driver.exceptions.ClientException: Invalid input 'ConfigNode': expected an identifier (line 1, column 86 (offset: 85))

Exception:
org.neo4j.driver.exceptions.ClientException: Invalid input 'ConfigNode': expected an identifier (line 1, column 86 (offset: 85))
"WITH $batch AS document UNWIND document.data AS data FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )"
Cypher Query:
JSON:
{"data":[{"uuid":"4567-c102-47ft-a87786876","name":"address 1"},{"uuid":"6432dd4d-8a43-4471-bbbb-5a9f47dac6f7","name":"address Group 1"},{"uuid":"6511a9ee-a37e-4ead-a71d-dde04394c3cc","name":"address 2"},{"uuid":"1234567-a37e-4ead-a71d-1234567","name":"Security Rule 1"},{"uuid":"PolicyA-a37e-4ead-a71d-PolicyA","name":"PolicyA 2"},{"uuid":"Policy B-a37e-4ead-a71d-PolicyB","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-PolicyC","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy1","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy2","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy3","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy4","name":"PolicyA 2"},{"uuid":"PolicyA-a37e-4ead-a71d-Policy5","name":"PolicyA 2"}]}
Query:
String q3 = "WITH $batch AS document " +
"UNWIND document.data AS data " +
"FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )";
Map<String, Object> parameters = new HashMap<String, Object>();
Gson gson = new Gson();
String json = "{\"data\":"+ gson.toJson(nodes) +"}";
try (Session session = getWriteTenantDBSession(driver, tenantId)) {
session.run(q3, parameters);
}catch(Exception e){
// log.error("Unable to create node due to exception {}", e.fillInStackTrace());
e.printStackTrace();
throw new UnableToSupportOpException("Unable to create node due to exception:"+e.getLocalizedMessage());
}
You don't need the quotes for ConfigNode. Also, you don't need the UNWIND because you are already doing a FOREACH loop. UNWIND will do a loop on each item in data (json)
NEW:
String q3 = "WITH $batch AS document " +
"FOREACH (node in data| CREATE(m:ConfigNode) SET m = node )";
OLD:
String q3 = "WITH $batch AS document " +
"UNWIND document.data AS data " +
"FOREACH (node in data| CREATE(m:'ConfigNode') SET m = node )";

Construct queries with a condition

I am using Spring Data Neo4j and I have a repository like this:
public interface MyNeo4jRepository extends Neo4jRepository<Object, Long> {
#Query("with ['X', 'Y','Z'] as list_labels, "
+ "$appsFilter as appsList\n "
+ "MATCH (apps:) where apps.n IN appsList "
+ "MATCH (a)<-[:event]-(nodes) "
+ "WHERE any(x IN labels(nodes) WHERE x IN list_labels) "
+ "CALL apoc.path.expandConfig(nodes, { "
+ "relationshipFilter: 'R1|R2>',"
+ "labelFilter: '-l1|>l2',"
+ "maxLevel: 6,"
+ "endNodes: [apps],"
+ "uniqueness: 'NODE_PATH'}) YIELD path "
+ "unwind nodes(path) as n "
...
}
I want to create this query using conditions like this:
#Query("with ['X', 'Y','Z'] as list_labels, "
+ "$appsFilter as appsList\n "
+ "MATCH (apps:) where apps.n IN appsList "
+ "MATCH (a)<-[:event]-(nodes) "
+ "WHERE any(x IN labels(nodes) WHERE x IN list_labels) "
if (condition) + "WHERE ...." else + ""
+ "CALL apoc.path.expandConfig(nodes, { "
...
Is there a way to do it in the Neo4j query or do I have to do it with Spring composable repositories?
I think what you are looking for is the CASE construct
'WHERE ....'
+
CASE
WHEN condition1 THEN 'cypherFragement1'
WHEN condition2 THEN 'cypherFragement2'
ELSE 'cypherFragementElse'
END
+
.....
Maybe you can rewrite your entire cypher via apoc.do.when or apoc.do.case functions, which provide conditional judgment.

How can I perfom an update with jena fuseki?

I've wrote this query that normally works
String query2 = "PREFIX publ: <http://www.ps7-wia2.com/publications/>\n" +
"PREFIX pub: <http://www.ps7-wia2.com/publications#>" +
"DELETE { publ: " + id + " pub:like ?o }\n" +
"INSERT { publ: " + id + " pub:like " + nbLikes + " }\n" +
"WHERE {publ:" + id + " pub:like ?o .}\n";
RDFConnection conn2 = RDFConnectionFactory.connect(DATABASE);
QueryExecution qExec2 = conn2.query(query2) ;
conn2.close();
qExec2.close();
And when I execute I encounter this error
org.apache.jena.query.QueryParseException: Encountered " "delete" "DELETE "" at line 2, column 52.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"json" ...
"describe" ...
"construct" ...
"ask" ...
```
In SPARQL, query and update are parsed separately; they are separate languages which use many of the same elements but have different syntax for their functionality ("SELECT" vs "INSERT" etc).
Use update(...).

QueryBuilder update with concat

I have the following raw SQL query:
UPDATE mySock s1
LEFT JOIN mySock s2
ON s1.parentId = s2.id
SET
s1.status = 1
s1.mylevel = (s2.mylevel + 1),
s1.parentString = CONCAT(s2.parentString, ':' CONCT(s1.id as char))
WHERE
s1.zz = 0;
and in create in Symfony 3.2
public function updateParentNew($idParent)
{
return $this->createQueryBuilder('s1')
->update('MyBundle:Stock', 's1')
->leftJoin(''MyBundle:Stock', 's2', 'WITH', 's2.id = s1.parentId')
->set('s1.zz', 1)
->set('s1.leveltask', 's2.leveltask + 1')
->set('s1.parentString', '?par2_string')
->where('s1.zz = 0')
->andWhere('s1.parentId = ?par1')
->setParameter('par1', $idParent)
->setParameter('par2_string', s2.parentString + ':' + (string)s1.id)
->getQuery()
->getSingleScalarResult();
}
It doesn't work. What is the way to Concat values (string and number)?
I would try something like this:
public function updateParentNew($idParent)
{
$qb = $this->createQueryBuilder('s1')
->update('MyBundle:Stock', 's1')
->leftJoin('MyBundle:Stock', 's2', 'WITH', 's2.id = s1.parentId')
;
$qb->set('s1.zz', 1)
->set('s1.leveltask', $qb->expr()->sum('s2.leveltask', 1))
->set('s1.parentString',
$qb->expr()->concat(
$qb->expr()->literal('s2.parentString'),
$qb->expr()->concat(':', $qb->expr()->literal('s1.id'))
))
->where('s1.zz = 0')
->andWhere('s1.parentId = :par1')
->setParameter('par1', $idParent)
->getQuery()
->getSingleScalarResult()
;
return $qb;
}

How do I append an int value into a string array in Swift?

I'm learning Swift now (with basic programming know-how), and I'm making a String array containing a deck of 52 cards via a for loop, but I'm not sure how to append a value with an int and string values.
I know using \(int) converts an int to a string, but it doesn't seem to work when appending to an array. My code, including the error messages are below:
var suits = ["Spades", "Hearts", "Clubs", "Diamonds"]
var deck:[String] = []
for s in suits
{
deck.append("Ace of " + s)
deck.append("King of " + s)
deck.append("Queen of " + s)
deck.append("Jack of " + s)
for (var i = 2; i < 11; ++i)
{
deck.append(\(i) + " of " + s)
//error message: "Expected ',' separator"
//error message: "Invalid character in source file"
}
}
You need to have your (i) in quotes in order for it to be converted to a String.
deck.append("\(i)" + " of " + s)
You could also do this:
var value = String(i)
deck.append(value + " of " + s)

Resources