c# - Neo4jClient Cypher query collect statement with multiple values -
i'm trying convert query cypher use neo4jclient api in c#
here cypher
start server=node:node_auto_index(serverid='sho2k3ms49') match server-[:is_server_type]->type, appenv-[:has_server]->server, app-[:has_env]->appenv return server.serverid, collect([ appenv.environmenttypeid, appenv.appenvid, app.appid, app.appname ]) ;
the query returns 1 line per server , collects applications on server.
the .collectas api far can see allows single values.
an idea how .net api?
edit
i've tried query
_connectedclient .cypher .start(new {server = node.byindexlookup("node_auto_index", "serverid", "sho2k3ms49") }) .match("server-[:is_server_type]->type", "appenv-[:has_server]->server", "app-[:has_env]->appenv") .return((server, appenv, app) => new { servername = return.as<string>("server.serverid"), aa = return.as<dynamic> ("collect([appenv.environmenttypeid,appenv.appenvid,app.appid,app.appname])") }) .results;
and received result.
stacktrace
at neo4jclient.serialization.cypherjsondeserializer`1.deserialize(string content) @ neo4jclient.graphclient.<>c__displayclass1e`1.<neo4jclient.irawgraphclient.executegetcypherresultsasync>b__1d(task`1 responsetask) @ system.threading.tasks.continuationresulttaskfromresulttask`2.innerinvoke() @ system.threading.tasks.task.execute()
innerexception
accessed jarray values invalid key value: "data". array position index expected
message -- removed boilerplate text brevity
neo4jclient encountered exception while deserializing response server. bug in neo4jclient. include full type definition of <>f__anonymoustype1`2[[system.string, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089],[system.object, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]]. include raw json, sensitive values replaced non-sensitive equivalents: {"columns":["servername","aa"],"data":[["sho2k3ms49",[["prd","matt.prd","matt","matt"],["prd","arcserv.prd","arcserv","arcserv"],["prd","active directory _windows server networking_.prd","active directory _windows server networking_","active directory (windows server networking)"]]]]} parameter name: content
it's because results bring collect
statement strings no defining columns. json.net can't infer columns (and can't use as
it), strings like:
"[\r\n"envtype1",\r\n"appenvid1",\r\n"app2",\r\n"app 2"\r\n]"
which can using following query:
_connectedclient .cypher .start(new {server = node.byindexlookup("node_auto_index", "serverid", "sho2k3ms49") }) .match("server-[:is_server_type]->type", "appenv-[:has_server]->server", "app-[:has_env]->appenv") .return((server, appenv, app) => new { servername = return.as<string>("server.serverid"), aa = return.as<ienumerable<string>>("collect([appenv.environmenttypeid,appenv.appenvid,app.appid,app.appname])") }) .results;
i've changed return type aa
property ienumerable<string>
.
another route use groupby
after getting data:
var query2 = graphclient .cypher .start(new { server = new nodereference(1) }) .match("server-[:is_server_type]->type", "appenv-[:has_server]->server", "app-[:has_env]->appenv") .return((server, appenv, app) => new { serverid = return.as<string>("server.serverid"), environmenttypeid = return.as<string>("appenv.environmenttypeid"), appenvid = return.as<string>("appenv.appenvid"), appid = return.as<string>("app.appid"), appname = return.as<string>("app.appname"), }); var results2 = query2.results.groupby(g => g.serverid).tolist();
which think give results in way want them, guess @ issue here whether it's more performant collect
on server, or groupby
on client...
Comments
Post a Comment