Dynamodb query error - Query key condition not supported - amazon-web-services

I am trying to query my dynamodb table to get feed_guid and status_id = 1. But it returns Query key condition not supported error.
Please find my table schema and query.
$result =$dynamodbClient->createTable(array(
'TableName' => 'feed',
'AttributeDefinitions' => array(
array('AttributeName' => 'user_id', 'AttributeType' => 'S'),
array('AttributeName' => 'feed_guid', 'AttributeType' => 'S'),
array('AttributeName' => 'status_id', 'AttributeType' => 'N'),
),
'KeySchema' => array(
array('AttributeName' => 'feed_guid', 'KeyType' => 'HASH'),
),
'GlobalSecondaryIndexes' => array(
array(
'IndexName' => 'StatusIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'status_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
),
array(
'IndexName' => 'UserIdIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'user_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20
)
));
Following is my query to update that table.
$result = $dynamodbClient->query(array(
'TableName' => 'feed',
'KeyConditionExpression' => 'feed_guid = :v_fid AND status_id = :v_sid ',
'ExpressionAttributeValues' => array(
':v_fid' => array('S' => '71a27f0547cd5456d9ee7c181b6cb2f8'),
':v_sid' => array('N' => 1)
),
'ConsistentRead' => false
));

As mentioned, the attribute included in "KeyConditionExpression" should be your hash key only, matching your base table schema (in this case 'feed_guid'). If you want to query on both 'feed_guid' and 'status_id', you need to create the table with hash and range key and specify 'status_id' as your range key.
Global secondary indexes are completely separate from the base table, so in this case you can query the indexes separately (use 'status_id' in key condition when querying StatusIndex and use 'user_id' in key condition when querying UserIdIndex).
Please find more details on querying global secondary indexes here

Another option would be to use a FilterExpression in addition to the KeyConditionExpression. As Daniela mentioned KeyConditionExpression should contain only columns in the hash key. But any un-indexed columns can be included in the FilterExpression.

You need to have both hash_key (Partition Key) and range_key (Sort Key) provided in the KeyConditionExpression. hash_key must be exact match (=), but the range_key can use other operators like 'begins_with'

Related

Query string in drupal service custom resources

I am trying to use query string structure in drupal services API. it's not working for me.
I have also search most of the solutions, but all failed.
here is m drupal code:
function rapid_services_resources() {
$resources = array(
'get_data' => array(
'operations' => array(
'retrieve' => array(
'help' => t('Gets user email of uid passed.'),
'callback' => 'my_module_get_user_email',
'args' => array(
array(
'name' => 'nid',
'type' => 'int',
'description' => 'The display ID of the view to get.',
'source' => array('param' => 'nid'),
'optional' => TRUE,
'default value' => 'default',
),
),
'access arguments' => '_blog_access_provide_access',
'access callback' => '_blog_access_provide_access',
//~ 'access arguments append' => FALSE,
),
),
),
);
return $resources;
}
function _blog_access_provide_access() {
return TRUE;
}
function my_module_get_user_email($nid){
var_dump($args);die;
}
I want url like this.:
http://localhost/drupaltest/rapidapi/get_data/?nid=111
Please let me know where i did wrong.
thanks in advance.
Hi here are to reference that will be useful
http://pingv.com/blog/an-introduction-drupal-7-restful-services
https://www.drupal.org/node/783460
Also I am not sure about the query string, but for the retrieve operation you can set it as part of the url
ex:
http://localhost/drupaltest/rapidapi/get_data/<nid should be here>
http://localhost/drupaltest/rapidapi/get_data/111
Also using the source path as source
'source' => array('path' => '0'),
I would think that source param only works for an index operation and not retrieve

Compare user ID exactly, not with LIKE

I have this query -
<?php
$post_args = array(
'post_type' => 'tribe_events',
'eventDisplay'=>'custom',
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'compliance',
),
),
'meta_query' => array(
array(
'key' => 'associated_people',
'value' => $current_user,
'compare' => 'LIKE'
)
)
); ?>
At the moment it is fetching events that are associated to a particular person in a custom post type called people. I'm doing this using a relationship advanced custom field called associated_people.
I'm using the 'compare' => 'LIKE' code to do this also, but it's fetching other id's that are like the current one. e.g. If it's looking for ID 117, it's also bringing back 17, 11, 7..etc.
Is there a way to look at just the exact ID?
So far we have tried changing it to 'compare' => '='
Any help would be much appreciated. Thanks!
We solved it by changing the way the value was called -
<?php
$post_args = array(
'post_type' => 'tribe_events',
'eventDisplay'=>'custom',
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-365 days' ) ),
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'compliance',
),
),
'meta_query' => array(
array(
'key' => 'associated_people',
'value' => '"' . $current_user . '"',
'compare' => 'LIKE'
)
)
); ?>

