I'm trying to apply query result reuse in AWS Athena using the javascript sdk, but I'm getting this error in CloudWatch: UnexpectedParameter: Unexpected key 'ResultReuseConfiguration' found in params
Here is my code:
const params = {
QueryString: `SELECT * FROM "some_database"."some_table"`,
ResultConfiguration: {
OutputLocation:
"someurl",
},
ResultReuseConfiguration: {
ResultReuseByAgeConfiguration: {
Enabled: true,
MaxAgeInMinutes: 10800,
},
},
};
athena.startQueryExecution(params, function (err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
const queryExecutionId = data.QueryExecutionId;
...
which mirrors what the documentation says is the request syntax: https://docs.aws.amazon.com/athena/latest/APIReference/API_StartQueryExecution.html
{
"ClientRequestToken": "string",
"ExecutionParameters": [ "string" ],
"QueryExecutionContext": {
"Catalog": "string",
"Database": "string"
},
"QueryString": "string",
"ResultConfiguration": {
"AclConfiguration": {
"S3AclOption": "string"
},
"EncryptionConfiguration": {
"EncryptionOption": "string",
"KmsKey": "string"
},
"ExpectedBucketOwner": "string",
"OutputLocation": "string"
},
"ResultReuseConfiguration": {
"ResultReuseByAgeConfiguration": {
"Enabled": boolean,
"MaxAgeInMinutes": number
}
},
"WorkGroup": "string"
}
My #aws-sdk/client-athena is at version 3.264.0, which means ResultReuseConfiguration should be supported.
Why would I be getting this error, and how can I fix it?
Related
My goal is to use create schema for json-schema-yup-transformer, therefore, I need to get this format :
const schema = {
type: "object",
properties: {
firstName: {
type: "string",
minLength: 2,
},
email: {
type: "string",
format: "email",
},
},
required: requiredFields,
};
I've got a schemaProperties :
const schemaProperties = formatData.map((item) => {
return {
[item.value]: { type: item.type, validation: item.validation },
};
});
That returns me :
[
{
"firstName": {
"type": "text",
"validation": {
"required": true,
"requiredMessage": "Prénom requis"
}
}
},
{
"lastName": {
"type": "text"
}
},
...
]
But, my problem is that schemaProperties is an array actually and not an object. I tried to destruct it and transform into an object, but its not working... Im sure its not something very complicated but I'm stuck...
I have a role-mapping model which maps a userId to a roleId, I need a remote method on the role-mapping model to retrieve the role-mappingId for a given userId.
this the code for the remoteMethod
'use strict';
module.exports = function(Rolemapping) {
Rolemapping.getRolesByUser = async function (id, cb) {
const roleMappings = await Rolemapping.find({ where: { principalId: id
} })
cb(null, roleMappings);
};
Rolemapping.remoteMethod("getRolesByUser", {
http: {
path: "/getRolesByUser",
verb: "get"
},
accepts: [
{ arg: "userId", type: "string", http: { source: "query" } }
],
returns: {
arg: "result",
type: "string"
},
description: "Cvs "
});
};
this is the role-mapping json file :
{
"name": "roleMapping",
"base": "RoleMapping",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"role": {
"type": "belongsTo",
"model": "role",
"foreignKey": "roleId"
}
},
"acls": [],
"methods": {}
}
the above remote method doesn't show up in the loopback API explorer.
RoleMapping is a built-in model, its role-mapping.js file is hidden in node_modules/loopback, I've tested it and it doesn't look like will load a js file for itself from common/models.
It looks like a boot script is your only option. It's the same code, but your function receives the server object.
server/boot/get-roles-by-user.js
module.exports = function(server) {
const Rolemapping = server.models.RoleMapping;
Rolemapping.getRolesByUser = async function (id) {
return JSON.stringify(await Rolemapping.find({ where: { principalId: id
} }))
};
Rolemapping.remoteMethod("getRolesByUser", {
http: {
path: "/getRolesByUser",
verb: "get"
},
accepts: [
{ arg: "userId", type: "string", http: { source: "query" } }
],
returns: {
arg: "result",
type: "string"
},
description: "Cvs "
});
}
I've also removed the cb parameter from your remote method, because methods which return a Promise do not need it, just return the value like you would for any other function
I have category and category_subs, master-detail model, post model belongs to category_subs. In the following code, I can get master-detail of both but I don't know how to include post to them or even attachment model of the post to the remote method.
module.exports = function (Category) {
Category.categorySubs = function (id, cb) {
Category.find({
where: {
id: id
},
include: {
relation: 'categorySubs',
scope: {
include: 'category_subs'
}
}
},
function (err, posts) {
cb(null, posts);
});
}
Category.remoteMethod('categorySubs', {
accepts: {
arg: 'id',
type: 'string'
},
returns: {
arg: 'ID',
type: 'string'
},
http: {
path: '/iteminfo',
verb: 'get'
}
});
update
category.json
"relations": {
"categorySubs": {
"type": "hasMany",
"model": "category_subs",
"foreignKey": "catgory_id"
}
},
category_subs
"relations": {
"posts": {
"type": "hasMany",
"model": "post",
"foreignKey": "category_sub_id"
}
},
I googled and I think you had to have deep look at https://loopback.io/doc/en/lb3/Include-filter.html
I need to create a filter that will take all of my cameras and filter out cameras that are associated with 'blueprints'. This is located within the properties of my cameras in MongoDB. I want to filter out cameras that don't have type "BluePrint".
I believe the section I need to fix is the query section in the method getAllCameras.
self.evaluateCameras = function() {
self.getAllCameras(function(err, cameras) {
if(err) {
console.log(err);
}
else {
// -- publish newly included cameras
cameras.forEach(function(camera) {
if(self.includedCameras[camera._id] == undefined) {
camera._source.entityId = camera._id;
camera._source.systemType = camera._type;
self.publish(camera._source, "create")
// -- to scale this need to do caching in Redis shared cache across processes
self.includedCameras[camera._id] = camera;
}
});
}
// process any messages received while initializing stream
self.initComplete = true;
for(var j = 0; j < self.tempMessageCache.length; j++) {
var cacheMsg = self.tempMessageCache[j];
self.evalPublish(cacheMsg);
}
self.tempMessageCache = [];
});
};
self.getAllCameras = function(callback) {
self.q = {
"from": 0,
"size": 10000, // -- todo: implement some kind of paging
"sort": [
{'properties.name': 'asc'},
{'properties.cameraId': 'asc'}
],
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"exists": {"field": "properties.geoRef"}
},
{
"geo_shape": {
"properties.geoRef": {
"shape": {
"coordinates": properties.geoRef.coordinates,
"type": "point"
}
}
}
}
]
}
}
}
};
elasticClient.search({
index: 'myproject-now',
type: 'system.camera',
body: self.q
}, function (err, response) {
if (err)
callback(err, null);
else {
callback(null, response.hits.hits);
}
});
};
After some research into elasticsearch this is the solution I came up with:
self.getAllCameras = function(callback) {
self.q = {
"from": 0,
"size": 10000, // -- todo: implement some kind of paging
"sort": [
{'properties.name': 'asc'},
{'properties.cameraId': 'asc'}
],
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"exists": {"field": "properties.geoRef"}
},
{
"not": {
"term": {
"properties.geoRef.type" : "floorplan"
}
}
}
]
}
}
}
};
elasticClient.search({
index: 'myproject-now',
type: 'system.camera',
body: self.q
}, function (err, response) {
if (err)
callback(err, null);
else {
callback(null, response.hits.hits);
}
});
};
I'm trying to dynamically generate a graphql scheme from a json config. But i'm unable to create a GraphQLList to itself.
json:
{
"label": "user",
"properties": [
{
"key": "name",
"type": "string"
},
{
"key": "id",
"type": "id"
},
{
"key": "birthday",
"type": "date"
},
{
"key": "gender",
"type": "string"
},
{
key: 'friends',
type: 'string'
}
]
}
The javascript code generating:
graphSchemes.forEach(function (graphScheme) {
graphQLObjects[graphScheme.label] = new graphql.GraphQLObjectType({
name: graphScheme.label,
fields: graphScheme.properties.reduce((fields, property) => {
if (property.key === 'friends') {
fields[property.key] = {
type: new graphql.GraphQLList(graphQLObjects[graphScheme.label])
};
return fields;
}
fields[property.key] = {
type: TYPES[property.type]
};
return fields;
}, {})
});
});
The issue here is:
type: new graphql.GraphQLList(graphQLObjects[graphScheme.label])
There is no "graphQLObjects[graphScheme.label]"
How can I go around this? Any suggestions?
It's possible a field to reference the type itself by putting the fields in a wrapper function.
an example:
var routeType = new GraphQLObjectType({
name: 'MessageRoute',
fields: function () {
return {
name: {
type: GraphQLString
},
routes: {
type: new GraphQLList(routeType),
resolve: (route) => {
return route.routes;
}
}
};
}
});