Documentation
Data Ingestion
Cassandra Connector

Module: cassandra_connector.py

Class and Functions

CassandraConnector

class CassandraConnector:
    """
    Facilitates connecting to a Cassandra database cluster and executing CQL operations.
    It handles session creation, CQL query execution, including batch operations, and gracefully manages resources.
    """
 
 
def __init__(self, nodes, keyspace, username=None, password=None):
    """
    Initializes the connector with authentication and keyspace selection.
 
    Parameters:
        nodes (list): List of nodes in the Cassandra cluster.
        keyspace (str): The keyspace to connect to within Cassandra.
        username (str, optional): Optional username for authentication.
        password (str, optional): Optional password for authentication.
    """
 
 
def execute_query(self, query, params=None):
    """
    Executes a CQL query with optional parameters.
 
    Parameters:
        query (str): The CQL query string.
        params (tuple, optional): Optional parameters for the query.
 
    Returns:
        result: The result of the query execution.
    """
 
 
def execute_batch(self, queries):
    """
    Executes multiple CQL queries as a batch operation.
 
    Parameters:
        queries (list): A list of CQL query strings to be executed in a batch.
    """
 
 
def close(self):
    """
    Closes the session and connection to the Cassandra cluster.
    """