How to create a RethinkDB data initialization script - database

I'm trying to create a simple script that I can paste into the RethinkDB data explorer to initialize a database.
I can insert records fine with something like this:
r.db('testdb').table('cars').insert([{ "model" : Honda }])
But how can that be followed by a second insert into a related table like:
r.db('testdb').table('engines').insert([{ "cars_id" : <what goes here> }])
I could imagine writing some javascript to extract the newly created id's, but it doesn't appear that the data explorer supports things like variables.
Ideally there would be a way to write a large script that would work directly in data explorer for when needed for convenience.

The data explorer can take multiple queries separated by a semi colon.
Note that queries will be sequentially executed, and only the result for the last query will be returned.
The data explorer supports some javascript to some extent, the requirements (as far as I know) are:
the last query must be a ReQL query
Any instructions must ends with a semi colon (except the last one)
That being said, you cannot use the result of the first query in the second query using JavaScript (you don't get access to the result). You can however nest queries (or chain with do), something like this should work I think:
r.db('testdb').table('cars').insert([{ "model" : Honda }]).do(function(result) {
r.db('testdb').table('engines').insert([{ "cars_id" : <you can use the result of the insert here> }])
})

Related

Apache Tinkerpop Gremlin Returns Query Results using Select Values As

I have this query that it is working as expected for me.
g.V().or(hasLabel("poi"),hasLabel("business")).as("dest")
.outE().inV().hasLabel("region").as("reg")
.select("dest").values("name").as("dest_name")
.select("dest").values("budget").as("dest_budget")
.select("reg").values("name").as("reg_name")
.select("reg_name","dest_name","dest_budget")
This query yields this result.
As I have expected. However I need to retrieve more properties from the "destination" I need to retrieve more 10 properties. This will me into something like this
g.V().or(hasLabel("poi"),hasLabel("business")).as("dest")
.outE().inV().hasLabel("region").as("reg")
.select("dest").values("name").as("dest_name")
.select("dest").values("budget").as("dest_budget")
.select("dest").values("property3").as("property3")
.select("dest").values("property4").as("property4")
//insert more queries like from the above
.select("reg").values("name").as("reg_name")
.select("reg_name","dest_name","dest_budget","property3","property4")
The query will grow long eventually which I am trying to avoid since I need to select values as well from the region as well. So My initial thought was to use select to select multiple values and label them each with an alias like this
g.V().
or(hasLabel("poi"),hasLabel("business"))
.as("destination")
.outE().inV().as("region")
.select("destination").values("name","budget").as("dest_name","dest_budget")
.select("region").values("name").as("reg_name")
.select("dest_name","reg_name","dest_budget")
However I was surprised with this result. Which I was not expecting.
To my understanding the names in values will be mapped to each values passed in the as step. Am I wrong?
Is there anyway for me to retrieve the result from the first screenshot without writing a long query?
The as() labels the step, not the values within that step. So by doing:
.select("destination").values("name","budget").as("dest_name","dest_budget")
you're just naming the values() step twice. I think that you can drastically simplify this traversal for what you want to get as the result though and it doesn't involve stringing together a lot of select() steps:
g.V().or(hasLabel("poi"),hasLabel("business")).
project('dest_name','dest_budget','reg_name').
by('name').
by('budget').
by(out().hasLabel("region").values('name').fold())
You will get a slightly different structure in that "reg_name" will be a list of all the region names rather than having a flattened structure, but you could unroll that I imagine if needed.

Microsoft word Database quick part - How to use a mergefield as a filter for the database query

I am using mail merge to input data from an excel sheet. Everthing works great and I can access my variables using «MyMergefield»
Now I need for each letter generated to look into another excel file and do a query that will take the «MyMergefield» as a query filter SELECT FROM x WHERE field1 = «MyMergefield»
The way I am proceeding is "inserting a quick part" => "Field" in my word document.
In the quickpart dialog, I choose "DataBase", then I choose my excel file.
once the data source is chosen, There an option to change the request parameters, I click on it and I get the filter configuration popup where I can choose the field (from the excel sheet), the operator ("equals" in this case). Then there's the compare with field. In my case its not as simple as comparing to as string. Its comparing to a mail merge field.
I tried the following syntax:
«Myfield»
MERGEFIELD Myfield
MERGEFIELD "Myfield"
{MergeField Myfield}
{ MERGEFIELD Myfield}
None worked, it complained that it did not find any match so it did not insert the database (Of course it will not find any match to the syntax if I don't run mail merge)
I did look directly in the openxml file of an existing example (because I can't edit existing quickpart - Correct me if Im wrong) and the database query looked like:
FROM `Candidates$` WHERE ((`column` = '</w:instrText>
...
<w:instrText xml:space="preserve"> MERGEFIELD Myfield</w:instrText>
</w:r>
Any ideas? Thank you!

python encoding characters in jinja2

It's a similar one with one of my other questions. I try to solve all the side effects of the first one.
I have stored few non-ascii characters on my database. If I make few "encoding-decoding" stuffs, I managed to work with the database queries. But I have another problem.
If I use the
self.response.out.write(mystring)
in one of my entities ( looks like this -> u'\u0395\u03c0\u03b9\u03c3\u03c4\u03ae\u03bc\u03b5\u03c2')
I can see it without any problem. But, I have a javascript which create a graph and needs a list with those strings. If I pass the list to the javascript like it is from the database, the javascript doesn't work at all. If I use the
tag2 = tag.encode("utf-8")
for every entity on the list and then pass the new list, I see all the non-ascii characters like this one -> ÎÏιÏÏήμεÏ

How to read database (JDBC Request) result into variables in Jmeter

I want to read Database result into variables so I can use it for later requests.
How can i do it?
What if i want to return from database multiple
columns, or even rows? can loop the returned table same way i can
with "CSV Data Set Config"?
--edit--
Ok, i found this solution that uses regular expression to parse the response, but this solution and other like it doesn't work for me, because they require me to change SQL queries so Jmeter could parse them more "easily". I'm using Jmeter to do testing (load testing), and the last thing I want is to maintain 2 different codes, one for "testing" and other for "runtime".
Is there a "specific" JDBC Request solution that enable me to read result into variables using the concept of result-sets and columns?
Using The Regular Expression shouldn't affect what your SQL statement looks like. If you need to modify which part of the response you store in variable, use a Beanshell sampler with java code to parse out the response and store into a variable.
You can loop through the returned table, by using a FOREACH controller, referencing the variable name in the reg ex. Make sure in your reg ex, you set the match value to -1 to capture every possible match.

SSIS suitability

I'm tring to create an SSIS package to import some dataset files, however given that I seem to be hitting a brick
wall everytime I achieve a small part of the task I need to take a step back and perform a sanity check on what I'm
trying to achieve, and if you good people can advise whether SSIS is the way to go about this then I would
appreciate it.
These are my questions from this morning :-
debugging SSIS packages - debug.writeline
Changing an SSIS dts variables
What I'm trying to do is have a For..Each container enumerate over the files in a share on the SQL Server. For each
file it finds a script task runs to check various attributes of the filename, such as looking for a three letter
code, a date in CCYYMM, the name of the data contained therein, and optionally some comments. For example:-
ABC_201007_SalesData_[optional comment goes here].csv
I'm looking to parse the name using a regular expression and put the values of 'ABC', '201007', and
'SalesData' in variables.
I then want to move the file to an error folder if it doesn't meet certain criteria :-
Three character code
Six character date
Dataset name (e.g. SalesData, in this example)
CSV extension
I then want to lookup the Character code, the date (or part thereof), and the Dataset name against a lookup table
to mark off a 'checklist' of received files from each client.
Then, based on the entry in the checklist, I want to kick off another SSIS package.
So, for example I may have a table called 'Checklist' with these columns :-
Client code Dataset SSIS_Package
ABC SalesData NorthSalesData.dtsx
DEF SalesData SouthSalesData.dtsx
If anyone has a better way of achieving this I am interested in hearing about it.
Thanks in advance
That's an interesting scenario, and should be relatively easy to handle.
First, your choice of the Foreach Loop is a good one. You'll be using the Foreach File Enumerator. You can restrict the files you iterate over to be just CSVs so that you don't have to "filter" for those later.
The Foreach File Enumerator puts the filename (full path or just file name) into a variable - let's call that "FileName". There's (at least) two ways you can parse that - expressions or a Script Task. Depends which one you're more comfortable with. Either way, you'll need to create three variables to hold the "parts" of the filename - I'll call them "FileCode", "FileDate", and "FileDataset".
To do this with expressions, you need to set the EvaluateAsExpression property on FileCode, FileDate, and FileDataset to true. Then in the expressions, you need to use FINDSTRING and SUBSTRING to carve up FileName as you see fit. Expressions don't have Regex capability.
To do this in a Script Task, pass the FileName variable in as a ReadOnly variable, and the other three as ReadWrite. You can use the Regex capabilities of .Net, or just manually use IndexOf and Substring to get what you need.
Unfortunately, you have just missed the SQLLunch livemeeting on the ForEach loop: http://www.bidn.com/blogs/BradSchacht/ssis/812/sql-lunch-tomorrow
They are recording the session, however.

Resources