本文整理汇总了Python中cassandra.cluster.Cluster.row_factory方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.row_factory方法的具体用法?Python Cluster.row_factory怎么用?Python Cluster.row_factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.row_factory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_raw_row_results_all_types
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import row_factory [as 别名]
def test_custom_raw_row_results_all_types(self):
"""
Test to validate that custom protocol handlers work with varying types of
results
Connect, create a table with all sorts of data. Query the data, make the sure the custom results handler is
used correctly.
@since 2.7
@jira_ticket PYTHON-313
@expected_result custom protocol handler is invoked with various result types
@test_category data_types:serialization
"""
# Connect using a custom protocol handler that tracks the various types the result message is used with.
session = Cluster(protocol_version=PROTOCOL_VERSION).connect(keyspace="custserdes")
session.client_protocol_handler = CustomProtocolHandlerResultMessageTracked
session.row_factory = tuple_factory
colnames = create_table_with_all_types("alltypes", session, 1)
columns_string = ", ".join(colnames)
# verify data
params = get_all_primitive_params(0)
results = session.execute("SELECT {0} FROM alltypes WHERE primkey=0".format(columns_string))[0]
for expected, actual in zip(params, results):
self.assertEqual(actual, expected)
# Ensure we have covered the various primitive types
self.assertEqual(len(CustomResultMessageTracked.checked_rev_row_set), len(PRIMITIVE_DATATYPES)-1)
session.shutdown()
示例2: initialize_connection
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import row_factory [as 别名]
def initialize_connection(self):
session = Cluster(contact_points=[self.host], port=self.port).connect(keyspace=self.keyspace)
session.row_factory = panda_factory
query = "SELECT epoch_time, post_count, byte_transfer, get_count, requests, visits FROM "+self.source
DataFrame = session.execute(query).sort(columns=['epoch_time', 'post_count', 'byte_transfer', 'get_count', 'requests', 'visits'], ascending=[1,0,0,0,0,0])
process = retrieve_insert(DataFrame, session, self.dest) # create instance for the class retrieve_insert
process.retrieve_variables()
return 1
示例3: test_custom_raw_uuid_row_results
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import row_factory [as 别名]
def test_custom_raw_uuid_row_results(self):
"""
Test to validate that custom protocol handlers work with raw row results
Connect and validate that the normal protocol handler is used.
Re-Connect and validate that the custom protocol handler is used.
Re-Connect and validate that the normal protocol handler is used.
@since 2.7
@jira_ticket PYTHON-313
@expected_result custom protocol handler is invoked appropriately.
@test_category data_types:serialization
"""
# Ensure that we get normal uuid back first
session = Cluster().connect()
session.row_factory = tuple_factory
result_set = session.execute("SELECT schema_version FROM system.local")
result = result_set.pop()
uuid_type = result[0]
self.assertEqual(type(uuid_type), uuid.UUID)
# use our custom protocol handlder
session.client_protocol_handler = CustomTestRawRowType
session.row_factory = tuple_factory
result_set = session.execute("SELECT schema_version FROM system.local")
result = result_set.pop()
raw_value = result.pop()
self.assertTrue(isinstance(raw_value, binary_type))
self.assertEqual(len(raw_value), 16)
# Ensure that we get normal uuid back when we re-connect
session.client_protocol_handler = ProtocolHandler
result_set = session.execute("SELECT schema_version FROM system.local")
result = result_set.pop()
uuid_type = result[0]
self.assertEqual(type(uuid_type), uuid.UUID)
session.shutdown()
示例4: create_connection
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import row_factory [as 别名]
def create_connection(self):
"""
Override the create_connection from the DbConnectionWrapper
class which get's called in it's initializer
"""
from cassandra.cluster import Cluster
from cassandra.query import dict_factory
session = Cluster(self.nodes).connect()
# Don't return paged results
session.default_fetch_size = self.default_fetch_size
# Return in dictionary format for easy parsing to DataFrame
session.row_factory = dict_factory
return session
示例5: Cluster
# 需要导入模块: from cassandra.cluster import Cluster [as 别名]
# 或者: from cassandra.cluster.Cluster import row_factory [as 别名]
"""
web app base singleton utils
1. session cassandra driver crud support
"""
from cassandra.cluster import Cluster
from cassandra.decoder import dict_factory
from tornado.options import options
__author__ = 'wanggen'
session = Cluster(contact_points=[options.cassandra_host]).connect(options.cassandra_keyspace)
session.row_factory = dict_factory