<commit_before>package sandra

import (
	"errors"
	"fmt"
	"time"

	"github.com/gocql/gocql"
	"github.com/mailgun/log"
)

type Cassandra interface {
	ExecuteQuery(string, ...interface{}) error
	ExecuteBatch(gocql.BatchType, []string, [][]interface{}) error
	ExecuteUnloggedBatch([]string, [][]interface{}) error
	ScanQuery(string, []interface{}, ...interface{}) error
	ScanCASQuery(string, []interface{}, ...interface{}) (bool, error)
	IterQuery(string, []interface{}, ...interface{}) func() (int, bool, error)
	Close() error
}

type cassandra struct {
	session *gocql.Session
	config  CassandraConfig
}

// CassandraConfig is a json and yaml friendly configuration struct
type CassandraConfig struct {
	Nodes       []string // addresses for the initial connections
	Timeout     string   // connection timeout (default: 600ms)
	Keyspace    string   // initial keyspace (optional)
	NumConns    int      // number of connections per host (default: 2)
	NumStreams  int      // number of streams per connection (default: 128)
	Consistency string   // consistency to use, default quorum
	Port        int      // port to connect to, default: 9042
	KeepAlive   string   // The keepalive period to use default: 0

	// TestMode affects whether a keyspace creation will be attempted on Cassandra initialization.
	TestMode bool `config:"optional"`
}

func (c CassandraConfig) String() string {
	return fmt.Sprintf("CassandraConfig(Nodes=%v, Keyspace=%v, Consistency=%v, TestMode=%v)",
		c.Nodes, c.Keyspace, c.Consistency, c.TestMode)
}

var NotFound = errors.New("Not found")

func NewCassandra(config CassandraConfig) (Cassandra, error) {
	log.Infof("Connecting to Cassandra with config: %v", config)

	cluster, err := setDefaults(config)
	if err != nil {
		return nil, err
	}

	// in test mode, create a keyspace if necessary
	if config.TestMode == true {
		session, err := cluster.CreateSession()
		if err != nil {<commit_msg>Annotate optional parameters.<commit_after>package sandra

import (
	"errors"
	"fmt"
	"time"

	"github.com/gocql/gocql"
	"github.com/mailgun/log"
)

type Cassandra interface {
	ExecuteQuery(string, ...interface{}) error
	ExecuteBatch(gocql.BatchType, []string, [][]interface{}) error
	ExecuteUnloggedBatch([]string, [][]interface{}) error
	ScanQuery(string, []interface{}, ...interface{}) error
	ScanCASQuery(string, []interface{}, ...interface{}) (bool, error)
	IterQuery(string, []interface{}, ...interface{}) func() (int, bool, error)
	Close() error
}

type cassandra struct {
	session *gocql.Session
	config  CassandraConfig
}

// CassandraConfig is a json and yaml friendly configuration struct
type CassandraConfig struct {
	// Required Parameters
	Nodes       []string // addresses for the initial connections
	Keyspace    string   // initial keyspace
	Consistency string   `config:"optional"` // consistency to use, default quorum
	Timeout     string   `config:"optional"` // connection timeout (default: 600ms)
	KeepAlive   string   `config:"optional"` // The keepalive period to use default: 0
	NumConns    int      `config:"optional"` // number of connections per host (default: 2)
	NumStreams  int      `config:"optional"` // number of streams per connection (default: 128)
	Port        int      `config:"optional"` // port to connect to, default: 9042

	// TestMode affects whether a keyspace creation will be attempted on Cassandra initialization.
	TestMode bool `config:"optional"`
}

func (c CassandraConfig) String() string {
	return fmt.Sprintf("CassandraConfig(Nodes=%v, Keyspace=%v, Consistency=%v, TestMode=%v)",
		c.Nodes, c.Keyspace, c.Consistency, c.TestMode)
}

var NotFound = errors.New("Not found")

func NewCassandra(config CassandraConfig) (Cassandra, error) {
	log.Infof("Connecting to Cassandra with config: %v", config)

	cluster, err := setDefaults(config)
	if err != nil {
		return nil, err
	}

	// in test mode, create a keyspace if necessary
	if config.TestMode == true {
		session, err := cluster.CreateSession()
		if err != nil {
{'fraction_non_alphanumeric': 0.12421580928481807, 'fraction_numerical': 0.00602258469259724, 'mean_word_length': 4.2516469038208164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3040971', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1172, 'n_words': 387}