本文整理汇总了Python中cassandra.query.SimpleStatement.routing_key方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleStatement.routing_key方法的具体用法?Python SimpleStatement.routing_key怎么用?Python SimpleStatement.routing_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.query.SimpleStatement
的用法示例。
在下文中一共展示了SimpleStatement.routing_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_routing_key_generation_complex
# 需要导入模块: from cassandra.query import SimpleStatement [as 别名]
# 或者: from cassandra.query.SimpleStatement import routing_key [as 别名]
def test_routing_key_generation_complex(self):
"""
Compares the routing key generated by complex composite partition key using the model with the one generated by the equivalent
bound statement
@since 3.2
@jira_ticket PYTHON-535
@expected_result they should match
@test_category object_mapper
"""
prepared = self.session.prepare(
"""
INSERT INTO {0}.complex_model_routing (partition, cluster, count, text, float, text_2) VALUES (?, ?, ?, ?, ?, ?)
""".format(DEFAULT_KEYSPACE))
partition = uuid4()
cluster = 1
count = 2
text = "text"
float = 1.2
text_2 = "text_2"
bound = prepared.bind((partition, cluster, count, text, float, text_2))
mrk = ComplexModelRouting._routing_key_from_values([partition, cluster, text, float], self.session.cluster.protocol_version)
simple = SimpleStatement("")
simple.routing_key = mrk
self.assertEqual(bound.routing_key, simple.routing_key)
示例2: test_routing_key_is_ignored
# 需要导入模块: from cassandra.query import SimpleStatement [as 别名]
# 或者: from cassandra.query.SimpleStatement import routing_key [as 别名]
def test_routing_key_is_ignored(self):
"""
Compares the routing key generated by simple partition key using the model with the one generated by the equivalent
bound statement. It also verifies basic operations work with no routing key
@since 3.2
@jira_ticket PYTHON-505
@expected_result they shouldn't match
@test_category object_mapper
"""
prepared = self.session.prepare(
"""
INSERT INTO {0}.basic_model_no_routing (k, v) VALUES (?, ?)
""".format(DEFAULT_KEYSPACE))
bound = prepared.bind((1, 2))
mrk = BasicModelNoRouting._routing_key_from_values([1], self.session.cluster.protocol_version)
simple = SimpleStatement("")
simple.routing_key = mrk
self.assertNotEqual(bound.routing_key, simple.routing_key)
# Verify that basic create, update and delete work with no routing key
t = BasicModelNoRouting.create(k=2, v=3)
t.update(v=4).save()
f = BasicModelNoRouting.objects.filter(k=2).first()
self.assertEqual(t, f)
t.delete()
self.assertEqual(BasicModelNoRouting.objects.count(), 0)
示例3: _execute_statement
# 需要导入模块: from cassandra.query import SimpleStatement [as 别名]
# 或者: from cassandra.query.SimpleStatement import routing_key [as 别名]
def _execute_statement(model, statement, consistency_level, timeout):
params = statement.get_context()
s = SimpleStatement(str(statement), consistency_level=consistency_level, fetch_size=statement.fetch_size)
if model._partition_key_index:
key_values = statement.partition_key_values(model._partition_key_index)
if not any(v is None for v in key_values):
parts = model._routing_key_from_values(key_values, connection.get_cluster().protocol_version)
s.routing_key = parts
s.keyspace = model._get_keyspace()
return connection.execute(s, params, timeout=timeout)
示例4: test_routing_key_generation_multi
# 需要导入模块: from cassandra.query import SimpleStatement [as 别名]
# 或者: from cassandra.query.SimpleStatement import routing_key [as 别名]
def test_routing_key_generation_multi(self):
"""
Compares the routing key generated by composite partition key using the model with the one generated by the equivalent
bound statement
@since 3.2
@jira_ticket PYTHON-535
@expected_result they should match
@test_category object_mapper
"""
prepared = self.session.prepare(
"""
INSERT INTO {0}.basic_model_routing_multi (k, v) VALUES (?, ?)
""".format(DEFAULT_KEYSPACE))
bound = prepared.bind((1, 2))
mrk = BasicModelMulti._routing_key_from_values([1, 2], self.session.cluster.protocol_version)
simple = SimpleStatement("")
simple.routing_key = mrk
self.assertEqual(bound.routing_key, simple.routing_key)