本文整理汇总了Python中cassandra.cluster.Session方法的典型用法代码示例。如果您正苦于以下问题:Python cluster.Session方法的具体用法?Python cluster.Session怎么用?Python cluster.Session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster
的用法示例。
在下文中一共展示了cluster.Session方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_cql_insert
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def create_cql_insert(self):
"""
Given a table, prepares a statement to allow the dataframe to be inserted row by row into cassandra.
Sets statement_input to be the prepared statement.
:return: 0
"""
assert isinstance(self.session, Session)
assert self.table is not None
statement = "INSERT INTO " + self.table + "(" + paste(self._cql_columns) + ") VALUES (" + paste(["?"] * len(self.columns)) + ");"
self.statement_input = self.session.prepare(statement)
self._prepared_columns = self._cql_columns
return
示例2: set_session
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def set_session(self, session):
"""
Setter method for self.session.
Pass a session object or None.
:return: None
"""
if session is None:
self.session = None
else:
assert isinstance(session, Session), "Got non-session, type: {}".format(type(session))
self.session = session
return
示例3: __init__
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def __init__(self, session: Session, key_space: str, strategy: str, replications: int):
self.session = session
self.statements = dict()
self.key_space = key_space
self.key_space_test = key_space + 'test'
self.strategy = strategy
self.replications = replications
self.logger = logging.getLogger(__name__)
示例4: get_conn
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def get_conn(self) -> Session:
"""
Returns a cassandra Session object
"""
if self.session and not self.session.is_shutdown:
return self.session
self.session = self.cluster.connect(self.keyspace)
return self.session
示例5: __init__
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def __init__(self, hashes: Iterable, batch_size: int, session: Session, table: str):
self.hashes = iter(hashes)
self.batch_size = batch_size
self.session = session
self.table = table
self.buffer = []
self._log = logging.getLogger("BatchedHashResolver")
示例6: aiosession
# 需要导入模块: from cassandra import cluster [as 别名]
# 或者: from cassandra.cluster import Session [as 别名]
def aiosession(session, *, executor=None, loop=None):
if not isinstance(session, Session):
raise RuntimeError(
'provide cassandra.cluster.Session')
if hasattr(session, '_asyncio_fut_factory'):
raise RuntimeError(
'session is already patched by aiosession')
if executor is not None:
if not isinstance(executor, ThreadPoolExecutor):
raise RuntimeError(
'executor should be instance of ThreadPoolExecutor')
if loop is None:
loop = asyncio.get_event_loop()
session._asyncio_loop = loop
session._asyncio_executor = executor
session._asyncio_fut_factory = _asyncio_fut_factory(loop=loop)
session._asyncio_result = MethodType(_asyncio_result, session)
session._asyncio_exception = MethodType(_asyncio_exception, session)
session.execute_future = MethodType(execute_future, session)
session.execute_futures = MethodType(execute_futures, session)
session.prepare_future = MethodType(prepare_future, session)
return session