RethinkDB Map/Reduce examples - rethinkdb

I running through the Map/Reduce examples in the RethinkDB docs. I have some documents that look like this:
{
"category": "Fiction" ,
"content": "This far, no further!" ,
"id": "0fc5339b-8139-4996-8979-88a0051195e3" ,
"title": "The line must be drawn here"
}
When I follow the examples using Data Explorer. e.g.
r.table('posts').map(lambda post: 1)
I get this error:
SyntaxError: missing ) after argument list

This is because the Data Explorer only allows JavaScript as an input. You need to switch to something like this to make it work:
r.table('posts').map(function(post){return 1})

Related

Kibana visualize use wild card in search bar

Is it possible to use wild card in Kibana visualize search bar.
Tried to use it like below, but did not work.
operation: "Revers" NOT file:"*Test.Revers"
This returns 2 because there are two Revers terms ("Revers", "/test/count/Test.Revers" ) even though only one data entry is in the stats data.
The following also returns the same value as 2.
operation: "Revers"
Stat data sample is as below.
"_source": {
"status": 0,
"trstime": 1819,
"username": "test",
"operation": "Revers",
"file": "/test/count/Test.Revers"
}
I have tested it in ES 7.10 as you not mentioned ES version.
Answer to your question is YES, you can use wildcrad in Kibana visualize search bar but value should be without double quotes. Because if you give value in doble quotes it will consider as text and search for it.
You can try below query and it will give you your expected output:
operation: Revers AND NOT file.keyword: *Test.Revers
The result given for the below query as 1 without double quotes.
operation: Revers AND NOT file: *Test.Revers

Graphene Django disable suggestions "Did you mean ..."

When you post an query with syntax errors graphql/graphene makes suggestions to you. By example, sending "i", it suggest "ID".
query{
users{
i
}
}
{
"errors": [
{
"message": "Cannot query field \"i\" on type \"User\". Did you mean \"id\"?",
"locations": [
{
"line": 5,
"column": 9
}
]
}
]
}
Can suggestions be disabled?
More info:
Syntax analysis who add suggestions is executed before the middlewares.
Apparently suggestions are made by ScalarLeafsRule class.
Ok, people in graphql-core github repo is awesome, they helped to me to solve this.
So graphql-core has two relevant versions, 3 (current) and 2.3.2 (legacy).
For graphql-core 3, quoting to Cito
Ok, if you want to keep it closed and also disable introspection it makes a little more sense. I suggest you simply set graphql.pyutils.did_you_mean.MAX_LENGTH = 0. I just commited a small change ffdf1b3 that makes this work a bit better.
You can also ask over at https://github.com/graphql/graphql-js/issues if they want to add some functionality to support your use case. From there it would be ported back here.
For legacy version:
from graphql.validation import rules
def get_empty_suggested_field_names(schema, graphql_type, field_name):
return []
def get_empty_suggested_type_names(schema, output_type, field_name):
return []
rules.fields_on_correct_type.get_suggested_field_names = get_empty_suggested_field_names
rules.fields_on_correct_type.get_suggested_type_names = get_empty_suggested_type_n
You can place it on django settings file.
Please follow all the thread on https://github.com/graphql-python/graphql-core/issues/97

Array of values in List view

What is the proper way to achieve the visual equivalent of this:
, but for an array that is part of the entity of the Resource itself (as opposed being a field on a referenced entity)? For instance, if my document looked like {"id": 1, "title": "my title", "comments_by": ["john", "kate"]}.
I tried to nest a List element but wasn't able to make it look right.
You're on the right track; This should achieve your goal:
<FunctionField render={record=>
record.comments_by.map((by,index)=> <ChipField record={{by}} source="by"/>)
}/>

How to use openWhisk forwarder combinator to forward parameters around a cloudant action

I have this scenario where I want to check if user's email is already been used when trying to signup and throw an error “user already exists” in that case.
here’s what my sequence looks like:
Input action -> CloudnAnt EXE QUERY-Find -> Validate email action -> CloudnAnt create User/Throw user already exists error action
my json payload looks like this :
{email: 'blahblah#domain.com', pass: "pass"}
the problem is that I have no control over the output of the cloudnant predefined actions, and by that I lose the payload after the 2nd action "CloudnAnt EXE QUERY-Find User with email action"
Is there a way to keep my input all the way through the sequence? and could the forward combinator be the solution for this issue?
I'd try /whisk.system/combinators/forwarder, which lets you pass arguments to an action and then specify arguments that get sent to the next one. Ie, I've got 5 arguments, let's pass 1 and 2 on to the next item in the sequence, and when done, pass 3, 4, 5 to the next one. I believe the output from the first item goes along as well.
The solution is very simple, just replace the cloudant action with a forward combinator which will invoke the cloudant action and forward the parameters around it.
to invoke a cloudant action you need get the full path for your action and that includes the namespace and the database name like the following:
/namespace/dbname/actionName
in my case it was /sansan/users/exec-query-find
so if you want to check whether the email exists or not in your cloudant db, and keep the original params just pass the following payload to your cloudant action
{
"data":{...},// some data you want to keep after the cloudant query
"query": {
"selector": {
"email": "email#domain.com"
}
},
"$actionName": "/sansan/users/exec-query-find",
"$forward": [// list of params you want forward
"data"
],
"$actionArgs": [ // list of params you want to feed the action
"query"
]
}
after running the sequence, the output should look like this:
{
"data": {...}, // your data
"docs": [...]// cloudant query results
}
the forward combinator is poorly documented, but you can find more details about it in Raymond Camden's blog post
look at Raymond's answer here too

Reducing duplication for JSON test input in RSpec

I'm working on an application that reads JSON content from files and uses them to produce output. I'm testing with RSpec, and my specs are littered with JSON literal content all over the place. There's a ton of duplication, the files are big and hard to read, and it's getting to the point where it's so painful to add new cases, it's discouraging me from covering the corner cases.
Is there a good strategy for me to reuse large sections of JSON in my specs? I'd like to store the JSON somewhere that's not in the spec file, so I can focus on the test logic in the specs, and just understand which example JSON I'm using.
I understand that if the tests are hard to write, I may need to refactor the application, but until I can get the time to do that, I need to cover these test cases.
Below is one modified example from the application. I have to load many different JSON formatted strings like this, many are considerably larger and more complex:
RSpec.describe DataGenerator do
describe "#create_data" do
let(:input){
'{ "schema": "TEST_SCHEMA",
"tables": [
{ "name": "CASE_INFORMATION",
"rows": 1,
"columns": [
{ "name": "case_location_id", "type": "integer", "initial_value": "10000", "strategy": "next" },
{ "name": "id", "type": "integer", "delete_key": true, "initial_value": "10000", "strategy": "next" }
]
}
]
}'
}
it "generates the correct number of tables" do
generator = DataGenerator.new(input)
expect(generator.tables.size).to eq 1
end
end
end
We had a very same problem. We solved it by creating following helpers:
module JsonHelper
def get_json(name)
File.read(Rails.root.join 'spec', 'fixtures', 'json', "#{name}.json")
end
end
We moved all the json into files in spec/fixtures/json folder. Now you will eb able to use it as:
include JsonHelper
let(:input){ get_json :create_data_input }
Naturally you can tweak it as mach as you like/need. For example we were stubbing external services json responses, so we created get_service_response(service_name, request_name, response_type) helper. It is much more readable now when we use get_service_response('cdl', 'reg_lookup', 'invalid_reg')
assuming you put your json into 'create_data_input`

Resources