Skip to content

Instantly share code, notes, and snippets.

@mastoj
Last active January 27, 2016 15:16
Show Gist options
  • Save mastoj/83453de470eca662ded5 to your computer and use it in GitHub Desktop.
Save mastoj/83453de470eca662ded5 to your computer and use it in GitHub Desktop.
Unwind sample
System.Threading.Tasks.TaskCanceledException: {"A task was canceled."}
at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypher(CypherQuery query) in D:\temp\8815004\Neo4jClient\GraphClient.cs:line 1053
at Neo4jClient.Cypher.CypherFluentQuery.ExecuteWithoutResults() in D:\temp\8815004\Neo4jClient\Cypher\CypherFluentQuery.cs:line 388
at [email protected](FSharpList`1 data) in C:\dev\git\Sfag\src\Sfag.GraphView\WriteToNeo4j.fs:line 37
at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc`2 f, FSharpList`1 x)
at Microsoft.FSharp.Collections.ListModule.Iterate[T](FSharpFunc`2 action, FSharpList`1 list)
at WriteToNeo4j.mergeNodes[T](GraphClient client, NodeMetaData nodeMeta, IEnumerable`1 nodes) in C:\dev\git\Sfag\src\Sfag.GraphView\WriteToNeo4j.fs:line 33
at [email protected](IEnumerable`1 nodes) in C:\dev\git\Sfag\src\Sfag.GraphView\WriteToNeo4j.fs:line 107
at IndexingImpl.saveState(GraphClient client, IndexingState state) in C:\dev\git\Sfag\src\Sfag.GraphView\IndexingImpl.fs:line 233
at IndexingImpl.reindex(GraphClient client, IndexingStateLookup lookUps) in C:\dev\git\Sfag\src\Sfag.GraphView\IndexingImpl.fs:line 272
at [email protected](Unit unitVar) in C:\dev\git\Sfag\src\Sfag.GraphView\GraphIndexing.fs:line 63
at [email protected](AsyncParams`1 args)
[<CLIMutable>]
type Foretak =
{
Id: Guid
Navn: string
EnhetNummer: string
FTNummer: int
FTNummerString: string
HistoriskeNavn: System.Collections.Generic.List<string>
StatusId: EnhetStatusVerdi
StatusNavn: string
AktivStatus: bool
Telefonnummer: string
Telefax: string
Epost: string
SistEndret: DateTime
EndretAv: string
Fjernet: bool
}
let batchesOf size lst =
let rec inner input cnt batch acc =
match input with
| [] ->
if List.isEmpty batch then acc else (batch |> List.rev)::acc
|> List.rev
| x::xs when cnt < size ->
inner xs (cnt+1) (x::batch) acc
| x::xs ->
let acc' = (List.rev (x::batch))::acc
inner xs 0 [] acc'
inner lst 0 [] []
let mergeNodes<'T> (client:GraphClient) nodeMeta (nodes: 'T seq) =
let tagsStr = nodeMeta.Tags |> tagsToStr
nodes
|> Seq.toList
|> batchesOf 10000
|> List.iter (fun data ->
client.Cypher
.Unwind(data, "node")
.Merge(sprintf "(n:%s {%s: node.%s})" tagsStr nodeMeta.IdPropName nodeMeta.IdPropName)
.OnCreate()
.Set("n = node")
.OnMatch()
.Set("n = node")
.ExecuteWithoutResults()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment