utilities

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BigintType = "bigint"
)

Variables

View Source
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)
)

Functions

func AddSecondsToCurrentTimestamp

func AddSecondsToCurrentTimestamp(seconds int64) string

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

func ExtractAfterWhere(sqlQuery string) (string, error)

ExtractAfterWhere ensures there is at least one space before and after the WHERE clause before splitting.

func FlattenTableName

func FlattenTableName(keyspaceFlatter bool, keyspace string, tableName string) string

func FormatTimestamp

func FormatTimestamp(ts int64) (*time.Time, error)

formatTimestamp formats the Timestamp into time.

func GetCassandraColumnType

func GetCassandraColumnType(choice string) (datatype.DataType, error)

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

func GetSpannerColumnType(cqlType string) string

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

func KeyExistsInList(key string, list []string) bool

keyExists checks if a key is present in a list of strings.

func ParseDurationToSeconds

func ParseDurationToSeconds(duration string) (int64, error)

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.
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL