Importing data from one Neo4j server to another server (Copy Entire Subgraph) - import

I want to copy entire subgraph from one server to another server via a cypher in Neo 4j .
I have a Neo 4j on Host 1 and another Neo 4j on Host 2 .
My requirement to copy the graph from Host 1 and insert into Host 2

You can use apoc.bolt.execute procedure to move data from one graph to another graph :
Here is an example moving data from the standard movies graph to another graph called movies888 :
Replace username, password and host with your values
MATCH (n:Person)-[r:ACTED_IN]->(m)
WITH n, r, m
CALL apoc.bolt.execute(
'bolt://<username>:<password>#<host>:7687',
'
MERGE (p:Person {name: $n.name}) SET p = $n
MERGE (m:Movie {title: $m.title}) SET m = $m
MERGE (p)-[r:ACTED_IN]->(m)
SET r = $r
',
{n: n{.*}, m: m{.*}, r: r{.*}}, {databaseName: 'movies888'}
)
YIELD row RETURN count(*)

Related

How does chisel connect to such a port?

I am learning the design of Boomv3.
The A part has a write port. The format is
val write_ports = Flipped(Vec(10, Valid(new RegisterFileWritePort(maxPregSz, registerWidth))))
B has a write port. The format is
val write_ports = Vec(5, Valid(new RegisterFileWritePort(maxPregSz, 4)))
C has a write port. The format is
val write_ports = Vec(5, Valid(new RegisterFileWritePort(maxPregSz, 4)))
I want to connect B and C to A.
When i use
A.write_ports <> B.write_ports
A.write_ports <> C.write_ports
, here will be a failed #: Left and Right are different length Vecs error.
But my original intention is that the length of A is 10. The length of B and C are both 5. This makes them connect.
But what should I do?
With these two bulk connexions, Chisel can't find where to assign B and C 5-sized Vec to B 10-sized Vec.
You should concatenate B and C vec and write one bulk connexion :
A.write_ports <> B.write_ports ++ C.write_ports
I tested it with scatie here.

Databricks, dbutils, get filecount and filesize of all subfolders in Azure Data Lake gen 2 path

I'm coding in a Databricks notebook (pyspark) and trying to get the filecount and filesizes of all subfolders in a specific Azure Data Lake gen2 mount path using dbutils.
I have code for it on a specific folder but I'm stuck on how to write the recursive part...
How about this?
def deep_ls(path: str):
"""List all files in base path recursively."""
for x in dbutils.fs.ls(path):
if x.path[-1] is not '/':
yield x
else:
for y in deep_ls(x.path):
yield y
Credits to
https://forums.databricks.com/questions/18932/listing-all-files-under-an-azure-data-lake-gen2-co.html
https://gist.github.com/Menziess/bfcbea6a309e0990e8c296ce23125059
Get the list of the files from directory,
Print and get the count with the below code.
def get_dir_content(ls_path):
dir_paths = dbutils.fs.ls(ls_path)
subdir_paths = [get_dir_content(p.path) for p in dir_paths if p.isDir() and p.path != ls_path]
flat_subdir_paths = [p for subdir in subdir_paths for p in subdir]
return list(map(lambda p: p.path, dir_paths)) + flat_subdir_paths
paths = get_dir_content('dbfs:/')
or
paths = get_dir_content('abfss://')
Below line prints the file names with path and number of files count at the end.
len([print(p) for p in paths])
if you want only count number of files use the below:
len([p for p in paths])

OrientDB batch commands on unique edges and vertices

