In cloudwatch how to group by key inside a nested json? - amazon-cloudwatch

For example
[{
"date" : "xx",
"user" : "user1",
"hostname" : "hostname1",
"ostype" : "os1",
"package" : {
"smplepackage" : "v3",
"package2" : "v2",
"package3" : "v5",
"package6" : "v10",
"package5" : "v11",
"package7" : "v2"
}
},
{
"date" : "xx",
"user" : "user2",
"hostname" : "hostname2",
"ostype" : "Mac1",
"package" : {
"smplepackage" : "v1",
"dx-package2" : "v2",
"package4" : "v3",
"package6" : "v4",
"package8" : "v5",
"package7" : "v6"
}
}
]
How can I get the user's count group by package in cloudwatch? I Could not find related examples to group by keys inside nested json.

Related

How to use springdoc with #PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) and #RequestParam

I'm upgrading a project from SpringFox to SpringDoc v1.6.12 and I struggle to make the new code work for the following method of my RestController:
#PostMapping(path = TASK_MAPPING_PATH, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> loadTask(
#RequestParam String applicationId,
#RequestParam String businessId,
#RequestParam boolean directLink
) {[...]}
The particularity of this method is that it should encode its parameters in the body since the Content-Type application/x-www-form-urlencoded is used.
But when I browse the url https://localhost:8443/v3/api-docs, the generated code is the following:
"/api/enrolment/task" : {
"post" : {
"operationId" : "loadTask",
"parameters" : [ {
"in" : "query",
"name" : "applicationId",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"in" : "query",
"name" : "businessId",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"in" : "query",
"name" : "directLink",
"required" : true,
"schema" : {
"type" : "boolean"
}
} ],
"responses" : {
[...]
},
"summary" : [...],
"tags" : [...]
}
},
All of the applicationId, businessId and directLink parameters are passed in the URL instead of the request body as expected.
I would have expected the following openApi definition instead:
"/api/enrolment/task" : {
"post" : {
"operationId" : "loadTask",
"requestBody" : {
"content" : {
"application/x-www-form-urlencoded" : {
"schema" : {
"type" : "object",
"properties" : {
"applicationId" : {
"type" : "string"
},
"businessId" : {
"type" : "string"
},
"directLink" : {
"type" : "boolean"
}
},
"required" : [ "applicationId", "businessId", "directLink" ]
}
}
}
},
"responses" : {
[...]
},
"summary" : [...],
"tags" : [...]
}
},
Does anyone ever had the same issue ?
Does anyone knows the solution to my problem ?
Thanks.

BQ load job failing when trying to create table from AVRO file

I am trying to create a BQ Table from AVRO file. I am getting this error when i run the BQ load job:
"Error while reading data, error message: The Apache Avro library
failed to parse the header with the following error: Unexpected type
for default value. Expected long, but found null: null"
The Schema of the AVRO file is:
{
"type" : "record",
"name" : "Pair",
"namespace" : "org.apache.avro.mapred",
"fields" : [ {
"name" : "key",
"type" : "int",
"doc" : ""
}, {
"name" : "value",
"type" : {
"type" : "record",
"name" : "CustomerInventoryOrderItems",
"namespace" : "com.test.customer.order",
"fields" : [ {
"name" : "updated_at",
"type" : "long"
}, {
"name" : "inventory_order_items",
"type" : {
"type" : "map",
"values" : {
"type" : "array",
"items" : {
"type" : "record",
"name" : "CustomerInventoryOrderItem",
"fields" : [ {
"name" : "order_item_id",
"type" : "int",
"default" : null
}, {
"name" : "updated_at",
"type" : "long"
}, {
"name" : "created_at",
"type" : "long"
}, {
"name" : "product_id",
"type" : [ "null", "int" ],
"default" : null
}, {
"name" : "type_id",
"type" : "int",
"default" : null
}, {
"name" : "event_id",
"type" : [ "null", "int" ],
"default" : null
}, {
"name" : "price",
"type" : [ "null", "double" ],
"default" : null
}, {
"name" : "tags",
"type" : [ "null", "string" ],
"default" : null
}, {
"name" : "estimated_ship_date",
"type" : [ "null", "long" ],
"default" : null
} ]
}
}
}
} ]
},
"doc" : "",
"order" : "ignore"
} ]
}
I am not sure what is wrong with the schema or anything else, because of which I am unable to load the data.
The problem is most likely the fields that have type int but you have null as the default value. For example:
"name" : "type_id",
"type" : "int",
"default" : null
The default should either be changed to be an integer or the type should be changed to be a union that includes null (like many of the other fields).

