I would like to make the following style table output using CouchDB and linked documents:
+----------------+------------+--------------------+
| Title | Date | Number of Comments |
+----------------+------------+--------------------+
| Hello World | 2000-01-01 | 301 |
| Next Question? | 1999-03-04 | 11 |
| Final Post | 1992-04-01 | 64 |
+----------------+------------+--------------------+
I have documents that look like this for posts:
{ _id : 'hello-world', title : 'Hello World', date : '2000-01-01', type : 'post' }
and for comments:
{ _id : 'some-comment', title : 'Great post!', postid: 'hello-world', type : 'comment' }
{ _id : 'some-comment2', title : 'Poor quality', postid: 'final-post', type : 'comment' }
How can I accomplish this? I would prefer to use a single map/reduce.
I'm answering this for myself in case any one else has this question. I think my misunderstand comes from my being used to SQL.
Basically, my options are:
Create a design document view (comments-by-post) that will give me the post._id as the key and the # number of comments for that post. Then, I can stitch this together with the posts obtained by a Mango query or another view in my programming language.
Alternatively, and probably more correctly, I can just create a property called numberOfComments on the post object and update it every time someone comments. This feels wrong from an SQL perspective, but I believe the flexibility of the document database lends itself to this.
I'm choosing to do #1 to begin with and experiment with #2.
Related
I would really appreciate if you could help me with a query that I would need to my report. This is my query:
SecurityAlert
| where ProviderName contains "IPC"
and the result is:
I would need to extract just the AadUserId from Entities but I'm not sure how since I'm still new to the KQL language.
I would be very grateful if you could advice.
Thank you very much.
I expect to extract AadUserID from my query.
Here are a few options
// Sample data generation. Not part of the solution.
let SecurityAlert = datatable(ProviderName:string, Entities:dynamic)
[
"IPC", dynamic([{"AadUserID":"Dummy"}])
];
// Solution starts here
SecurityAlert
| where ProviderName contains "IPC"
| project tostring(Entities[0].AadUserID)
Entities_0_AadUserID
Dummy
Fiddle
// Sample data generation. Not part of the solution.
let SecurityAlert = datatable(ProviderName:string, Entities:dynamic)
[
"IPC", dynamic([{"AadUserID":"Dummy"}])
];
// Solution starts here
SecurityAlert
| where ProviderName contains "IPC"
| mv-expand Entities
| project tostring(Entities.AadUserID)
| where isnotempty(Entities_AadUserID)
Entities_AadUserID
Dummy
Fiddle
// Sample data generation. Not part of the solution.
let SecurityAlert = datatable(ProviderName:string, Entities:dynamic)
[
"IPC", dynamic([{"AadUserID":"Dummy"}])
];
// Solution starts here
SecurityAlert
| where ProviderName contains "IPC"
| mv-apply Entities on (summarize make_set(Entities.AadUserID))
| project set_Entities_AadUserID
set_Entities_AadUserID
["Dummy"]
Fiddle
The log item looks like below, the currencyamount field has multiple case situation:
{ "AdditionalFields":{
"backendRequestBody":{
"currencyamount":1
} } }
{ "AdditionalFields":{
"backendRequestBody":{
"CurrencyAmount":1
} } }
{ "AdditionalFields":{
"backendRequestBody":{
"currencyAmount":1
} } }
However, the parse_json log query is case sensitive, is there any way to get the currentAmount field case insensitively using azure log query?
The query below only able to get one of the log entry which has lower case currencyamount field.
AzureDiagnostics
| where apiId_s contains "targetId" and AdditionalFields.backendRequestBody has "amount"
| extend amt = (parse_json(tostring(AdditionalFields.backendRequestBody)).currencyamount)
AFAIK, in parse Json we cannot be able to use Incase sensitive Json object. Instead of that you can use following way to achieve.
AzureActivity
| where apiId_s contains "targetId" and AdditionalFields.backendRequestBody has "amount"
| extend backendReqbody = parse_json(AdditionalFields.backendRequestBody)
| extend lowercuramount = parse_json(tostring(parse_json(backendReqbody.currencyamount)))
| extend curamount = parse_json(tostring(parse_json(backendReqbody.CurrencyAmount)))
| extend lowupcuramount = parse_json(tostring(parse_json(backendReqbody.currencyAmount)))
You can use conditions like (iff) Ms -Doc while filtering the data in a result.
I'm currently trying to write a SPARQL query for Wikidata in which I rank subprofessions according to how many people have that respective occupation and group it according to their parent profession alphabetically.
My final result should look something like
Profession | Subprofession | Count
Artist | Painter | 34
Artist | Actor | 12
Politician | President | 67
Politician | Minister | 13
Right now, I could only go as far as displaying the parent profession, but I feel I have a long way to go ahead and introducing the subprofession in the query and just trying to display it along side the parent occupation leads all the time to Timeout. Is it here where I should use nested SELECTS? I'm not very familiar with them
SELECT ?occupation ?suboccupation (count(*) as ?count)
WHERE
{
?people wdt:P106 ?occupation . #occupation
?suboccupation wdt:P279 ?occupation . #subclassof
}
GROUP BY ?occupation ?suboccupation
ORDER BY DESC(?count)
Thank you everybody in advance!
Well, there seem to be some professions and sub-professions that have no English language label so some of the listings are not very helpful. In addition, this list is LONG! You may want to aggregate more or limit the results somehow.
Here's a start to what you might want:
SELECT ?profLabel ?subprofLabel ?count
WITH {
SELECT ?prof ?subprof (COUNT(?person) AS ?count) WHERE {
?prof wdt:P31 wd:Q28640.
?subprof wdt:P279+ ?prof.
?person wdt:P106 ?subprof.
}
GROUP BY ?prof ?subprof
} AS %main {
INCLUDE %main .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?profLabel DESC(?count)
How can I fetch a list of all the scenarios that have a particular tag. For example
get all scenarios that have #checkout tag.
Lets assume you have 15-20 Scenarios/Scenarios Outline tagged with #checkout.
#checkout
Scenario Outline: Validation of UseCase Guest User Order Placement flow from Search
Given User is on Brand Home Page <Site>
And User searches for a styleId and makes product selection on the basis of given color and size
| Style_ID | Product_Size | Product_Color |
| TestData1 | TestData1 | TestData1 |
| TestData2 | TestData2 | TestData2 |
Then Clicking on Cart icon shall take user to Shopping Bag
Please follow this way to fetch name of scenarios.
File name Hook.java
#Before
public void setUpScenario(Scenario scenario){
String scenarioName = scenario.getName();
//Either you can write down name of the scenario under a file system like excel or implement in the way you want
}
Please lets know if you find it meaningful and it solved your problem.
Dry run to the rescue.
Dry run gives you a way to quickly scan your features without actually running them.
Try the following CucumberOptions annotations (this is Java/Junit version, but the idea applies everywhere)
#RunWith(Cucumber.class)
#CucumberOptions(plugin = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber.json" }, glue = {
"some.stepdef" }, features = { "src/cucumberTest/featureFiles" }, tags = { "#now" }
,dryRun = true, strict=true)
public class CucumberNowTestDryRunner {
}
The cucumber report will look like this
In AfterScenario method, I want to get the rows from table "Examples" in Scenario Outline, to get the values in it, and search that specific values in the database
I know that this can be achieved by using Context.Scenario.Current...
Context.Scenario.Current[key]=value;
...but for some reason I'd like to be able to get it in a simpler way
like this:
ScenarioContext.Current.Examples();
----------- SCENARIO --------------------------------
Scenario Outline: Create a Matter
Given I create matter "< matterName >"
Examples:
| matterName |
| TAXABLE |
----------AFTER SCENARIO -----------------------------------
[AfterScenario()]
public void After()
{
string table = ScenarioContext.Current.Examples();
}
So if you look at the code for ScenarioContext you can see it inherits from SpecflowContext which is itself a Dictionary<string, object>. This means that you can simply use Values to get the collection of values, but I have no idea if they are Examples or not.
The best solution I came up with was to infer the examples by keeping my own static singleton object, then counting how many times the same scenario ran.
MyContext.Current.Counts[ScenarioContext.Current.ScenarioInfo.Title]++;
Of course, this doesn't work very well if you don't run all the tests at the same time or run them in random order. Having a table with the examples themselves would be more ideal, but if you combine my technique along with using ScenarioStepContext you could extract the parameters of the Examples table out of the rendered step definition text itself.
Feature
Scenario Outline: The system shall do something!
Given some input <input>
When something happens
Then something should have happened
Examples:
| input |
| 1 |
| 2 |
| 3 |
SpecFlow Hook
[BeforeStep]
public void BeforeStep()
{
var text = ScenarioStepContext.Current.StepInfo.Text;
var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType;
if (text.StartsWith("some input ") && stepType == StepDefinitionType.Given)
{
var input = text.Split(' ').Last();
}
}