Documentation ¶
Index ¶
- Constants
- Variables
- func AddSecondsToCurrentTimestamp(seconds int64) string
- func DecodeBytesToSpannerColumnType(b []byte, choice datatype.DataType, protocolVersion primitive.ProtocolVersion) (interface{}, error)
- func ExtractAfterWhere(sqlQuery string) (string, error)
- func FlattenTableName(keyspaceFlatter bool, keyspace string, tableName string) string
- func FormatTimestamp(ts int64) (*time.Time, error)
- func GetCassandraColumnType(choice string) (datatype.DataType, error)
- func GetSpannerColumnType(cqlType string) string
- func KeyExistsInList(key string, list []string) bool
- func ParseDurationToSeconds(duration string) (int64, error)
- func SetupLogger(logLevel string, loggerConfig *LoggerConfig) (*zap.Logger, error)
- func TypeConversion(s interface{}, protocalV primitive.ProtocolVersion) ([]byte, error)
- type ExecuteOptions
- type LoggerConfig
Constants ¶
const (
BigintType = "bigint"
)
Variables ¶
var ( MapTextCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Varchar) MapBigintCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Bigint) MapIntCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Int) MapBooleanCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Boolean) MapTimestampCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Timestamp) MapDoubleCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Double) MapDateCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Date) MapBlobCassandraType = datatype.NewMapType(datatype.Varchar, datatype.Blob) ListTextCassandraType = datatype.NewListType(datatype.Varchar) ListBigintCassandraType = datatype.NewListType(datatype.Bigint) ListBooleanCassandraType = datatype.NewListType(datatype.Boolean) ListIntCassandraType = datatype.NewListType(datatype.Int) ListDoubleCassandraType = datatype.NewListType(datatype.Double) ListFloatCassandraType = datatype.NewListType(datatype.Float) ListTimestampCassandraType = datatype.NewListType(datatype.Timestamp) ListDateCassandraType = datatype.NewListType(datatype.Date) ListBlobCassandraType = datatype.NewListType(datatype.Blob) SetTextCassandraType = datatype.NewSetType(datatype.Varchar) SetBigintCassandraType = datatype.NewSetType(datatype.Bigint) SetBooleanCassandraType = datatype.NewSetType(datatype.Boolean) SetIntCassandraType = datatype.NewSetType(datatype.Int) SetDoubleCassandraType = datatype.NewSetType(datatype.Double) SetFloatCassandraType = datatype.NewSetType(datatype.Float) SetTimestampCassandraType = datatype.NewSetType(datatype.Timestamp) SetDateCassandraType = datatype.NewSetType(datatype.Date) SetBlobCassandraType = datatype.NewSetType(datatype.Blob) )
var (
EncodedTrue, _ = proxycore.EncodeType(datatype.Boolean, primitive.ProtocolVersion4, true)
EncodedFalse, _ = proxycore.EncodeType(datatype.Boolean, primitive.ProtocolVersion4, false)
)
Functions ¶
func AddSecondsToCurrentTimestamp ¶
AddSecondsToCurrentTimestamp takes a number of seconds as input and returns the current Unix timestamp plus the input time in seconds.
func DecodeBytesToSpannerColumnType ¶
func DecodeBytesToSpannerColumnType(b []byte, choice datatype.DataType, protocolVersion primitive.ProtocolVersion) (interface{}, error)
DecodeBytesToSpannerColumnType - Function to decode incoming bytes parameter for handleExecute scenario into corresponding go datatype
Parameters:
- b: []byte
- choice: datatype.DataType
- protocolVersion: primitive.ProtocolVersion
Returns: (interface{}, error)
func ExtractAfterWhere ¶
ExtractAfterWhere ensures there is at least one space before and after the WHERE clause before splitting.
func FlattenTableName ¶
func FormatTimestamp ¶
formatTimestamp formats the Timestamp into time.
func GetCassandraColumnType ¶
getCassandraColumnType converts a string representation of a Cassandra data type into a corresponding DataType value. It supports a range of common Cassandra data types, including text, blob, timestamp, int, bigint, boolean, uuid, various map and list types.
Parameters:
- c: A string representing the Cassandra column data type. This function expects the data type in a specific format (e.g., "text", "int", "map<text, boolean>").
Returns:
- datatype.DataType: The corresponding DataType value for the provided string. This is used to represent the Cassandra data type in a structured format within Go.
- error: An error is returned if the provided string does not match any of the known Cassandra data types. This helps in identifying unsupported or incorrectly specified data types.
func GetSpannerColumnType ¶
GetSpannerColumnType takes a string representing a Cassandra column data type and converts it into the corresponding Google Cloud Spanner column data type.
Parameters:
- c: A string representing the Cassandra column data type. This function is designed to accept common Cassandra data types and their variations, such as "text", "blob", "timestamp", various "map" and "list" types, etc.
Returns:
- A string representing the equivalent Google Cloud Spanner column data type. For example, Cassandra's "text" type is converted to Spanner's "string" type, and "bigint" is converted to "int64".
func KeyExistsInList ¶
keyExists checks if a key is present in a list of strings.
func ParseDurationToSeconds ¶
parseDurationToSeconds converts a duration string like "1s", "1m", "1h" to the equivalent number of seconds in int64.
func SetupLogger ¶
func SetupLogger(logLevel string, loggerConfig *LoggerConfig) (*zap.Logger, error)
SetupLogger initializes a zap.Logger instance based on the provided log level and logger configuration. If loggerConfig specifies file output, it sets up a file-based logger. Otherwise, it defaults to console output. Returns the configured zap.Logger or an error if setup fails.
func TypeConversion ¶
func TypeConversion(s interface{}, protocalV primitive.ProtocolVersion) ([]byte, error)
TypeConversion converts a Go data type to a Cassandra protocol-compliant byte array.
Parameters:
- s: The data to be converted.
- protocalV: Cassandra protocol version.
Returns: Byte array in Cassandra protocol format.
Types ¶
type ExecuteOptions ¶
type ExecuteOptions struct {
MaxStaleness int64
}
type LoggerConfig ¶
type LoggerConfig struct { OutputType string `yaml:"outputType"` Filename string `yaml:"fileName"` MaxSize int `yaml:"maxSize"` // megabytes MaxBackups int `yaml:"maxBackups"` // The value of MaxBackups determines how many previous log files are kept after a new log file is created due to the MaxSize or MaxAge limits. MaxAge int `yaml:"maxAge"` // days Compress bool `yaml:"compress"` // the rotated log files to be compressed to save disk space. }