Suppose I want to create a set of unique edges and vertices.
create vertex A set etc.
create vertex B set etc.
create edge AB, create edge AC,
And all of these edges and vertices are unique--so some of the commands will likely fail when they are unique.
How do I batch these commands such that I am guaranteed all commands will be run, even when some commands fail?
I tried your case, I have a Vertex class with a name property (unique index), you can execute batch commands in different ways:
Studio
begin
LET a = create vertex User set name = 'John'
LET b = create vertex User set name = 'Jane'
LET c = create edge FriendOf from $a to $b
commit retry 100
return $c
Java API
OrientGraph g=new OrientGraph(currentPath);
String cmd = "begin\n";
cmd += "let $user2 = UPDATE User SET user_id = 'userX' UPSERT RETURN AFTER #rid WHERE user_id = 'userX'\n";
cmd += "let $service = UPDATE Service SET service = 'serviceX' UPSERT RETURN AFTER #rid WHERE service = 'serviceX'\n";
cmd += "CREATE edge link FROM $user2 TO $service\n";
cmd += "commit";
g.command(new OCommandScript("sql", cmd)).execute();
Console
create a .txt file with your code like this:
connect remote:localhost/stack49801389 root root
begin
create vertex User set name = 'John'
create vertex User set name = 'Jane'
create edge FriendOf from $a to $b
commit retry 100
return $c
and then run it by console
For more information you can take a look at this link
Hope it helps
Regards

Extending Stargazer to multiwaycov

I'm using stargazer to create regression outputs for my bachelor thesis. Due to the structure of my data I have to use clustered models (code below). I'm using the vcovclust command from the multiwaycov package, which works perfectly. However, stargazer does not support it. Do you know another way to create outputs as nice as stargazer does? Or do you know an other package/command to cluster the models, which is suppported by stargazer?
model1.1.2 <- lm(leaflet ~ partisan + as.factor(gender) + age + as.factor(education) + meaning + as.factor(polintrest), data = voxit)
summary(model1.1.2)
#clustering
vcov_clust1.1.2 <- cluster.vcov(model1.1.2, cbind(voxit$id, voxit$projetx))
coeftest(model1.1.2, vcov_clust1.1.2)
You can supply the adjusted p- and se-values to stargazer manually.
# model1 and model2 are both objects returned from coeftest()
# Capture them in an object and extract the ses (2nd column) and ps (4th column) in a list
ses <- list(model1[,2], model2[,2])
ps <- list(model1[,4], model2[,4])
# you can then run your normal stargazer command and supply
# the se- and p-values manually to the stargazer function
stargazer(model1, model2, type = "text", se = ses, p = ps, p.auto = F)
Hope this helps!

Erlang - Mnesia - equivalent to "select distinct id from Table"

Hi is there a possibility to make a distinct select request to mnesia ?
I could copy the content of one table to ets and since ets is a hash table it could work. But i thought there is maybe a more elegant solution to this problem.
Thank you.
I'm not sure if this is what you had in mind, but you could use QLC's {unique, true} option (See QLC documentation for more info).
I created a mnesia table, called test, with bag semantics. Each row consists of the table name, a Key and a Value, so my rows looked like:
1. test, 1, 1
2. test, 2, 1
3. test, 2, 2
4. test, 3, 1
5. test, 3, 2
6. test, 3, 3
... etc.
Then this simple module illustrates my approach. Notice that you have to include the qlc library and that, in my example, I am selecting distinct Keys.
-module(test).
-export([select_distinct/0]).
-include_lib("stdlib/include/qlc.hrl").
select_distinct()->
QH = qlc:q( [K || {_TName, K, _V} <- mnesia:table(test)], {unique, true}),
F = fun() -> qlc:eval(QH) end,
{atomic, Result} = mnesia:transaction(F),
Result.
Compiling and running
> c("/home/jim/test", [{outdir, "/home/jim/"}]).
> test:select_distinct().
> [4,1,2,3,5]
If you wanted sorted output then use the following version of the QH = ... line above
QH = qlc:sort(qlc:q( [K || {_TName, K, _V} <- mnesia:table(test)], {unique, true})),
If you wanted to select distinct values, the following would work:
QH = qlc:sort(qlc:q( [V || {_TName, _K, V} <- mnesia:table(test)], {unique, true})),
Again, the code is just to illustrate an approach
For keys you can get a list of unique keys using:
mnesia:all_keys(Table).
From my tests, for bags it yields a list of unique keys.