I have a dictionary (json) that looks like this
[{"foo":"fooval1a",type:"xfs"},{"foo":"fooval2a",type:"ext2"},{"foo":"fooval3a",type:"nfs"},{"foo":"fooval4a",type:"ntfs"}]
I would like to check in this list, when "foo" is value "fooval3a" it should be "nfs". I have like 20 of these sort of tests.
Is there a way to do this easily with robotframework?
You miss quote on "type"
${listOfDict} Evaluate [{"foo":"fooval1a","type":"xfs"},{"foo":"fooval2a","type":"ext2"},{"foo":"fooval3a","type":"nfs"},{"foo":"fooval4a","type":"ntfs"}]
FOR ${dict} IN #{listOfDict}
IF "${dict}[foo]"=="fooval3a"
Should Be Equal ${dict}[type] nfs
END
END
Related
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?
For example I have the following table named "example":
name | age | address
'abc' | 12 | {'street':'1', 'city':'kl', 'country':'malaysia'}
'cab' | 15 | {'street':'5', 'city':'jakarta', 'country':'indonesia'}
In Spark I can do this:
scala> val test = sc.cassandraTable ("test","example")
and this:
scala> test.first.getString
and this:
scala> test.first.getMapString, String
which gives me all the fields of the address in the form of a map
Question 1: But how do I use the "get" to access "city" information?
Question 2: Is there a way to falatten the entire table?
Question 3: how do I go about counting number of rows where "city" = "kl"?
Thanks
Question 3 : How do we count the number of rows where city == something
I'll answer 3 first because this may provide you an easier way to work with the data. Something like
sc.cassandraTable[(String,Map[String,String],Int)]("test","example")
.filter( _._2.getOrElse("city","NoCity") == "kl" )
.count
First, I use the type parameter [(String,Map[String,String],Int)] on my cassandraTable call to transform the rows into tuples. This gives me easy access to the Map without any casting. (The order is just how it appears when I made the table in my test environment you may have to change the ordering)
Second I say I would like to filter based on the _._2 which is shorthand for the second element of the incoming tuple. getOrElse returns the value for the key "city" if the key exists and "NoCity" otherwise. The final equivalency checks what city it is.
Finally, I call count to find out the number of entries in the city.
1 How do we access the map?
So the answer to 2 is that once you have a Map, you can call get("key") or getOrElse("key") or any of the standard Scala operations to get a value out of the map.
2 How to flatten the entire table.
Depending on what you mean by "flatten" this can be a variety of things. For example if you want to return the entire table as an array to the driver (Not recommended since your RDD should be very big in production.) You can call collect
If you want to flatten the elements of your map into a tuple you can always do something like calling toSeq and you will end up with a list of (key,value) tuples. Feel free to ask another question if I haven't answered what you want with "flattening."
How do you use indirect references in R? More specifically, in the following simple read statement, I would like to be able to use a variable name to read inputFile into data table myTable.
myTable <- read.csv(inputFile, sep=",", header=T)
Instead of the above, I want to define
refToMyTable <- "myTable"
Then, how can I use refToMyTable instead of myTable to read inputFile into myTable?
Thanks for the help.
R doesn't really have references like that, but you can use strings to retrieve/create variables of that name.
But first let me say this is generally not a good practice. If you're looking to do this type of thing, it's generally a sign that you're not doing it "the R way.'
Nevertheless
assign(refToMyTable, read.csv(inputFile, sep=",", header=T))
Should to the trick. And the complement to assign is get to retrieve a variable's value using it's name.
I think you mean something like the following:
reftomytable='~/Documents/myfile.csv'
myTable=read.csv(reftomytable)
Perhaps assign as mentioned by MrFlick.
When you want the contents of the object named "myTable" you would use get:
get("myTable")
get(refToMyTable) # since get will evaluate its argument
(It would be better to assign results of multiple such dataframes to a ist object or a Reference Class.)
If you wanted a language-name object you would use as.name:
as.name("myTable")
# myTable .... is printed at the console; note no quotes
str(as.name("myTable"))
#symbol myTable
It will eventually be part of a larger script so it needs to be shell scripted. A simple task in other languages, but I'm having trouble accomplishing it in shell. Basically I have a string and I want to insert a "." at all possible indices within the string. The output can be on newlined or separated by spaces. Can anyone help?
Example:
input: "abcd"
output: ".abcd
a.bcd
ab.cd
abc.d
abcd."
OR
output: ".abcd a.bcd ab.cd abc.d abcd."
A simple for loop would do:
input=abcd
for ((i=0; i<${#input}+1; i++))
do
echo ${input::$i}.${input:$i}
done
This just slices up the string at each index and inserts a .. You can change the echo to something else like appending to an array if you want to store them instead ouf output them, of course.
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.