ZF2 Segment Route doesn't match parent's constraint when using children

I created the following routes:
'relatorios' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/relatorios/:tipo',
'defaults' => array(
'controller' => 'Relatorios',
'action' => 'index',
'tipo' => 'normais',
),
'constraints' => array('tipo' => '(normais|administrativos)$',
),
'may_terminate' => true,
'child_routes' => array(
'view' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/view/:id_relatorio',
'defaults' => array('action' => 'view'),
'constraints' => array('id_relatorio' => '[0-9]+'),
),
),
),
);
This is supposed to match the following routes:
/relatorios/normais //matches
/relatorios/administrativos //matches
/relatorios/normais/view/1 //doesn't match
/relatorios/administrativos/view/1 //doesn't match
So basically the :tipo parameter must be either normais or administrativos and there is a child /view/any_digits.
When the parent route is called it matches, when the child view is called it doesn't match because of my tipo constraint. Why is that?
As per my comment, the $ on the constraint means 'end of the string' (which in this case is the URL path), so it shouldn't be there.

Cakephp validating if my user checked at least one option

I have a problem validating if my user checked at least one option from a list of checkboxes.
Here is what i tried:
My view looks like this:
echo $this->Form->input('market_segment_targeted', array(
'multiple' => 'checkbox',
'label'=>array('text' => 'Market segment targeted', 'class'=>'w120'),
'options' => array(
'Home users' => 'Home users',
'SOHO' => 'SOHO',
'SMB' => 'SMB',
'Enterprise' => 'Enterprise'
),
));
In my controller i have added this snippet of code:
$validate_on_fly = array(
'market_segment_targeted' => array(
'notEmpty' => array(
'rule' => array('multiple', array('min' => 1)),
'required' => true,
'message' => 'Please select at least one!'
))
)));
$this->Partner->validate = Set::merge(
$this->Partner->validate,
$validate_on_fly
);
Any ideas what am i doing wrong?
Thank you
In CakePHP you can use Model Validation for checkboxes. Here is a quick example.
Your Form can look like:
$this->Form->create('User');
$this->Form->input('User.agree', array('type'=>'checkbox', 'hiddenField'=>false, 'value'=>'0'));
$this->Form->submit('Save'):
$this->Form->end();
Then in your Model under public $validate, use:
'agree'=>array(
'Not empty'=>array(
'rule'=>array('comparison', '!=', 0),
'required'=>true,
'message'=>'You must agree to the ToS'
)
)

ZF2 Doctrine2 Form validation NoObjectExists

I'm using \DoctrineModule\Validator\NoObjectExists to validate my form submission. But, like the ZendDB adapter, I need to exclude all the rows where FieldX equals to SomethingX.
How can I achive that?
This is my form, filter input:
$filter->add(
$factory->createInput(array(
'name' => 'example',
'required' => false,
'validators' => array(
array(
'name' => '\DoctrineModule\Validator\NoObjectExists',
'options' => array(
'object_repository' => $this->mainRepository,
'fields' => 'example'
),
),
),
))
);
Thanks.