I am having an issue where I am trying to get the data from the DynamoDB directly to my android studio. It works totally fine if I want to query with PK and filter with random column, however, no matter what I do I am unable to use also the sort key. Expression cannot be used as its part of partion key, but it is also not possible to put two primitive types into the query.
I also tried using QueryFilter, however, I am getting has protected access on the code bellow, even if I extend the class.
QueryFilter queryFilter = new QueryFilter();
This is the code which works for query with only Partion Key without Sort Key.
final Expression expression = new Expression();
expression.setExpressionStatement("#t < :time");
//expression.setExpressionStatement("begins_with (#t, :time)");
expression.withExpressionAttibuteValues(":time", new Primitive(timeNow.format(format)));
expression.addExpressionAttributeNames("#t", "time");
Search searchResult = dbTable.query(new Primitive("Location1"), expression);
After trying for a bit longer I have found a solution with QueryOperationConfig. As someone may find this usefull, I will be posting the solution which worked for me.
final Expression expression2 = new Expression();
expression2.setExpressionStatement("#p = :PK AND begins_with(#s, :SK)");
expression2.withExpressionAttibuteValues(":PK", new Primitive("Location1"));
expression2.withExpressionAttibuteValues(":SK", new Primitive("2021-04-11 22:08"));
expression2.addExpressionAttributeNames("#p", "location");
expression2.addExpressionAttributeNames("#s", "device # MAC # UUID");
QueryOperationConfig queryOperationConfig = new QueryOperationConfig();
queryOperationConfig.withKeyExpression(expression2);
Search searchResult = dbTable.query(queryOperationConfig);
Related
I'm trying to create a Django filter using a variable as filter input for a contains query on a jsonfield. I just cannot get it to work. Form what I'm finding the solution should be using kwargs but I'm lost how to implement this.
lookupValue = "[{{\"displayName\":\"{0}\"}}]".format(user['name'])
print("value is: ")
print(lookupValue)
recent_user_calls = CallRecord.objects.filter(participants__contains = [{"displayName":"Some Name"}])
#recent_user_calls = CallRecord.objects.filter(participants__contains = lookupValue)
I create the value I want to search and put it in lookup value. In the last commented out line I try to use this value in de query. This does not work as where the previous line works perfectly. A few lines before I print the lookupvalue and it is 100% the same as the fully typed out version. I'm have been staring at this for 2 days. Can someone please point me in the right direction?
The problem is that the variable you are passing in the query is a string and not a list.
You can write:
recent_user_calls = CallRecord.objects.filter(participants__contains = [{"displayName":user['name']}])
Or you can directly filter using the key:
recent_user_calls = CallRecord.objects.filter(participants__displayName=user['name'])
I have inherited a DynamoDB table with three columns of which one is a key
Id - String - hashKey
ProductID - String
UsageCount - number
I want to run a query/scan that logically equates to the following
select ProductID, UsageCount where ProductID='abcd'
Although ProductID is not a key of any sort, I can use the AmazonDynamoDB console and add a filter
and get just what I want. So I assume I should be able to do the same thing with code (although everyone talks about using hash and range keys for such purposes)
I am trying to do the same thing with RUBY but not getting results...
resp = $dynamodb.scan(
:table_name => PRODUCTTABLE,
:projection_expression => "Id, TenantId, SeatCount",
:filter_expression => 'TenantId = abcd'
)
Could someone help me with the correct syntax for doing this? I tried numerous variations that all throw exceptions except for the above syntax that does not throw an exception but returns zero rows. So Im thinking it must be close :) (or maybe not)
You have to use both filter_expression but make it 'TenantId = :val'
and then pass :val with expression_attribute_names and expression_attribute_values
Even though it's in Java, this doc will help clear things out for you
I've search hard for an answer to this but haven't found anything that works. I have a NodeJS app, with the Mongoose ORM. I'm trying to query my Mongo database where a result is LIKE the query.
I have tried using a new RegExp to find the results, but it hasn't worked for me. The only time I get a result is when the query is exactly the same as the collection property's value.
Here's what I'm using right now:
var query = "Some Query String.";
var q = new RegExp('^/.*'+ query +'.*/i$');
Quote.find({author: q}, function(err, doc){
cb(doc);
});
If the value of an author property contains something LIKE the query (for instance: 'some. query String'), I need to return the results. Perhaps stripping case, and excluding special characters is all I can do? What is the best way to do this? My RegEx in this example is obviously not working. Thanks!
You likely want to create your RegExp as follows instead as you don't include the / chars when using new RegExp:
var q = new RegExp(query, 'i');
I don't know of a way to ignore periods in the author properties of your docs with a RegExp though. You may want to look at $text queries for more flexible searching like that.
I have been working on the AX Query Service as of late. I have a pretty good understanding of everything but it seems that the QueryDataFieldMetadata object does not like aggregates. When I build a QueryDataFieldMetadata object:
QueryDataFieldMetadata field = new QueryDataFieldMetadata();
field.TableName = "InventSum";
field.FieldName = "AvailPhysical";
field.SelectionField = SelectionField.Database;
And add it to the data source everything is fine. But when I do this:
QueryDataFieldMetadata field = new QueryDataFieldMetadata();
field.TableName = "InventSum";
field.FieldName = "AvailPhysical";
field.SelectionField = SelectionField.Sum;
And add it to the data source the field is not returned at all in the results set. I have checked the datasource itself before executing the query and it is in the fields list but nothing is returned. Does anyone know why this might be happening? Any help would be appreciated.
I just figured this one out. The problem was due to me selecting another field from the table but forgetting to put it in the "Group by" fields. It is strange to me that the query service was returning THAT field with an empty but not returning the aggregate fields at all. Basically I had made a query service query that would be equal to this:
Select wMSLocationId, SUM(AvailPhysical), RecId from InventSum group by ItemId, InventLocationId, wMSlocationId where ItemId == 'some value';
The query was returning:
InventSum.wMSLocationId = 001
InventSum.RecId = 0
The inclusion of the RecId was a mistake, I had forgotten to remove it, but didn't think it would matter as it wasn't in the group by fields and would therefore return null. Removing this selection field did result in the aggregate field returning in the query.
Anyway I hope this helps someone out there as it took me some time to figure out.
I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.