I'm trying to send query to my Mongo database depending on a variable producted in my R code.
Unfortunately, Mongo query needs double quotes and the function "paste" in R doesn't support it.
Here my variable is equal to "test01" but it will change at each iteration.
I tried to build a great character chain named "req" thanks to some "paste" functions with returns:
req
> "'{\"id\":\"test01\"}'"
cat(req)
> '{"id":"test01"}'
Which seems to be as a query but when I try :
connection_db$count(jsonlite::toJSON(req))
It returns [0] whereas if if try :
connection_db$count('{"id":"test01"}')
It returns [1].
Can you help me please?
Related
In my ML db, we have documents with distributor code like 'DIST:5012' (DIST:XXXX) XXXX is a four-digit number.
currently, in my TDE, the below code works well.
However instead of concat all the raw distributor codes, I want to simply concat the number part only. I used the fn:substring-after XQuery function. However, it won't work. It won't show that distributorCode column in the SQL View anymore. (Below code does not work.)
What is wrong? How to fix that?
Both fn:substring-after and fn:string-join is in TDE Dialect page.
https://docs.marklogic.com/9.0/guide/app-dev/TDE#id_99178
substring-after() expects a single string as input, not a sequence of strings.
To demonstrate, this will not work:
let $dist := ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
This will:
for $dist in ("DIST:5012", "DIST:5013")
return substring-after($dist, "DIST:")
I need to double check what XPath expressions will work in a DTE, you might be able to change it to apply the substring-after() function in the last step:
fn:string-join( distributors/distributor/urn/substring-after(., 'DIST:'), ';')
I'm trying to run a custom function over a list of items which are stored in an array and I'm looking at the range operator in KQL.
Here is my code : `
let myfunction = (lot:string){T|where id=lot};
union( range x from 1 to 50 step 1
|invoke myfunction(strcat("test-",x))
)
`
but I'm getting failed message that cant resolve scalar named 'x'. What I would like to do is repeat myfunction for 50 times and then use union to merge the results of each iteration. If this can't be done by using range operator, is there an alternative way to achieve the results that I'm looking for?
Thank you,
The way you chose will not work because the input to the "invoke" operator is a tabular source and the function returns a tabular output.
One way to achieve this in Kusto is by using the python plugin.
I will like to pass variable within the cypher query in Shiny R.
The R version that I am using is R version 3.3.3 (2017-03-06) and neo4j-community-3.1.1
There is no issue retrieving the data from neo4j DB via below cypher query in Shiny R
query = "MATCH p=()-[:Month]->()-[:Day]->(d:Day)-[Hour]->(h:Hour)<-[timerel:CONNECTED_ON]-(n:IP)-[:CONNECT_TO]->(k:IP) WHERE h.hour=\"9\" and d.day=\"2\" RETURN p limit 25
cypher(graph, query)
However, when I attempt to pass variable into the cypher query based on what I have read in http://neo4j.com/docs/developer-manual/current/cypher/syntax/parameters/, I encountered this error message:
"Warning: Error in : Client error: (400) Bad Request
Neo.ClientError.Statement.ParameterMissing
Expected a parameter named day"
day = "2"
hour = "9"
query = "MATCH p=()-[:Month]->()-[:Day]->(d:Day)-[Hour]->(h:Hour)<-[timerel:CONNECTED_ON]-(n:IP)-[:CONNECT_TO]->(k:IP) WHERE h.hour=$hour and d.day=$day RETURN p limit 25
I have also tried the following:
1: Putting {$hour}
day = "2"
hour = "9"
query = "MATCH p=()-[:Month]->()-[:Day]->(d:Day)-[Hour]->(h:Hour)<-[timerel:CONNECTED_ON]-(n:IP)-[:CONNECT_TO]->(k:IP) WHERE h.hour={$hour} and d.day={$day} RETURN p limit 25
2: Putting {hour}
All the above does not allow me to pass variable into the cypher query statement.
Appreciate it if anyone can guide me on that. Thank you.
To answer my own question for the sharing purpose, below 2 urls serve to address the method on how to pass variable in using Rneo4j
https://rdrr.io/cran/RNeo4j/man/cypher.html
https://github.com/nicolewhite/RNeo4j/blob/master/man/cypher.Rd
The query argument of cypher() is expecting a string. Use glue to compose the string.
I am working with RElasticSearch package in R. I am able to connect to the proper index in ElasticSearch. Suppose my index contains two fields like id and name. Two of my R variables,say rid and rname contains the value i want to search. How should i use the searchES method to accomplish this? I have tried using like:
searchES(server=es.index,query="id":rid & "name":rname)
but it keeps throwing an error! Can someone please help me out?
You need to correctly build your as a character value in order for this to work. In order to concatenate strings in R, you should use paste(). For example
searchES(server=es.index,query=paste0("id:", rid, " AND name:", rname))
Is it possible to get a list of declared variables with a VimL (aka VimScript) expression? I'd like to get the same set of values that will be presented for a command using -complete=expression. The goal is to augment that list for use in a user-defined command completion function.
You can use g: as a dictionary that holds all global variables, so:
let globals = keys(g:)
will give you all the names. The same applies to the other scopes: b:, s:, w:, etc. See :help internal-variables for the complete list.
You can get something similar using keys of g:, b:, t:, w: and v: dictionaries, but beware of the following facts:
There is no equivalent to this dictionaries if you want to complete options.
Some variables like count (but not g:count or l:count), b:changedtick and, maybe, others are not present in this dictionaries.
Some vim hacker may add key ### to dictionary g:, but it won't make expression g:### valid variable name (but adding 000 there will). Though g:["###"] will be a valid expression.