示例#1
0
文件: engine.py 项目: mathcamp/dql
 def _alter(self, tree):
     """ Run an ALTER statement """
     if tree.throughput:
         [read, write] = tree.throughput
         index = None
         if tree.index:
             index = tree.index
         self._update_throughput(tree.table, read, write, index)
     elif tree.drop_index:
         updates = [IndexUpdate.delete(tree.drop_index[0])]
         try:
             self.connection.update_table(tree.table, index_updates=updates)
         except DynamoDBError as e:
             if tree.exists and e.kwargs["Code"] == "ResourceNotFoundException":
                 pass
             else:
                 raise
     elif tree.create_index:
         # GlobalIndex
         attrs = {}
         index = self._parse_global_index(tree.create_index, attrs)
         updates = [IndexUpdate.create(index)]
         try:
             self.connection.update_table(tree.table, index_updates=updates)
         except DynamoDBError as e:
             if (
                 tree.not_exists
                 and e.kwargs["Code"] == "ValidationException"
                 and "already exists" in e.kwargs["Message"]
             ):
                 pass
             else:
                 raise
     else:
         raise SyntaxError("No alter command found")
示例#2
0
 def _alter(self, tree):
     """ Run an ALTER statement """
     if tree.throughput:
         [read, write] = tree.throughput
         index = None
         if tree.index:
             index = tree.index
         self._update_throughput(tree.table, read, write, index)
     elif tree.drop_index:
         updates = [IndexUpdate.delete(tree.drop_index[0])]
         try:
             self.connection.update_table(tree.table, index_updates=updates)
         except DynamoDBError as e:
             if tree.exists and e.kwargs[
                     "Code"] == "ResourceNotFoundException":
                 pass
             else:
                 raise
     elif tree.create_index:
         # GlobalIndex
         attrs = {}
         index = self._parse_global_index(tree.create_index, attrs)
         updates = [IndexUpdate.create(index)]
         try:
             self.connection.update_table(tree.table, index_updates=updates)
         except DynamoDBError as e:
             if (tree.not_exists
                     and e.kwargs["Code"] == "ValidationException"
                     and "already exists" in e.kwargs["Message"]):
                 pass
             else:
                 raise
     else:
         raise SyntaxError("No alter command found")
示例#3
0
 def test_delete_index(self):
     """ Delete a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key=hash_key,
                              global_indexes=[index])
     self.dynamo.update_table('foobar', index_updates=[
         IndexUpdate.delete('name-index')])
     table = self.dynamo.describe_table('foobar')
     self.assertTrue(len(table.global_indexes) == 0 or
                     table.global_indexes[0].index_status == 'DELETING')
示例#4
0
 def test_index_update_equality(self):
     """ IndexUpdates should have sane == behavior """
     self.assertEqual(IndexUpdate.delete('foo'), IndexUpdate.delete('foo'))
     collection = set([IndexUpdate.delete('foo')])
     self.assertIn(IndexUpdate.delete('foo'), collection)
     self.assertNotEqual(IndexUpdate.delete('foo'),
                         IndexUpdate.delete('bar'))
示例#5
0
 def test_index_update_equality(self):
     """ IndexUpdates should have sane == behavior """
     self.assertEqual(IndexUpdate.delete('foo'), IndexUpdate.delete('foo'))
     collection = set([IndexUpdate.delete('foo')])
     self.assertIn(IndexUpdate.delete('foo'), collection)
     self.assertNotEqual(IndexUpdate.delete('foo'),
                         IndexUpdate.delete('bar'))
示例#6
0
 def test_delete_index(self):
     """ Delete a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar',
                              hash_key=hash_key,
                              global_indexes=[index])
     self.dynamo.update_table(
         'foobar', index_updates=[IndexUpdate.delete('name-index')])
     table = self.dynamo.describe_table('foobar')
     self.assertTrue(
         len(table.global_indexes) == 0
         or table.global_indexes[0].index_status == 'DELETING')
示例#7
0
 def test_delete_index(self):
     """Delete a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     self.dynamo.create_table("foobar", hash_key=hash_key, global_indexes=[index])
     self.dynamo.update_table(
         "foobar", index_updates=[IndexUpdate.delete("name-index")]
     )
     table = self.dynamo.describe_table("foobar")
     assert table is not None
     self.assertTrue(
         len(table.global_indexes) == 0
         or table.global_indexes[0].status == "DELETING"
     )