Mongodb: Pull corresponding value from another collection

I have two diff collections:
CollectionA
{
"_id" : 1.0,
"1234" : "GROUP"
}
{
"_id" : 2.0,
"2345" : "SUBGROUP"
}
CollectionB
{
"_id" : 1.0,
"config" : "1234",
"description" : "DCS"
}
{
"_id" : 2.0,
"config" : "2345",
"description" : "BCS"
}
I was expecting the below output when i write a find query by joining the two collections. Can we able to get the requested output by using $lookup function?
{
"_id" : 1.0,
"config" : "GROUP",
"description" : "DCS",
}
{
"_id" : 2.0,
"config" : "SUBGROUP",
"description" : "BCS",
}
You can implement your query like this:
db.getCollection('a').aggregate([{
$lookup: {
from: 'b',
localField: '_id',
foreignField: '_id',
as: 'data'
}
},
{
$unwind: '$data'
},
{
$project: {
config: '$1234', //In your schema you may have the same key instead of 1234 and 2345
description: '$data.description'
}
}
]);

Access Nested Array with Pug

I have the following that is being pulled froma MongoDB and I'm trying to display the "url" and "applications" in pug the data from url is displaying correctly but I'm having trouble accessing the data from "applications"
{
"_id" : ObjectId("5975cdfeb39f71f2fcc2a09d"),
"url" : "http://www.opencolleges.edu.au",
"applications" : [
{
"name" : "AppNexus",
"confidence" : "100",
"version" : "",
"icon" : "AppNexus.svg",
"website" : "http://appnexus.com",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "CloudFlare",
"confidence" : "100",
"version" : "",
"icon" : "CloudFlare.svg",
"website" : "http://www.cloudflare.com",
"categories" : [
"CDN"
]
},
{
"name" : "Crazy Egg",
"confidence" : "100",
"version" : "",
"icon" : "Crazy Egg.png",
"website" : "http://crazyegg.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Google AdSense",
"confidence" : "100",
"version" : "",
"icon" : "Google AdSense.svg",
"website" : "http://google.com/adsense",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "Google Analytics",
"confidence" : "100",
"version" : "UA",
"icon" : "Google Analytics.svg",
"website" : "http://google.com/analytics",
"categories" : [
"Analytics"
]
},
{
"name" : "Google Font API",
"confidence" : "100",
"version" : "",
"icon" : "Google Font API.png",
"website" : "http://google.com/fonts",
"categories" : [
"Font Scripts"
]
},
{
"name" : "Google Tag Manager",
"confidence" : "100",
"version" : "",
"icon" : "Google Tag Manager.png",
"website" : "http://www.google.com/tagmanager",
"categories" : [
"Tag Managers"
]
},
{
"name" : "New Relic",
"confidence" : "100",
"version" : "",
"icon" : "New Relic.png",
"website" : "http://newrelic.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Nginx",
"confidence" : "100",
"version" : "",
"icon" : "Nginx.svg",
"website" : "http://nginx.org/en",
"categories" : [
"Web Servers"
]
},
{
"name" : "Optimizely",
"confidence" : "100",
"version" : "",
"icon" : "Optimizely.png",
"website" : "http://optimizely.com",
"categories" : [
"Analytics"
]
},
{
"name" : "Sizmek",
"confidence" : "100",
"version" : "",
"icon" : "Sizmek.png",
"website" : "http://sizmek.com",
"categories" : [
"Advertising Networks"
]
},
{
"name" : "Twitter Bootstrap",
"confidence" : "100",
"version" : "",
"icon" : "Twitter Bootstrap.png",
"website" : "http://getbootstrap.com",
"categories" : [
"Web Frameworks"
]
},
{
"name" : "VideoJS",
"confidence" : "100",
"version" : "",
"icon" : "VideoJS.png",
"website" : "http://videojs.com",
"categories" : [
"Video Players"
]
},
{
"name" : "jQuery",
"confidence" : "100",
"version" : "",
"icon" : "jQuery.svg",
"website" : "http://jquery.com",
"categories" : [
"JavaScript Frameworks"
]
}
],
"originalUrl" : "http://www.opencolleges.edu.au",
"updatedAt" : ISODate("2017-07-26T23:23:19.756Z"),
"__v" : 0,
"createdAt" : ISODate("2017-07-24T10:37:50.247Z")
}
In the .pug file I use:
ul.list-group
each tech, i in techs
li.list-group-item
h5 #{tech.originalUrl}
h5 #{tech.applications.name}
However the result for tech.applications.name returns null value and when I use tech.applications it returns [Object, Object] is it possible to access this using PUG?

