Neo4j shell import throws - Unknown command 'foreach' - neo4j

Tried with Neo4j version 2.1.7 / 2.2.0
CQL contains =>
FOREACH (name in ["Hindu","Muslim","Christian","Jain"] | CREATE (:Religion {title:name}) );
I'm unable to import this using neo4j shell. err thrown : Unknown command 'foreach'.
I'm generating the CQL file through PHP.

Seems like neo4j-shell is not aware that a valid cypher statement can start with FOREACH. A simple workaround is to begin with a WITH:
with ["Hindu","Muslim","Christian","Jain"] as r
foreach (name in r|create (:Religion{title:name}));

Related

Neo4j Desktop neosemantics RPC failure invoking rdf.preview.fetch - NoSuchMethodError JacksonFeatureSet JSONParser getReadCapabilities

I'm attempting to extract RDF from Wikidata into a Neo4j graph through the Neo4j Desktop with APOC and Neosemantics plugins on a Mac and keep getting Neo.ClientError.Procedure.ProcedureCallFailed
`
Failed to invoke procedure `n10s.rdf.preview.fetch`: Caused by: java.lang.NoSuchMethodError: 'com.fasterxml.jackson.core.util.JacksonFeatureSet com.fasterxml.jackson.core.JsonParser.getReadCapabilities()'
`
Trying to run the following code:
`
WITH 'PREFIX neo: <neo4j://wiki#>
CONSTRUCT {
?descendant a neo:Entity .
?descendant neo:entityName ?descendantLabel .
?descendant neo:entityGender ?gender .
}
WHERE
{
VALUES ($ancestor) {(wd:Q317521)}
?ancestor wdt:P40? ?descendant.
?descendant wdt:P21 ?gender .
?descendant rdfs:label ?descendantLabel .
FILTER (LANG(?descendantLabel) = "en") .
}' AS sparql
CALL n10s.rdf.preview.fetch(
"https://query.wikidata.org/sparql?query=" + apoc.text.urlencode(sparql),
"JSON-LD", { headerParams: { Accept: "application/ld+json" } }
)
YIELD nodes, relationships
RETURN nodes, relationships
`
I use Homebrew for just about everything on my Mac and just completed a brew upgrade. I use sdkman for Java and upgraded that as well.
I've tried to rollback to an earlier version of the Desktop as well as other versions of the plugins as well. Here are the various software versions I'm using.
Mac Monterey 12.6
Neo4j Desktop 1.5.2
APOC 4.4.0.6
Neosemantics 4.4.0.1
openjdk 17.0.5
Python 3.10.8
Any suggestions? Perhaps different versions of the JDK to get at the Jackson JSON Parser?

Error creating a keyspace with dataframes in spark cassandra

I'm trying to connect spark to cassandra and then I make a query to the keyspace and table from flask.
The problem is that when I run the web application I get an error saying that the keyspace in not created.
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Keyspace MyKeyspace does not exist"
In spark I run the following commands:
val flightRecommendations = finalPredictions.writeStream.foreachBatch {
(batchDF: DataFrame, batchId: Long) =>
batchDF
.write
.cassandraFormat("MytableName", "MyKeyspace")
.option("cluster", "cassandra_cluster")
.mode("append")
.save
}.start()
My question is whether the above code automatically generates the keyspace and the table.
I think it could also be a problem of connection because I'm working in docker and the setting I put is this:
spark.setCassandraConf("cassandra_cluster", CassandraConnectorConf.ConnectionHostParam.option("cassandra"))
Also in the spark-submit command I put the following two configurations:
--conf spark.cassandra.connection.host=cassandra \
--conf spark.sql.extensions=com.datastax.spark.connector.CassandraSparkExtensions \
It's weird because the spark-submit doesn't give errors but the keyspace is not created.
Yes, that's possible with since Spark Cassandra Connector 2.5.0. There is a new function createCassandraTableEx that allows to create a new table based on the Dataframe schema and it has an option to handle the cases where table does already exist (in addition to other things, like, control the sorting of the clustering columns, table options, etc.) - before 2.5.0 there was the createCassandraTable function, but it thrown exception if table already exists.
Here is example from the blog post that announces 2.5.0 release. For dataframe with following structure:
root
|-- id: integer (nullable = false)
|-- c: integer (nullable = false)
|-- t: string (nullable = true)
it's possible to create a new table using following code:
import com.datastax.spark.connector.cql.ClusteringColumn
import org.apache.spark.sql.cassandra._
import com.datastax.spark.connector._
data.createCassandraTableEx("test", "test_new", Seq("id"),
Seq(("c", ClusteringColumn.Descending)),
ifNotExists = true, tableOptions = Map("gc_grace_seconds" -> "1000"))
And you don't need to use foreachBatch with that version - it was required only before 2.5.0 - in new version you can just write:
val query = streamingCountsDF.writeStream
.outputMode(OutputMode.Update)
.option("checkpointLocation", ".../checkpoint")
.option("table", "tablename")
.("keyspace", "ksname")
.start()
And with Spark 3.x & SCC 3.x you can create keyspaces & tables in Cassandra using the Spark SQL - see documentation for more details.

Failed to read from defunct connection (Jupyter notebook, python driver )

I try to import data into a Neo4j VM in Azure.
This code works:
def create_article(tx):
tx.run("CREATE (a:ARTICLE)")
session.read_transaction(create_article)
But this code doesn't work:
def create_node_article(tx, id, title, label):
tx.run("CREATE (a:ARTICLE {id:$id, title:$title, label:$label})", id=id, title=title, label=label)
for index, row in df_article_ids.iterrows():
session.read_transaction(create_node_article, row['id'], row['cleaned_best_title'], row['label'])
I have the error:
Transaction failed and will be retried in 1.0608892687544587s (Failed
to read from defunct connection Address(host='IP', port=7687)
(Address(host='IP', port=7687)))
I don't know what I have to change or check. I also tried Neo4j Desktop and I have the same error.
Neo4j version: 4.1.3

Connecting to MSSQL server in Spark shell and running a stored procedure

How can I connect to a sql server using jdbc in spark-shell and then query the database using a stored procedure?
I have seen this code:
val url =
"jdbc:mysql://yourIP:yourPort/test?
user=yourUsername; password=yourPassword"
val df = sqlContext
.read
.format("jdbc")
.option("url", url)
.option("dbtable", "people")
.load()
But I need to run a stored procedure.
When I use exec command for the dbtable option above, it gives me this error:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near
the keyword 'exec'.

Error when using export-graphml in Neo4j 2.2

I am trying to use the export-graphml function in Neo4j 2.2. I have downloaded neo4j shell tools and extract it into the lib directory. I am able to export the entire database as a graphml file. However, if I try to export a subset using a query, I receive the following error:
Error occurred in server thread; nested exception is:
java.lang.NoSuchMethodError: org.neo4j.cypher.export.CypherResultSubGraph.from(Lorg/neo4j/cypher/javacompat/ExecutionResult;Lorg/neo4j/graphdb/GraphDatabaseService;Z)Lorg/neo4j/cypher/export/SubGraph;
The statement I used is:
export-graphml -o /path/to/file/out.graphml match (n:Person)-[r:RELATIONSHIP]-() WHERE n.id = 12345 return n, r
I have tried different variations with the different options (-r, -t) and none work

Resources