DynamoDB Query Input: How to retrieve all items where key value is not null - dynamodb-queries

I have the following schema:
resources:
Resources:
ChatDynamoDbTable:
Type: "AWS::DynamoDB::Table"
DeletionPolicy: Retain
Properties:
TableName: "chats-admin-${opt:stage, self:provider.stage}"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: user_id
AttributeType: S
- AttributeName: admin_type
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
-
IndexName: user_id-admin_type-index
KeySchema:
-
AttributeName: user_id
KeyType: HASH
-
AttributeName: admin_type
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
I need to fetch all items where the admin_type matches the key I supply.
I tried the following and it failed because I've not specified the value for user_id:
"error_message":"ValidationException: Query condition missed key
schema element: user_id
input := &dynamodb.QueryInput{
TableName: aws.String(table),
IndexName: aws.String("user_id-admin_type-index"),
KeyConditionExpression: aws.String("#admin_type = :admin_type"),
ExpressionAttributeNames: map[string]*string{
"#admin_type": aws.String("admin_type"),
},
ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
":admin_type": {
S: aws.String(a.AdminType),
},
},
}
How can I modify the above to fetch all items where admin_type matches my key? (basically all items matching admin_type without worrying about the value of user_id.)

The DynamoDB API offers two basic means of fetching data; query and scan.
The query operation requires you to specify the primary key. When you have a composite primary key (partition key + sort key), you can:
Specify only the partition key (you'll get back everything in the partition)
Specify both the partition key and sort key (you'll get back a single item)
There is no option with the query operation to specify only the sort key.
To fetch items by sort key only, you'll need to use the scan operation. Alternatively, you could create a secondary index with a primary key set to your sort key (in your case, the admin_type). This would allow you to fetch items by admin_type, regardless of the user_id.

Related

GCP golang datastore query performance

I have a kind "Customers" in GCP datastore and I have an existing query to return list of customers sorted by creation date desc
Query #1
q := datastore.NewQuery(CUSTOMERS).
Filter("User=", userKey).
Filter("Country=",country)
Filter("CreatedOn >", Zero).
SortOrder("-CreatedOn")
The composite index used is
- kind: Customer
properties:
- name: User
- name: Country
- name: CreatedOn
direction: desc
Query #2
Now I want to write a util to check if customer exists or not , something like below
q := datastore.NewQuery(CUSTOMERS).
Filter("User=", userKey).
Filter("Country=",country)
Filter("CreatedOn >", Zero).
KeysOnly()
I tested and found in my local that the existing index for Query1 also serves Query2 ,
is it worth adding any new index without direction for Query 2? I am reluctant as the existing index for query1 is already taking 25GB memory ?
What performance impact it will have?

mailchimp - how to add default value for date field?

I want add a date field into Mailchimp with default value
name: gen
type: date
value: 2019-01-01
The instructions do not explain how to do it
I tried this values:
01/01/2019
2019-01-01
but when new user subrscribes to list,
i don't see any default value
Per documentation, "Default merge tag values will only display in campaigns, and not in your list fields."

How do we create a array of 2 properties in yml?

How do we create a array of 2 properties in yml?
Eg:
Array of employees. Each employee has 2 properties, name and age
employee:
-name : emp1
age : 20
-name :emp1
age : 20
Is this correct?
Any finally i want to return it in ruby
def readEmployees
[
{name: 'emp1', age: '20'},
{name: 'emp2', age: '30'},
]
end
Instead of giving a man a fish, I am going to feed him for a lifetime. You want to know how a structure would be presented in yaml? Check it:
inp = [
{name: 'emp1', age: '20'},
{name: 'emp2', age: '30'},
]
inp.to_yaml
#⇒ "---\n- :name: emp1\n :age: '20'\n- :name: emp2\n :age: '30'\n"
For readers, the yaml above is:
---
- :name: emp1
:age: '20'
- :name: emp2
:age: '30'
This:
employee:
-name : emp1
age : 20
-name :emp1
age : 20
is not correct YAML. For two reasons:
you did not insert space after the dash that indicates a sequence element
you did not insert a space after colon, before emp1 in the second element (which is always needed except when you have quoted scalars: {"name":"emp1"})
It is also not customary to insert spaces before the colon+space that separates the key from the value in mapping:
employee:
- name: emp1
age: 20
- name: emp1
age: 20
You should also note that there is no such thing as an array in YAML, nor are there properties. A YAML sequence might be represented in Ruby as array and your properties are YAML key-value pairs that belong to a mapping.

How to add sorting by price on Sylius ProductController::indexByTaxon method

How would I go about adding a simple 'order by price desc' or 'order by price asc' select menu to a category listing page on Sylius frontend?
In example - on demo page here: http://demo.sylius.org/t/category/mugs
There's:
- filtering by price
So far I've managed to figure out that this is done via facets and configured in sylius_search like like this:
sylius_search:
...
filters:
pre_search_filter:
enabled: true
taxonomy: category
facet_groups:
search_set:
values: [taxons, price, made_of, color]
categories_set:
values: [price, made_of, color]
all_set:
values: [taxons, price, made_of]
facets:
taxons:
display_name: 'Basic categories'
type: terms
value: ~
price:
display_name: 'Available prices'
type: range
values:
- { from: 0, to: 2000}
- { from: 2001, to: 5000}
- { from: 5001, to: 10000}
made_of:
display_name: 'Material'
type: terms
value: ~
color:
display_name: 'Available colors'
type: terms
value: ~
Any attempt to figure this out ended up as a dead end or bunch of errors.
I can override product repository and try passing request along to add custom leftJoin to Variants and then add orderBy on doctrine query builder, but I'm guessing this is hacking and wouldn't get me very far.
So in short, how do I add sorting options to product listing page(s) so I can have my products sorted using master variant price?
Any help or guide in the right direction appreciated.

symfony1 enums with column aggregation inheritence

I have a profile table that saves all profiles for all user.
I have different types of users and want each type of user to have different select options for choosing a certain field.
So both user types can choose how long they want to register for, but the have different options - one can choose 2 years and the other cant.
The schema.yml looks something like this:
UserProfile:
columns:
username:
type: string(255)
notnull: true
unique: false
WriterUserProfile:
inheritance:
type: column_aggregation
extends: UserProfile
columns:
register_time:
type: enum
values:
- 6 months
- 1 year
- 2 years
- Other
default: other
ReaderUserProfile:
inheritance:
type: column_aggregation
extends: UserProfile
columns:
register_time:
type: enum
values:
- 6 months
- 1 year
- Other
default: other
For some reason I am unable to select the '2 year' option - the form gives an 'invalid' error.
Does the '2 years' and 'Other' coincide with eachother because they are both the 3rd option?
Are there other fields which are not common? This one field only not enough cause to use column aggregation. Anyway, if the same field appears in multiple sub-classes than the field should be moved up and field names should be unique among all related classes (UserProfile, WriterUserProfile, ReaderUserProfile in your case).
You can change the options of the choice field in a form:
$choices = array('0' => 'a', '1' => 'b');
$this->getWidget('register_time')->setOption('choices', $choices);
$this->getValidator('register_time')->setOption('choices', array_keys($choices));

Resources