db.find vs db.aggregation to select nested array Object

I'v tried to perform the following query :
db.getCollection('fxh').find({"username": "user1", "pf.acc.accnbr" : 915177},{userid: true, "pf.pfid": true, "pf.acc.accid":true})
and my collection is the following :
{
"_id" : ObjectId("5932fd8f381d4c0a7de21942"),
"userid" : 1496513894,
"username" : "user1",
"email" : "user1#gmail.com",
"fullname" : "User 1",
"pf" : {
"acc" : [
{
"cyc" : [
{
"det" : {
"status" : "New",
"dcycid" : 1496513941
},
"status" : "New",
"name" : "QPT202017_M1",
"cycid" : 1496513940
}
],
"status" : "New",
"accnbr" : 915177,
"accid" : 1496513939
},
{
"cyc" : [
{
"det" : {
"status" : "New",
"dcycid" : 1496552643
},
"status" : "New",
"name" : "QPT202017_S8",
"cycid" : 1496552642
}
],
"status" : "New",
"accnbr" : 73497,
"accid" : 1496552641
}
],
"pfid" : 1496513935,
},
"lastupdate" : ISODate("2017-06-03T18:18:55.080Z"),
"__v" : 0
}
When I execute the query the result is the following :
{
"_id" : ObjectId("5932fd8f381d4c0a7de21942"),
"userid" : 1496513894,
"portfolio" : {
"acc" : [
{
"accid" : 1496513939
},
{
"accid" : 1496552641
}
],
"pfid" : 1496513935
}
}
And my problem is that I need to see only the concerned accid and the result returns the all accid !.
Any idea how just to return the selected accid of accnbr ?
NB : I have also tried to add $ sign at the end of my query , it
selects the right acc but it returns the all objects or I need just
only ONE returned object.
On 6/5/17
I also used the aggregate command instead of find and it get result by using this :
db.getCollection('fxh').aggregate([ { $unwind : "$pf.acc"} , { $match : {"username":"adh1", "pf.acc.accbr": 915177 } }, {$project : {_id:0, accid: "$pf.acc.accid"}}])
But could NOT get a lower level result, when I ran this :
db.getCollection('fxh').aggregate([ { $unwind : "$pf.acc.cyc"} , { $match : {"username":"adh1", "pf.acc.accbr": 915177, "pf.acc.cyc.name": "QPT202017_M1" } }, {$project : {_id:0, cycid: "$pf.acc.cyc.cycid"}}])
Any idea ?
You can try the below aggregation pipeline.
The idea is to $unwind one nested level at a time, starting from the outermost to the innermost.
For each nested level unwinding, you can apply the$match to limit the documents and continue till you have the desired shape.
You can $group it together at the end to get back to the original shape.
db.getCollection('fxh').aggregate([
{ $match : {"username":"adh1"} },
{ $unwind : "$pf.acc"} ,
{ $match : {"pf.acc.accbr": 915177 } },
{ $unwind : "$pf.acc.cyc"},
{ $match : {"pf.acc.cyc.name": "QPT202017_M1" } },
{$project : {_id:0, accid: "$pf.acc.accid", cycid: "$pf.acc.cyc.cycid"}}])